mirror of https://github.com/CIRCL/lookyloo
fix: Properly load the config files when needed.
parent
a7ecaee8c4
commit
9663c5de87
|
@ -54,7 +54,7 @@ def get_email_template() -> str:
|
||||||
|
|
||||||
def load_configs(path_to_config_files: Optional[Union[str, Path]]=None):
|
def load_configs(path_to_config_files: Optional[Union[str, Path]]=None):
|
||||||
global configs
|
global configs
|
||||||
if configs is not None:
|
if configs:
|
||||||
return
|
return
|
||||||
if path_to_config_files:
|
if path_to_config_files:
|
||||||
if isinstance(path_to_config_files, str):
|
if isinstance(path_to_config_files, str):
|
||||||
|
@ -77,7 +77,7 @@ def load_configs(path_to_config_files: Optional[Union[str, Path]]=None):
|
||||||
def get_config(config_type: str, entry: str) -> Any:
|
def get_config(config_type: str, entry: str) -> Any:
|
||||||
"""Get an entry from the given config_type file. Automatic fallback to the sample file"""
|
"""Get an entry from the given config_type file. Automatic fallback to the sample file"""
|
||||||
global configs
|
global configs
|
||||||
if configs is None:
|
if not configs:
|
||||||
load_configs()
|
load_configs()
|
||||||
if config_type in configs:
|
if config_type in configs:
|
||||||
if entry in configs[config_type]:
|
if entry in configs[config_type]:
|
||||||
|
@ -85,8 +85,8 @@ def get_config(config_type: str, entry: str) -> Any:
|
||||||
else:
|
else:
|
||||||
logger.warning(f'Unable to find {entry} in config file.')
|
logger.warning(f'Unable to find {entry} in config file.')
|
||||||
else:
|
else:
|
||||||
logger.warning('No generic config file available.')
|
logger.warning(f'No {config_type} config file available.')
|
||||||
logger.warning('Falling back on sample config, please initialize the generic config file.')
|
logger.warning(f'Falling back on sample config, please initialize the {config_type} config file.')
|
||||||
with (get_homedir() / 'config' / f'{config_type}.json.sample').open() as _c:
|
with (get_homedir() / 'config' / f'{config_type}.json.sample').open() as _c:
|
||||||
sample_config = json.load(_c)
|
sample_config = json.load(_c)
|
||||||
return sample_config[entry]
|
return sample_config[entry]
|
||||||
|
|
Loading…
Reference in New Issue