-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
70 lines (49 loc) · 1.75 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2022-Present Indoc Systems
#
# Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE,
# Version 3.0 (the "License") available at https://www.gnu.org/licenses/agpl-3.0.en.html.
# You may not use this file except in compliance with the License.
import logging
from functools import lru_cache
from typing import Any
from typing import Dict
from typing import Optional
from common import VaultClient
from pydantic import BaseSettings
from pydantic import Extra
class VaultConfig(BaseSettings):
"""Store vault related configuration."""
APP_NAME: str = 'pipelinewatch'
CONFIG_CENTER_ENABLED: bool = False
VAULT_URL: Optional[str]
VAULT_CRT: Optional[str]
VAULT_TOKEN: Optional[str]
class Config:
env_file = '.env'
env_file_encoding = 'utf-8'
def load_vault_settings(settings: BaseSettings) -> Dict[str, Any]:
config = VaultConfig()
if not config.CONFIG_CENTER_ENABLED:
return {}
client = VaultClient(config.VAULT_URL, config.VAULT_CRT, config.VAULT_TOKEN)
return client.get_from_vault(config.APP_NAME)
class Settings(BaseSettings):
"""Store service configuration settings."""
DATAOPS_SERVICE: str
METADATA_SERVICE: str
K8S_NAMESPACE: str = 'greenroom'
GREEN_ZONE_LABEL: str = 'Greenroom'
CORE_ZONE_LABEL: str = 'Core'
LOGGING_LEVEL: int = logging.INFO
LOGGING_FORMAT: str = 'json'
class Config:
env_file = '.env'
env_file_encoding = 'utf-8'
extra = Extra.allow
@classmethod
def customise_sources(cls, init_settings, env_settings, file_secret_settings):
return env_settings, init_settings, load_vault_settings, file_secret_settings
@lru_cache(1)
def get_settings():
settings = Settings()
return settings