From 1d2ba931b37cfca5d37d123d124a785d63f53121 Mon Sep 17 00:00:00 2001 From: Liam Marshall Date: Sun, 8 Nov 2015 16:47:09 -0600 Subject: [PATCH] Improve the implementation of the suggestion Write the code to set directives Fix logging in _remove_existing_ssl_directives Fix logging statement --- .../letsencrypt_apache/configurator.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/letsencrypt-apache/letsencrypt_apache/configurator.py b/letsencrypt-apache/letsencrypt_apache/configurator.py index 173be4104..eb8268e33 100644 --- a/letsencrypt-apache/letsencrypt_apache/configurator.py +++ b/letsencrypt-apache/letsencrypt_apache/configurator.py @@ -213,21 +213,10 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): # Assign the final directives; order is maintained in find_dir if self.version >= (2, 4, 8): - logger.debug("Apache version (%s) is >= 2.4.8", - ".".join(map(str,self.version))) - for directive in ["SSLCertificateKeyFile", "SSLCertificateChainFile", - "SSLCACertificatePath"]: - logging.debug("Trying to delete directive '%s'", directive) - directive_tree = self.parser.find_dir(directive, None, vhost.path) - logging.debug(directive_tree) - if directive_tree: - logger.debug("Removing directive %s", directive) - self.aug.remove(re.sub(r"/\w*$", "", directive_tree[-1])) - logging.debug("fullchain path: %s", fullchain_path) self.aug.set(path["cert_path"][-1], fullchain_path) elif self.version < (2, 4, 8): - logger.debug("Apache version (%s) is < 2.4.8", - ".".join(map(str,self.version))) + self.aug.set(path["cert_path"][-1], cert_path) + self.aug.set(path["chain_path"][-1], chain_path) # Save notes about the transaction that took place self.save_notes += ("Changed vhost at %s with addresses of %s\n" @@ -583,6 +572,10 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): # Update Addresses self._update_ssl_vhosts_addrs(vh_p) + # Remove existing SSL directives + logging.info("Removing existing SSL directives") + self._remove_existing_ssl_directives(vh_p) + # Add directives self._add_dummy_ssl_directives(vh_p) @@ -651,6 +644,16 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): return ssl_addrs + def _remove_existing_ssl_directives(self, vh_path): + for directive in ["SSLCertificateKeyFile", "SSLCertificateChainFile", + "SSLCACertificatePath", "SSLCertificateFile"]: + logger.debug("Trying to delete directive '%s'", directive) + directive_tree = self.parser.find_dir(directive, None, vh_path) + logger.debug("Parser found %s", directive_tree) + if directive_tree: + logger.debug("Removing directive %s", directive) + self.aug.remove(re.sub(r"/\w*$", "", directive_tree[-1])) + def _add_dummy_ssl_directives(self, vh_path): self.parser.add_dir(vh_path, "SSLCertificateFile", "insert_cert_file_path")