mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:19 +02:00
Remove unused code for renaming certificates (#10437)
Fixes https://github.com/certbot/certbot/issues/10397 This code was not being called, so let's remove it.
This commit is contained in:
@@ -26,32 +26,6 @@ logger = logging.getLogger(__name__)
|
||||
###################
|
||||
|
||||
|
||||
def rename_lineage(config: configuration.NamespaceConfig) -> None:
|
||||
"""Rename the specified lineage to the new name.
|
||||
|
||||
:param config: Configuration.
|
||||
:type config: :class:`certbot._internal.configuration.NamespaceConfig`
|
||||
|
||||
"""
|
||||
certname = get_certnames(config, "rename")[0]
|
||||
|
||||
new_certname = config.new_certname
|
||||
if not new_certname:
|
||||
code, new_certname = display_util.input_text(
|
||||
"Enter the new name for certificate {0}".format(certname),
|
||||
force_interactive=True)
|
||||
if code != display_util.OK or not new_certname:
|
||||
raise errors.Error("User ended interaction.")
|
||||
|
||||
lineage = lineage_for_certname(config, certname)
|
||||
if not lineage:
|
||||
raise errors.ConfigurationError("No existing certificate with name "
|
||||
"{0} found.".format(certname))
|
||||
storage.rename_renewal_config(certname, new_certname, config)
|
||||
display_util.notification("Successfully renamed {0} to {1}."
|
||||
.format(certname, new_certname), pause=False)
|
||||
|
||||
|
||||
def certificates(config: configuration.NamespaceConfig) -> None:
|
||||
"""Display information about certs configured with Certbot
|
||||
|
||||
|
||||
@@ -1269,26 +1269,6 @@ def rollback(config: configuration.NamespaceConfig, plugins: plugins_disco.Plugi
|
||||
client.rollback(config.installer, config.checkpoints, config, plugins)
|
||||
|
||||
|
||||
def rename(config: configuration.NamespaceConfig,
|
||||
unused_plugins: plugins_disco.PluginsRegistry) -> None:
|
||||
"""Rename a certificate
|
||||
|
||||
Use the information in the config file to rename an existing
|
||||
lineage.
|
||||
|
||||
:param config: Configuration object
|
||||
:type config: configuration.NamespaceConfig
|
||||
|
||||
:param unused_plugins: List of plugins (deprecated)
|
||||
:type unused_plugins: plugins_disco.PluginsRegistry
|
||||
|
||||
:returns: `None`
|
||||
:rtype: None
|
||||
|
||||
"""
|
||||
cert_manager.rename_lineage(config)
|
||||
|
||||
|
||||
def delete(config: configuration.NamespaceConfig,
|
||||
unused_plugins: plugins_disco.PluginsRegistry) -> None:
|
||||
"""Delete a certificate
|
||||
|
||||
@@ -170,25 +170,6 @@ def atomic_rewrite(config_filename: str, new_config: configobj.ConfigObj) -> Non
|
||||
filesystem.replace(temp_filename, config_filename)
|
||||
|
||||
|
||||
def rename_renewal_config(prev_name: str, new_name: str,
|
||||
cli_config: configuration.NamespaceConfig) -> None:
|
||||
"""Renames cli_config.certname's config to cli_config.new_certname.
|
||||
|
||||
:param .NamespaceConfig cli_config: parsed command line
|
||||
arguments
|
||||
"""
|
||||
prev_filename = renewal_filename_for_lineagename(cli_config, prev_name)
|
||||
new_filename = renewal_filename_for_lineagename(cli_config, new_name)
|
||||
if os.path.exists(new_filename):
|
||||
raise errors.ConfigurationError("The new certificate name "
|
||||
"is already in use.")
|
||||
try:
|
||||
filesystem.replace(prev_filename, new_filename)
|
||||
except OSError:
|
||||
raise errors.ConfigurationError("Please specify a valid filename "
|
||||
"for the new certificate name.")
|
||||
|
||||
|
||||
def update_configuration(lineagename: str, archive_dir: str, target: Mapping[str, str],
|
||||
cli_config: configuration.NamespaceConfig) -> configobj.ConfigObj:
|
||||
"""Modifies lineagename's config to contain the specified values.
|
||||
|
||||
@@ -357,100 +357,6 @@ class DomainsForCertnameTest(BaseCertManagerTest):
|
||||
assert mock_make_or_verify_dir.called
|
||||
|
||||
|
||||
class RenameLineageTest(BaseCertManagerTest):
|
||||
"""Tests for certbot._internal.cert_manager.rename_lineage"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.config.certname = "example.org"
|
||||
self.config.new_certname = "after"
|
||||
|
||||
def _call(self, *args, **kwargs):
|
||||
from certbot._internal import cert_manager
|
||||
return cert_manager.rename_lineage(*args, **kwargs)
|
||||
|
||||
@mock.patch('certbot._internal.storage.renewal_conf_files')
|
||||
@test_util.patch_display_util()
|
||||
def test_no_certname(self, mock_get_utility, mock_renewal_conf_files):
|
||||
self.config.certname = None
|
||||
self.config.new_certname = "two"
|
||||
|
||||
# if not choices
|
||||
mock_renewal_conf_files.return_value = []
|
||||
with pytest.raises(errors.Error):
|
||||
self._call(self.config)
|
||||
|
||||
mock_renewal_conf_files.return_value = ["one.conf"]
|
||||
util_mock = mock_get_utility()
|
||||
util_mock.menu.return_value = (display_util.CANCEL, 0)
|
||||
with pytest.raises(errors.Error):
|
||||
self._call(self.config)
|
||||
|
||||
util_mock.menu.return_value = (display_util.OK, -1)
|
||||
with pytest.raises(errors.Error):
|
||||
self._call(self.config)
|
||||
|
||||
@test_util.patch_display_util()
|
||||
def test_no_new_certname(self, mock_get_utility):
|
||||
self.config.certname = "one"
|
||||
self.config.new_certname = None
|
||||
|
||||
util_mock = mock_get_utility()
|
||||
util_mock.input.return_value = (display_util.CANCEL, "name")
|
||||
with pytest.raises(errors.Error):
|
||||
self._call(self.config)
|
||||
|
||||
util_mock.input.return_value = (display_util.OK, None)
|
||||
with pytest.raises(errors.Error):
|
||||
self._call(self.config)
|
||||
|
||||
@test_util.patch_display_util()
|
||||
@mock.patch('certbot._internal.cert_manager.lineage_for_certname')
|
||||
def test_no_existing_certname(self, mock_lineage_for_certname, unused_get_utility):
|
||||
self.config.certname = "one"
|
||||
self.config.new_certname = "two"
|
||||
mock_lineage_for_certname.return_value = None
|
||||
with pytest.raises(errors.ConfigurationError):
|
||||
self._call(self.config)
|
||||
|
||||
@test_util.patch_display_util()
|
||||
@mock.patch("certbot._internal.storage.RenewableCert._check_symlinks")
|
||||
def test_rename_cert(self, mock_check, unused_get_utility):
|
||||
mock_check.return_value = True
|
||||
self._call(self.config)
|
||||
from certbot._internal import cert_manager
|
||||
updated_lineage = cert_manager.lineage_for_certname(self.config, self.config.new_certname)
|
||||
assert updated_lineage is not None
|
||||
assert updated_lineage.lineagename == self.config.new_certname
|
||||
|
||||
@test_util.patch_display_util()
|
||||
@mock.patch("certbot._internal.storage.RenewableCert._check_symlinks")
|
||||
def test_rename_cert_interactive_certname(self, mock_check, mock_get_utility):
|
||||
mock_check.return_value = True
|
||||
self.config.certname = None
|
||||
util_mock = mock_get_utility()
|
||||
util_mock.menu.return_value = (display_util.OK, 0)
|
||||
self._call(self.config)
|
||||
from certbot._internal import cert_manager
|
||||
updated_lineage = cert_manager.lineage_for_certname(self.config, self.config.new_certname)
|
||||
assert updated_lineage is not None
|
||||
assert updated_lineage.lineagename == self.config.new_certname
|
||||
|
||||
@test_util.patch_display_util()
|
||||
@mock.patch("certbot._internal.storage.RenewableCert._check_symlinks")
|
||||
def test_rename_cert_bad_new_certname(self, mock_check, unused_get_utility):
|
||||
mock_check.return_value = True
|
||||
|
||||
# for example, don't rename to existing certname
|
||||
self.config.new_certname = "example.org"
|
||||
with pytest.raises(errors.ConfigurationError):
|
||||
self._call(self.config)
|
||||
|
||||
self.config.new_certname = "one{0}two".format(os.path.sep)
|
||||
with pytest.raises(errors.ConfigurationError):
|
||||
self._call(self.config)
|
||||
|
||||
|
||||
class DuplicativeCertsTest(storage_test.BaseRenewableCertTest):
|
||||
"""Test to avoid duplicate lineages."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user