diff --git a/amarillo/models/AgencyConf.py b/amarillo/models/AgencyConf.py index 9a6af77..2908eeb 100644 --- a/amarillo/models/AgencyConf.py +++ b/amarillo/models/AgencyConf.py @@ -1,3 +1,4 @@ +from typing import Optional from pydantic import ConfigDict, BaseModel, Field @@ -9,13 +10,13 @@ class AgencyConf(BaseModel): pattern='^[a-zA-Z0-9]+$', examples=["mfdz"]) - api_key: str = Field( + api_key: Optional[str] = Field(None, description="The agency's API key for using the API", min_length=20, max_length=256, pattern=r'^[a-zA-Z0-9]+$', examples=["d8yLuY4DqMEUCLcfJASi"]) - password: str = Field( + password: Optional[str] = Field(None, description="The agency's password for generating JWT tokens", min_length=8, max_length=256, diff --git a/amarillo/services/agencyconf.py b/amarillo/services/agencyconf.py index 88ec94e..86c879b 100644 --- a/amarillo/services/agencyconf.py +++ b/amarillo/services/agencyconf.py @@ -33,7 +33,8 @@ class AgencyConfService: api_key = agency_conf.api_key self.agency_id_to_agency_conf[agency_id] = agency_conf - self.api_key_to_agency_id[api_key] = agency_conf.agency_id + if api_key is not None: + self.api_key_to_agency_id[api_key] = agency_conf.agency_id def get_agency_conf(self, agency_id: str) -> AgencyConf: agency_conf = self.agency_id_to_agency_conf.get(agency_id) diff --git a/amarillo/services/config.py b/amarillo/services/config.py index 4029a05..2417715 100644 --- a/amarillo/services/config.py +++ b/amarillo/services/config.py @@ -4,7 +4,6 @@ from pydantic_settings import BaseSettings class Config(BaseSettings): admin_token: str - secret_key: str ride2go_query_data: str env: str = 'DEV' graphhopper_base_url: str = 'https://api.mfdz.de/gh' diff --git a/amarillo/services/oauth2.py b/amarillo/services/oauth2.py index f7c85b0..fa2141c 100644 --- a/amarillo/services/oauth2.py +++ b/amarillo/services/oauth2.py @@ -15,9 +15,9 @@ from amarillo.services.agencies import AgencyService from amarillo.services.agencyconf import AgencyConfService from amarillo.models.Carpool import Agency -from amarillo.services.config import config +from amarillo.services.secrets import secrets -SECRET_KEY = config.secret_key +SECRET_KEY = secrets.secret_key ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30 diff --git a/amarillo/services/secrets.py b/amarillo/services/secrets.py index 756d21c..6092151 100644 --- a/amarillo/services/secrets.py +++ b/amarillo/services/secrets.py @@ -4,6 +4,7 @@ from pydantic_settings import BaseSettings class Secrets(BaseSettings): model_config = ConfigDict(extra='allow') ride2go_token: str = Field(None, env = 'RIDE2GO_TOKEN') + secret_key: str # Read if file exists, otherwise no error (it's in .gitignore)