5
from pydantic import BaseConfig
6
from pydantic_settings import BaseSettings
8
BaseConfig.arbitrary_types_allowed = True
9
logging.basicConfig(level=logging.INFO)
13
class Config(BaseSettings):
14
APP_HOST: str = os.environ.get("APP_HOST") or 'localhost'
15
APP_PORT: int = os.environ.get("APP_PORT") or '8000'
16
APP_PROTOCOL: str = os.environ.get('APP_PROTOCOL') or 'http'
17
BUS_HOST: str = os.environ.get('BUS_HOST') or '127.0.0.1'
18
BUS_PORT: str = os.environ.get('BUS_PORT') or '8099'
19
INTERCO_TOKEN: str = os.environ.get('INTERCO_TOKEN') or 'netu'
22
class DevelopmentConfig(Config):
25
class DockerConfig(Config):
26
BUS_HOST: str = 'bus_app'
29
class LocalConfig(Config):
33
class ProductionConfig(Config):
42
Метод для удобного импорта адаптеров по пути
44
components = name.split('.')
45
mod = __import__(components[0])
46
for comp in components[1:]:
47
mod = getattr(mod, comp)
51
env = os.getenv("ENV", "local")
52
for name, value in os.environ.items():
53
logging.info("{0}: {1}".format(name, value))
57
"dev": DevelopmentConfig(),
58
"local": LocalConfig(),
59
"docker": DockerConfig(),
60
"prod": ProductionConfig(),
62
config = config_type[env]
65
config: Config = get_config()