diff --git a/certbot/client.py b/certbot/client.py index 95882a9fcfe..c5b33a7ff7e 100644 --- a/certbot/client.py +++ b/certbot/client.py @@ -168,7 +168,7 @@ def perform_registration(acme, config): "registration again." % config.email) raise errors.Error(msg) else: - config.namespace.email = display_ops.get_email(invalid=True) + config.email = display_ops.get_email(invalid=True) return perform_registration(acme, config) else: raise diff --git a/certbot/configuration.py b/certbot/configuration.py index d2537892265..30c6f0437f5 100644 --- a/certbot/configuration.py +++ b/certbot/configuration.py @@ -42,7 +42,7 @@ class NamespaceConfig(object): """ def __init__(self, namespace): - self.namespace = namespace + object.__setattr__(self, 'namespace', namespace) self.namespace.config_dir = os.path.abspath(self.namespace.config_dir) self.namespace.work_dir = os.path.abspath(self.namespace.work_dir) @@ -54,6 +54,9 @@ def __init__(self, namespace): def __getattr__(self, name): return getattr(self.namespace, name) + def __setattr__(self, name, value): + setattr(self.namespace, name, value) + @property def server_path(self): """File path based on ``server``.""" diff --git a/certbot/main.py b/certbot/main.py index 118c0f9586b..2d0d9348ec5 100644 --- a/certbot/main.py +++ b/certbot/main.py @@ -359,7 +359,7 @@ def _determine_account(config): acc = accounts[0] else: # no account registered yet if config.email is None and not config.register_unsafely_without_email: - config.namespace.email = display_ops.get_email() + config.email = display_ops.get_email() def _tos_cb(regr): if config.tos: @@ -382,7 +382,7 @@ def _tos_cb(regr): raise errors.Error( "Unable to register an account with ACME server") - config.namespace.account = acc.id + config.account = acc.id return acc, acme @@ -459,7 +459,7 @@ def register(config, unused_plugins): return ("--register-unsafely-without-email provided, however, a " "new e-mail address must\ncurrently be provided when " "updating a registration.") - config.namespace.email = display_ops.get_email(optional=False) + config.email = display_ops.get_email(optional=False) acc, acme = _determine_account(config) acme_client = client.Client(config, acc, None, None, acme=acme) @@ -565,7 +565,7 @@ def certificates(config, unused_plugins): def revoke(config, unused_plugins): # TODO: coop with renewal config """Revoke a previously obtained certificate.""" # For user-agent construction - config.namespace.installer = config.namespace.authenticator = "None" + config.installer = config.authenticator = "None" if config.key_path is not None: # revocation by cert key logger.debug("Revoking %s using cert key %s", config.cert_path[0], config.key_path[0]) diff --git a/certbot/plugins/selection.py b/certbot/plugins/selection.py index 81387c4359d..d138001e6db 100644 --- a/certbot/plugins/selection.py +++ b/certbot/plugins/selection.py @@ -137,9 +137,8 @@ def choose_plugin(prepared, question): def record_chosen_plugins(config, plugins, auth, inst): "Update the config entries to reflect the plugins we actually selected." - cn = config.namespace - cn.authenticator = plugins.find_init(auth).name if auth else "None" - cn.installer = plugins.find_init(inst).name if inst else "None" + config.authenticator = plugins.find_init(auth).name if auth else "None" + config.installer = plugins.find_init(inst).name if inst else "None" def choose_configurator_plugins(config, plugins, verb): diff --git a/certbot/renewal.py b/certbot/renewal.py index a0cc872a0c6..6eb1717631c 100644 --- a/certbot/renewal.py +++ b/certbot/renewal.py @@ -103,13 +103,13 @@ def _restore_webroot_config(config, renewalparams): """ if "webroot_map" in renewalparams: if not cli.set_by_cli("webroot_map"): - config.namespace.webroot_map = renewalparams["webroot_map"] + config.webroot_map = renewalparams["webroot_map"] elif "webroot_path" in renewalparams: logger.debug("Ancient renewal conf file without webroot-map, restoring webroot-path") wp = renewalparams["webroot_path"] if isinstance(wp, str): # prior to 0.1.0, webroot_path was a string wp = [wp] - config.namespace.webroot_path = wp + config.webroot_path = wp def _restore_plugin_configs(config, renewalparams): @@ -148,10 +148,10 @@ def _restore_plugin_configs(config, renewalparams): if config_value in ("None", "True", "False"): # bool("False") == True # pylint: disable=eval-used - setattr(config.namespace, config_item, eval(config_value)) + setattr(config, config_item, eval(config_value)) else: cast = cli.argparse_type(config_item) - setattr(config.namespace, config_item, cast(config_value)) + setattr(config, config_item, cast(config_value)) def restore_required_config_elements(config, renewalparams): @@ -172,7 +172,7 @@ def restore_required_config_elements(config, renewalparams): for item_name, restore_func in required_items: if item_name in renewalparams and not cli.set_by_cli(item_name): value = restore_func(item_name, renewalparams[item_name]) - setattr(config.namespace, item_name, value) + setattr(config, item_name, value) def _restore_pref_challs(unused_name, value): diff --git a/certbot/tests/configuration_test.py b/certbot/tests/configuration_test.py index 3a2f7d29181..66a07ddddb5 100644 --- a/certbot/tests/configuration_test.py +++ b/certbot/tests/configuration_test.py @@ -120,6 +120,12 @@ def test_renewal_absolute_paths(self): self.assertTrue(os.path.isabs(config.live_dir)) self.assertTrue(os.path.isabs(config.renewal_configs_dir)) + def test_get_and_set_attr(self): + self.config.foo = 42 + self.assertEqual(self.config.namespace.foo, 42) + self.config.namespace.bar = 1337 + self.assertEqual(self.config.bar, 1337) + if __name__ == '__main__': unittest.main() # pragma: no cover diff --git a/certbot/tests/renewal_test.py b/certbot/tests/renewal_test.py index cd53aa91c55..d97e0578384 100644 --- a/certbot/tests/renewal_test.py +++ b/certbot/tests/renewal_test.py @@ -52,7 +52,7 @@ def _call(cls, *args, **kwargs): def test_allow_subset_of_names_success(self, mock_set_by_cli): mock_set_by_cli.return_value = False self._call(self.config, {'allow_subset_of_names': 'True'}) - self.assertTrue(self.config.namespace.allow_subset_of_names is True) + self.assertTrue(self.config.allow_subset_of_names is True) @mock.patch('certbot.renewal.cli.set_by_cli') def test_allow_subset_of_names_failure(self, mock_set_by_cli): @@ -68,7 +68,7 @@ def test_pref_challs_list(self, mock_set_by_cli): self._call(self.config, renewalparams) expected = [challenges.TLSSNI01.typ, challenges.HTTP01.typ, challenges.DNS01.typ] - self.assertEqual(self.config.namespace.pref_challs, expected) + self.assertEqual(self.config.pref_challs, expected) @mock.patch('certbot.renewal.cli.set_by_cli') def test_pref_challs_str(self, mock_set_by_cli): @@ -76,7 +76,7 @@ def test_pref_challs_str(self, mock_set_by_cli): renewalparams = {'pref_challs': 'dns'} self._call(self.config, renewalparams) expected = [challenges.DNS01.typ] - self.assertEqual(self.config.namespace.pref_challs, expected) + self.assertEqual(self.config.pref_challs, expected) @mock.patch('certbot.renewal.cli.set_by_cli') def test_pref_challs_failure(self, mock_set_by_cli): @@ -88,7 +88,7 @@ def test_pref_challs_failure(self, mock_set_by_cli): def test_must_staple_success(self, mock_set_by_cli): mock_set_by_cli.return_value = False self._call(self.config, {'must_staple': 'True'}) - self.assertTrue(self.config.namespace.must_staple is True) + self.assertTrue(self.config.must_staple is True) @mock.patch('certbot.renewal.cli.set_by_cli') def test_must_staple_failure(self, mock_set_by_cli):