From 51500bef2bf0019c1ba9daa80255c992c4a3ab73 Mon Sep 17 00:00:00 2001 From: DigitalTrustCenter <107399020+DigitalTrustCenter@users.noreply.github.com> Date: Tue, 2 Jan 2024 11:33:23 +0100 Subject: [PATCH] Only load the config once on intelmqctl init --- CHANGELOG.md | 1 + intelmq/bin/intelmqctl.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c419c2957..2d511b63c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ (PR#2408 and PR#2414 by Jan Kaliszewski). - `intelmq.lib.upgrades`: Replace deprecated instances of `url2fqdn` experts by the new `url` expert in runtime configuration (PR#2432 by Sebastian Wagner). - `intelmq.lib.bot`: Ensure closing log files on reloading (PR#2435 by Kamil Mankowski). +- Only load the config once when starting intelmqctl (which makes IntelMQ API calls take less time) (PR#2444 by DigitalTrustCenter). ### Development - Makefile: Add codespell and test commands (PR#2425 by Sebastian Wagner). diff --git a/intelmq/bin/intelmqctl.py b/intelmq/bin/intelmqctl.py index 51301b1d8..2add4b82e 100644 --- a/intelmq/bin/intelmqctl.py +++ b/intelmq/bin/intelmqctl.py @@ -87,6 +87,11 @@ def __init__(self, interactive: bool = False, returntype: ReturnType = ReturnTyp self._parameters.logging_handler = 'file' self._parameters.logging_path = DEFAULT_LOGGING_PATH + try: + self._runtime_configuration = utils.load_configuration(RUNTIME_CONF_FILE) + except ValueError as exc: # pragma: no cover + self.abort(f'Error loading {RUNTIME_CONF_FILE!r}: {exc}') + # Try to get logging_level from defaults configuration, else use default (defined above) defaults_loading_exc = None try: @@ -203,11 +208,6 @@ def __init__(self, interactive: bool = False, returntype: ReturnType = ReturnTyp intelmqctl debug --get-environment-variables ''' - try: - self._runtime_configuration = utils.load_configuration(RUNTIME_CONF_FILE) - except ValueError as exc: # pragma: no cover - self.abort(f'Error loading {RUNTIME_CONF_FILE!r}: {exc}') - self._processmanagertype = getattr(self._parameters, 'process_manager', 'intelmq') if self._processmanagertype not in process_managers(): self.abort('Invalid process manager given: %r, should be one of %r.' '' % (self._processmanagertype, list(process_managers().keys()))) @@ -384,7 +384,8 @@ def __init__(self, interactive: bool = False, returntype: ReturnType = ReturnTyp ) def load_defaults_configuration(self, silent=False): - for option, value in utils.get_global_settings().items(): + global_settings = self._runtime_configuration.get('global', {}) + for option, value in global_settings.items(): setattr(self._parameters, option, value) # copied from intelmq.lib.bot, should be refactored to e.g. intelmq.lib.config