Commit 64507cba authored by nk2202's avatar nk2202
Browse files

Merge branch 'feature/endpoint' into 'master'

Separate base_url and endpoint

Closes #1

See merge request !3
parents 27141766 98904594
Pipeline #117768 passed with stage
in 23 seconds
endpoint =
endpoint = prod
base_url =
version = 3.0
token = <token>
base_url =
version = 3.0
token = <token>
base_url =
version = 3.0
token = <token>
......@@ -25,10 +25,14 @@ class ArgumentParser(argparse.ArgumentParser):
help='config file path (default: %(default)s)')
self.add_argument('--endpoint', '-e',
help='endpoint to use.\n'
'Environment: "NETDB_ENDPOINT"\n'
'Config: [DEFAULT]: endpoint')
self.add_argument('--base-url', '-b',
help='webapi server.\n'
'Environment: "NETDB_BASE_URL"\n'
'Config: [DEFAULT]: endpoint')
'Config: [$endpoint]: base_url')
help='webapi version.\n'
'Environment: "NETDB_VERSION"\n'
......@@ -47,23 +51,42 @@ class ArgumentParser(argparse.ArgumentParser):
self.error(f"Config file is readable by others. Please set it at least to 660.")
def load_configoption(option):
if getattr(args, option) is None:
setattr(args, option, os.getenv(f'NETDB_{option.upper()}', None))
if getattr(args, option) is None:
if option == 'base_url':
setattr(args, option, config.get('DEFAULT', 'endpoint', fallback=None))
def load_config(option):
"""load config for an option"""
# if value is already set, we can stop here
if getattr(args, option) is not None:
# try to load option from environment
value = os.getenv(f'NETDB_{option.upper()}', None)
if value is None:
# endpoint should be loaded from DEFAULT section
if option == 'endpoint':
section = 'DEFAULT'
# everything else loads from the $endpoint section
setattr(args, option, config.get(args.base_url, option, fallback=None))
if getattr(args, option) is None:
section = getattr(args, 'endpoint')
# load value from config section
value = config.get(section, option, fallback=None)
# For backwards compatibility:
# if base_url is still unknown use endpoint instead
if option == 'base_url' and value is None:
value = section
if value is None:
f'No {option} specified (looked in args, environment variable '
f'"NETDB_{option.upper()}", config-file in "{args.auth_config}")'
f'"NETDB_{option.upper()}", config-file in "{args.auth_config} section {section}")')
# we have a value now and can use it
setattr(args, option, value)
# load base_url first!
for configoption in ['base_url', 'token', 'version']:
# start with endpoint to get the right config section
for option in ['endpoint', 'base_url', 'token', 'version']:
return args
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment