-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
59 lines (44 loc) · 2.48 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
from configparser import BasicInterpolation as Basic_Interpolation
from configparser import ConfigParser as Config_Parser
from os import path
from pathlib import Path
class Config_Reader:
path = Path(__file__).parent / '../config.ini'
def __init__(self):
self.cr = Config_Parser(interpolation=Config_Reader.Env_Interpolation())
def read(self):
self.cr.read(self.path.resolve())
self.cb_host = self.cr.get('context-broker', 'host', fallback='0.0.0.0')
self.cb_port = self.cr.get('context-broker', 'port', fallback=5000)
self.cb_https = self.cr.getboolean('context-broker', 'https', fallback=False)
self.auth = self.cr.getboolean('auth', 'enabled', fallback=True)
self.auth_header_prefix = self.cr.get('auth', 'header-prefix', fallback='ASTRID')
self.auth_secret_key = self.cr.get('auth', 'secret-key', fallback='astrid-secret-key')
self.hb_timeout = self.cr.get('heartbeat', 'timeout', fallback='10s')
self.hb_period = self.cr.get('heartbeat', 'period', fallback='1min')
self.es_endpoint = self.cr.get('elasticsearch', 'endpoint', fallback='localhost:9200')
self.es_timeout = self.cr.get('elasticsearch', 'timeout', fallback='20s')
self.es_retry_period = self.cr.get('elasticsearch', 'retry-period', fallback='3min')
self.elastic_apm_enabled = self.cr.getboolean('elastic-apm', 'enabled', fallback=False)
self.elastic_apm_server = self.cr.get('elastic-apm', 'server', fallback='http://localhost:8200')
self.log_config = self.cr.get('log', 'config', fallback='log.yaml')
def write(self, db):
# FIXME is it necessary?
self.cr.set('context-broker', 'port', db.port)
self.cr.set('elasticsearch', 'endpoint', db.es_endpoint)
self.cr.set('elasticsearch', 'timeout', db.es_timeout)
with self.path.open('w') as f:
self.cr.write(f)
class Env_Interpolation(Basic_Interpolation):
"""Interpolation which expands environment variables in values."""
def before_get(self, parser, section, option, value, defaults):
"""Execute before getting the value.
:param self: class instance
:param parser: configparser instance
:param section: section value
:param option: option value
:param value: current value
:param defaults: default values
:returns: value with expanded variables
"""
return path.expandvars(value)