generalConfig: fix the case when confdir is a list of paths

convert all env variable values containing ':' into a list of paths
+ fix one case where an env variable is not converted to a Path
+ remove unused _gcfg_help

Change-Id: Ibc51ab4606ca51e0e87d0fedfac1aca4952f3270
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/34872
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2024-10-24 13:58:38 +02:00
parent 16d5749d9e
commit 7ab062a449

View File

@@ -37,10 +37,6 @@ from pathlib import Path
SECoP_DEFAULT_PORT = 10767 SECoP_DEFAULT_PORT = 10767
_gcfg_help = """
"""
class GeneralConfig: class GeneralConfig:
"""generalConfig holds server configuration items """generalConfig holds server configuration items
@@ -94,14 +90,16 @@ class GeneralConfig:
if cfg.get('confdir') is None: if cfg.get('confdir') is None:
cfg['confdir'] = configfile.parent cfg['confdir'] = configfile.parent
# environment variables will overwrite the config file # environment variables will overwrite the config file
missing_keys = []
for key in mandatory: for key in mandatory:
env = environ.get(f'FRAPPY_{key.upper()}') env = environ.get(f'FRAPPY_{key.upper()}') or cfg.get(key)
if env is not None: if env is None:
cfg[key] = Path(env) if self.defaults.get(key) is None:
missing_keys = [ missing_keys.append(key)
key for key in mandatory else:
if cfg.get(key) is None and self.defaults.get(key) is None if not isinstance(env, Path):
] env = [Path(v) for v in env.split(':')]
cfg[key] = env
if missing_keys: if missing_keys:
if configfile: if configfile:
raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}") raise KeyError(f"missing value for {' and '.join(missing_keys)} in {configfile}")