-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: use bento base pydantic config
- Loading branch information
1 parent
19990be
commit d3bfe30
Showing
3 changed files
with
14 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import json | ||
|
||
from bento_lib.logging import LogLevelLiteral | ||
from bento_lib.config.pydantic import BentoBaseConfig | ||
from fastapi import Depends | ||
from functools import lru_cache | ||
from pydantic.fields import FieldInfo | ||
from pydantic_settings import BaseSettings, EnvSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict | ||
from typing import Annotated, Any, Literal | ||
from typing import Annotated, Literal | ||
|
||
from .constants import SERVICE_TYPE | ||
|
||
|
@@ -16,48 +12,18 @@ | |
] | ||
|
||
|
||
class CorsOriginsParsingSource(EnvSettingsSource): | ||
def prepare_field_value(self, field_name: str, field: FieldInfo, value: Any, value_is_complex: bool) -> Any: | ||
if field_name == "cors_origins": | ||
return tuple(x.strip() for x in value.split(";")) if value is not None else () | ||
return json.loads(value) if value_is_complex else value | ||
|
||
|
||
class Config(BaseSettings): | ||
bento_debug: bool = False | ||
bento_container_local: bool = False | ||
|
||
class Config(BentoBaseConfig): | ||
service_id: str = str(":".join(list(SERVICE_TYPE.values())[:2])) | ||
service_name: str = "Bento Drop Box Service" | ||
service_description: str = "Drop box service for a Bento platform node." | ||
service_contact_url: str = "mailto:[email protected]" | ||
service_url: str = "http://127.0.0.1:5000" # base URL to construct object URIs from | ||
|
||
service_data: str = "data/" | ||
service_data_source: Literal["local"] = "local" | ||
traversal_limit: int = 16 | ||
|
||
bento_authz_service_url: str # Bento authorization service base URL | ||
authz_enabled: bool = True | ||
|
||
cors_origins: tuple[str, ...] | ||
|
||
log_level: LogLevelLiteral = "debug" | ||
|
||
# Make Config instances hashable + immutable | ||
model_config = SettingsConfigDict(frozen=True) | ||
|
||
@classmethod | ||
def settings_customise_sources( | ||
cls, | ||
settings_cls: type[BaseSettings], | ||
init_settings: PydanticBaseSettingsSource, | ||
env_settings: PydanticBaseSettingsSource, | ||
dotenv_settings: PydanticBaseSettingsSource, | ||
file_secret_settings: PydanticBaseSettingsSource, | ||
) -> tuple[PydanticBaseSettingsSource, ...]: | ||
return (CorsOriginsParsingSource(settings_cls),) | ||
|
||
|
||
@lru_cache() | ||
def get_config() -> Config: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters