-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharg.py
63 lines (46 loc) · 2.84 KB
/
arg.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
from argparse import ArgumentParser as Argument_Parser
from about import description, title, version
from reader.config import Config_Reader
from utils.time import get_seconds
class Arg_Reader:
db = None
cr = None
ap = None
@classmethod
def init(cls):
cls.cr = Config_Reader()
cls.cr.read()
cls.ap = Argument_Parser(prog='python3 main.py', description=f'{title}: {description}')
add = cls.ap.add_argument
add('--host', '-o', type=str, help='Hostname/IP of the REST Server', default=cls.cr.cb_host)
add('--port', '-p', type=int, help='TCP Port of the REST Server', default=cls.cr.cb_port)
add('--https', '-q', help='Force to use HTTPS instead of HTTP', action='store_true')
add('--auth', '-t', help='Enable JWT authentication', action='store_true')
add('--auth-header-prefix', '-x', type=str, help='Prefix in the JWT authentication header', default=cls.cr.auth_header_prefix)
add('--auth-secret-key', '-k', type=str, help='Secret key for JWT authentication', default=cls.cr.auth_secret_key)
add('--hb-timeout', '-b', type=str, help='Timeout (with unit, e.g.: 10s) for heartbeat with LCP', default=cls.cr.hb_timeout)
add('--hb-period', '-r', type=str, help='Period (with unit, e.g.: 1min) for the heartbeat with the LCP', default=cls.cr.hb_period)
add('--apm-enabled', '-n', help='Enable Elastic APM integration', action='store_true')
add('--apm-server', '-m', type=str, help='Elastic APM hostname/IP:port', default=cls.cr.elastic_apm_server)
add('--es-endpoint', '-e', type=str, help='Elasticsearch server hostname/IP:port', default=cls.cr.es_endpoint)
add('--es-timeout', '-s', type=str, help='Timeout (with unit, e.g.: 10s) for the connection to Elasticsearch',
default=cls.cr.es_timeout)
add('--es-retry_period', '-y', type=str, help='Period (with unit, e.g.: 1min) to retry the connection to Elasticsearch',
default=cls.cr.es_retry_period)
add('--log-config', '-l', help='Path of the log configuration file (e.g. log.yaml)', default=cls.cr.log_config)
add('--write-config', '-w', help='Write options to config.ini', action='store_true')
add('--version', '-v', help='Show version', action='store_const', const=version)
return cls.ap
@classmethod
def read(cls):
cls.init()
cls.db = cls.ap.parse_args()
cls.db.config = cls.cr
for field in ('hb_timeout', 'hb_period', 'es_timeout', 'es_retry_period'):
setattr(cls.db, field, get_seconds(getattr(cls.db, field)))
cls.db.https = cls.db.https or cls.cr.cb_https
cls.db.auth = cls.db.auth or cls.cr.auth
cls.db.apm_enabled = cls.db.apm_enabled or cls.cr.elastic_apm_enabled
if cls.db.write_config:
cls.cr.write(cls.db)
return cls.db