Skip to content

Commit

Permalink
Development: Add support for setting environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Hialus committed May 26, 2024
1 parent 817fd3b commit b575fda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class APIKeyConfig(BaseModel):

class Settings(BaseModel):
api_keys: list[APIKeyConfig]
env_vars: dict[str, str]

@classmethod
def get_settings(cls):
Expand All @@ -32,5 +33,10 @@ def get_settings(cls):
except yaml.YAMLError as e:
raise yaml.YAMLError(f"Error parsing YAML file at {file_path}.") from e

def set_env_vars(self):
"""Set environment variables from the settings."""
for key, value in self.env_vars.items():
os.environ[key] = value


settings = Settings.get_settings()
3 changes: 3 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from fastapi.responses import ORJSONResponse
from fastapi import FastAPI

from app.config import settings
from app.web.routers.health import router as health_router
from app.web.routers.pipelines import router as pipelines_router
from app.web.routers.webhooks import router as webhooks_router

settings.set_env_vars()

app = FastAPI(default_response_class=ORJSONResponse)

app.include_router(health_router)
Expand Down

0 comments on commit b575fda

Please sign in to comment.