-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
88 lines (75 loc) · 3.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import yaml
from exceptions import ConfigError
class YamlConfig:
def __init__(self, config_file):
try:
with open(config_file) as f:
config = yaml.full_load(f)
except FileNotFoundError: # pragma: no cover
raise ConfigError(f"File {config_file} not found.")
try:
api = config['api']
self.APP_NAME = api['app_name']
self.API_VERSION = api['version']
self.SWAGGER_UI_CONFIG = api['swagger_ui_config']
self.HOST = api['host']
self.PRIVATE_KEY = api['rsa_private_key']
self.DEBUG = api['debug']
self.SECRET_KEY = api['secret_key']
self.ENV = api['env']
self.CLUSTER_PARTS = api['cluster_parts']
self.VOLUMES_GLOBAL_SIZE = api['volumes_size']['global']
self.VOLUMES_DEFAULT_SIZE = api['volumes_size']['default']
self.ADMINS = api['admins']
self.SUPERADMINS = api['superadmins']
self.ACME_DOMAINS = api['acme_domains']
self.NATS_URI = api['nats']['uri']
self.NATS_CA_CERT = api['nats']['ca_cert']
nats_log_level = api['nats']['log_level']
if nats_log_level in ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']:
self.NATS_LOG_LEVEL = nats_log_level
else:
raise ConfigError("Config file must have " # pragma: no cover
"api>nats>log_level with a value setted in "
"['DEBUG', 'INFO', 'WARN', "
"'ERROR', 'FATAL'].")
sqlalc = api['sqlalchemy']
self.SQLALCHEMY_ECHO = sqlalc['echo']
self.SQLALCHEMY_TRACK_MODIFICATIONS = sqlalc['track_modifications']
# OIDC
_oidc = api['oidc']
self.OIDC_CLIENT_SECRETS = _oidc['client_secrets']
self.OIDC_ID_TOKEN_COOKIE_SECURE = _oidc['id_token_cookie_secure']
self.OIDC_REQUIRE_VERIFIED_EMAIL = _oidc['require_verified_email']
self.OIDC_USER_INFO_ENABLED = _oidc['user_info_enabled']
self.OIDC_OPENID_REALM = _oidc['openid_realm']
self.OIDC_SCOPES = _oidc['scopes']
self.OIDC_INTROSPECTION_AUTH_METHOD = \
_oidc['introspection_auth_method']
# Database
self.SQLALCHEMY_DATABASE_URI = api['database_uri']
self.SQLALCHEMY_ENGINE_OPTIONS = {
# To avoid "SQL lost connection".
'pool_pre_ping': True,
}
if 'preserve' in api:
self.PRESERVE = api['preserve']
else:
self.PRESERVE = {}
self.PAAS_CNAME = api['paas_cname']
# Drivers
self.DRIVERS = config['drivers']
except KeyError as e: # pragma: no cover
raise ConfigError(f"The key `{e}` is not present in the YAML "
"configuration file.")
def get_pubkey_from_driver(self, drivername):
try: # pragma: no cover
driver = self.DRIVERS[drivername]
except KeyError as d: # pragma: no cover
raise ConfigError(f"The driver `{d}` is not present in the YAML "
"configuration file.")
try: # pragma: no cover
return driver['rsa_public_key']
except KeyError as e: # pragma: no cover
raise ConfigError(f"The key `{e}` is not present in the YAML "
f"configuration file for the driver {driver}.")