-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
70 lines (50 loc) · 1.88 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
import json
import logging
import os
import tempfile
import subprocess
loglevel = os.environ.get('LOGLEVEL', 'INFO').upper()
config_file_path = os.path.expanduser("/etc/decentrafly/config.json")
def write_to_file(path, content):
with tempfile.NamedTemporaryFile("w", delete=False) as tmp:
tmp.write(content)
tmp.close()
return subprocess.call(['sudo', 'mv', tmp.name, path])
def load_config():
if os.path.isfile(config_file_path):
config = json.load(open(config_file_path))
return config
else:
return {}
def write_config(updated_config):
write_to_file(config_file_path,
json.dumps(updated_config, indent=2))
def persist_config_entry(k, v):
current_config = load_config()
current_config[k] = v
return write_to_file(config_file_path, json.dumps(current_config,
indent=2))
def basic_logging():
logging.basicConfig(level=loglevel, format='%(message)s')
default_config = {
"DCF_LOG_INTERVAL": "20",
"DCF_CA_FILE": '/etc/decentrafly/mtls-ca.crt',
"DCF_CLIENT_CRT_FILE": '/etc/decentrafly/mtls-cert.crt',
"DCF_CLIENT_KEY_FILE": '/etc/decentrafly/mtls-private.key',
"DCF_CLIENT_ID": "notset",
"DCF_IOT_TOPIC": "beast/ingest/0",
"DCF_MAX_INTERVAL": "1.0",
"DCF_MAX_MESSAGE_SIZE": "100000",
"DCF_TRIGGER_SIZE": "50000",
"DCF_READSB_HOST": "localhost",
"DCF_READSB_PORT": "30005",
"DCF_MAIN_DOMAIN": "api.decentrafly.org",
"DCF_SECURE_ADSB_HOST": "localhost",
"DCF_SECURE_ADSB_PORT": "40004",
"DCF_SECURE_ADSB_HOSTNAME": "feed.decentrafly.org",
}
environment_config = {k: os.getenv(k) for k in default_config.keys()
if os.getenv(k) is not None}
effective_config = {**default_config, **load_config(), **environment_config}
def ec(k):
return effective_config.get(k.upper())