From 2a9edeec5b11fd0196be970bb982733b28bc8fd3 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 21 Feb 2023 13:42:01 +0100 Subject: [PATCH] conf: Change how api_host_options determine option types The _integer_opts and _boolean_opts specify option types for both global options as well as api_host_options --- osc/conf.py | 20 ++++++++++++++------ tests/test_conf.py | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/osc/conf.py b/osc/conf.py index 7734b80c..fcc153b9 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -189,13 +189,15 @@ if not os.path.isfile('/usr/lib/build/vc') and os.path.isfile('/usr/lib/obs-buil api_host_options = ['user', 'pass', 'passx', 'aliases', 'http_headers', 'realname', 'email', 'sslcertck', 'cafile', 'capath', 'trusted_prj', 'downloadurl', 'sshkey'] + +# _integer_opts and _boolean_opts specify option types for both global options as well as api_host_options _integer_opts = ('build-jobs',) _boolean_opts = ( 'debug', 'do_package_tracking', 'http_debug', 'post_mortem', 'traceback', 'check_filelist', 'checkout_no_colon', 'checkout_rooted', 'check_for_request_on_action', 'linkcontrol', 'show_download_progress', 'request_show_interactive', 'request_show_source_buildstatus', 'review_inherit_group', 'use_keyring', 'no_verify', 'builtin_signature_check', 'http_full_debug', 'include_request_from_project', 'local_service_run', 'buildlog_strip_time', 'no_preinstallimage', - 'status_mtime_heuristic', 'print_web_links', 'ccache', 'sccache', 'build-shell-after-fail') + 'status_mtime_heuristic', 'print_web_links', 'ccache', 'sccache', 'build-shell-after-fail', 'allow_http', 'sslcertck', ) def apply_option_types(config, conffile=""): @@ -211,6 +213,8 @@ def apply_option_types(config, conffile=""): typed_opts = ((_boolean_opts, cp.getboolean), (_integer_opts, cp.getint)) for opts, meth in typed_opts: for opt in opts: + if opt not in config: + continue try: config[opt] = meth('general', opt) except ValueError as e: @@ -826,11 +830,15 @@ def get_config(override_conffile=None, credentials.AbstractCredentialsManager.config_entry, ) for key in optional: - if cp.has_option(url, key): - if key in ('sslcertck', 'allow_http'): - api_host_options[apiurl][key] = cp.getboolean(url, key) - else: - api_host_options[apiurl][key] = cp.get(url, key) + if not cp.has_option(url, key): + continue + if key in _boolean_opts: + api_host_options[apiurl][key] = cp.getboolean(url, key) + elif key in _integer_opts: + api_host_options[apiurl][key] = cp.getint(url, key) + else: + api_host_options[apiurl][key] = cp.get(url, key) + if cp.has_option(url, 'build-root', proper=True): api_host_options[apiurl]['build-root'] = cp.get(url, 'build-root', raw=True) diff --git a/tests/test_conf.py b/tests/test_conf.py index dd21ddd7..acea8347 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -16,23 +16,31 @@ class TestConf(unittest.TestCase): def test_bool_opts_defaults(self): config = osc.conf.config for opt in osc.conf._boolean_opts: + if opt not in config: + continue self.assertIsInstance(config[opt], bool, msg=f"option: '{opt}'") def test_int_opts_defaults(self): config = osc.conf.config for opt in osc.conf._integer_opts: + if opt not in config: + continue self.assertIsInstance(config[opt], int, msg=f"option: '{opt}'") def test_bool_opts(self): osc.conf.get_config() config = osc.conf.config for opt in osc.conf._boolean_opts: + if opt not in config: + continue self.assertIsInstance(config[opt], bool, msg=f"option: '{opt}'") def test_int_opts(self): osc.conf.get_config() config = osc.conf.config for opt in osc.conf._integer_opts: + if opt not in config: + continue self.assertIsInstance(config[opt], int, msg=f"option: '{opt}'")