Skip to content

Commit

Permalink
Enable getting Stomp authentication credentials from the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondJoseph committed Feb 21, 2024
1 parent 598d789 commit 7719626
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/blueapi/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from enum import Enum
from pathlib import Path
from typing import Any, Dict, Generic, Literal, Mapping, Optional, Type, TypeVar, Union

import yaml
from pydantic import BaseModel, Field, ValidationError, parse_obj_as
from pydantic import BaseModel, Field, ValidationError, parse_obj_as, validator

from blueapi.utils import BlueapiBaseModel, InvalidConfigError

Expand All @@ -29,6 +30,12 @@ class BasicAuthentication(BaseModel):
username: str = "guest"
passcode: str = "guest"

@validator("username", "passcode")
def get_passcode_from_env(cls, v: str):
if v.startswith("${") and v.endswith("}"):
return os.environ[v.removeprefix("${").removesuffix("}").upper()]
return v

Check warning on line 37 in src/blueapi/config.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/config.py#L35-L37

Added lines #L35 - L37 were not covered by tests


class StompConfig(BaseModel):
"""
Expand Down

0 comments on commit 7719626

Please sign in to comment.