updating config to new confz version, db connections take config folder as argument

This commit is contained in:
Mose Mueller
2023-07-31 16:16:03 +02:00
parent 007f1156f7
commit 9abc444868
3 changed files with 27 additions and 27 deletions

View File

@@ -1,37 +1,24 @@
from pathlib import Path
from typing import Literal
from confz import ConfZ, ConfZEnvSource, ConfZFileSource
from confz import BaseConfig, EnvSource
from pydantic import AnyUrl, SecretStr
CONFIG_DIR = Path(__file__).parent.parent.parent.resolve() / "config"
class OperationMode(ConfZ): # type: ignore
class OperationMode(BaseConfig): # type: ignore
environment: Literal["development"] | Literal["production"] = "development"
CONFIG_SOURCES = ConfZEnvSource(allow=["ENVIRONMENT"])
CONFIG_SOURCES = EnvSource(allow=["ENVIRONMENT"])
class PostgreSQLConfig(ConfZ): # type: ignore
class PostgreSQLConfig(BaseConfig): # type: ignore
host: AnyUrl
port: int
database: str
user: str
password: SecretStr
CONFIG_SOURCES = [
ConfZFileSource(f"{CONFIG_DIR}/postgres_{OperationMode().environment}.yaml"),
ConfZEnvSource(prefix="POSTGRES_", allow=["user", "password"], file=".env"),
]
class InfluxDBConfig(ConfZ): # type: ignore
class InfluxDBConfig(BaseConfig): # type: ignore
url: AnyUrl
org: str
token: SecretStr
CONFIG_SOURCES = [
ConfZFileSource(f"{CONFIG_DIR}/influxdb_config.yaml"),
ConfZEnvSource(prefix="INFLUXDB_V2_", allow=["token"], file=".env"),
]