diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index cf67f53a65a..4f02c3be145 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -705,6 +705,17 @@ class ConfigManager: else: raise AnsibleUndefinedConfigEntry(f'No config definition exists for {_get_config_label(plugin_type, plugin_name, config)}.') + if config == "GALAXY_RETRY_HTTP_ERROR_CODES": + try: + for i in range(0, len(value)): + http_error_code = int(value[i]) + if http_error_code < 100 or http_error_code > 999: + raise ValueError(f"{http_error_code} must be between 100-999") + value[i] = http_error_code + except ValueError: + raise AnsibleOptionsError(f'Invalid value {value!r} for config {_get_config_label(plugin_type, plugin_name, config)}.', + help_text='Valid values are 3-digit numbers.') + if not _tags.Origin.is_tagged_on(value): value = _tags.Origin(description=f'').tag(value) diff --git a/test/units/config/test_manager.py b/test/units/config/test_manager.py index 3bd8f05a3d2..0339c83e167 100644 --- a/test/units/config/test_manager.py +++ b/test/units/config/test_manager.py @@ -300,3 +300,20 @@ def test_config_trust_from_file(tmp_path: pathlib.Path) -> None: assert origin assert origin.path == str(cfg_path) assert origin.description == "section 'testing' option 'valid'" + + +def test_galaxy_retry_http_error_codes(tmp_path: pathlib.Path) -> None: + cfg_path = tmp_path / 'test.cfg' + cfg_path.write_text("[galaxy]\nretry_http_error_codes=429,502,520") + manager = ConfigManager(str(cfg_path)) + result = manager.get_config_value("GALAXY_RETRY_HTTP_ERROR_CODES") + assert result == [429, 502, 520] + + +def test_galaxy_retry_http_error_codes_invalid(tmp_path: pathlib.Path) -> None: + cfg_path = tmp_path / 'test.cfg' + cfg_path.write_text("[galaxy]\nretry_http_error_codes=429,502,520,invalid") + manager = ConfigManager(str(cfg_path)) + with pytest.raises(AnsibleOptionsError) as exec_info: + manager.get_config_value("GALAXY_RETRY_HTTP_ERROR_CODES") + assert "Invalid value [429, 502, 520, 'invalid'] for config" in str(exec_info.value)