mirror of
https://github.com/certbot/certbot.git
synced 2026-06-07 15:52:08 -04:00
Merge pull request #4665 from certbot/span-plan2
Augeas span workarounds
This commit is contained in:
commit
6723b15f78
3 changed files with 44 additions and 3 deletions
|
|
@ -120,8 +120,8 @@ class AugeasConfigurator(common.Plugin):
|
|||
|
||||
# If the augeas tree didn't change, no files were saved and a backup
|
||||
# should not be created
|
||||
save_files = set()
|
||||
if save_paths:
|
||||
save_files = set()
|
||||
for path in save_paths:
|
||||
save_files.add(self.aug.get(path)[6:])
|
||||
|
||||
|
|
@ -140,6 +140,12 @@ class AugeasConfigurator(common.Plugin):
|
|||
self.save_notes = ""
|
||||
self.aug.save()
|
||||
|
||||
# Force reload if files were modified
|
||||
# This is needed to recalculate augeas directive span
|
||||
if save_files:
|
||||
for sf in save_files:
|
||||
self.aug.remove("/files/"+sf)
|
||||
self.aug.load()
|
||||
if title and not temporary:
|
||||
try:
|
||||
self.reverter.finalize_checkpoint(title)
|
||||
|
|
|
|||
|
|
@ -1065,8 +1065,28 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||
span_end = span_val[6]
|
||||
with open(span_filep, 'r') as fh:
|
||||
fh.seek(span_start)
|
||||
vh_contents = fh.read(span_end-span_start)
|
||||
return vh_contents.split("\n")
|
||||
vh_contents = fh.read(span_end-span_start).split("\n")
|
||||
self._remove_closing_vhost_tag(vh_contents)
|
||||
return vh_contents
|
||||
|
||||
def _remove_closing_vhost_tag(self, vh_contents):
|
||||
"""Removes the closing VirtualHost tag if it exists.
|
||||
|
||||
This method modifies vh_contents directly to remove the closing
|
||||
tag. If the closing vhost tag is found, everything on the line
|
||||
after it is also removed. Whether or not this tag is included
|
||||
in the result of span depends on the Augeas version.
|
||||
|
||||
:param list vh_contents: VirtualHost block contents to check
|
||||
|
||||
"""
|
||||
for offset, line in enumerate(reversed(vh_contents)):
|
||||
if line:
|
||||
line_index = line.lower().find("</virtualhost>")
|
||||
if line_index != -1:
|
||||
content_index = len(vh_contents) - offset - 1
|
||||
vh_contents[content_index] = line[:line_index]
|
||||
break
|
||||
|
||||
def _update_ssl_vhosts_addrs(self, vh_path):
|
||||
ssl_addrs = set()
|
||||
|
|
|
|||
|
|
@ -597,6 +597,21 @@ class MultipleVhostsTest(util.ApacheTest):
|
|||
# already listens to the correct port
|
||||
self.assertEqual(mock_add_dir.call_count, 0)
|
||||
|
||||
def test_make_vhost_ssl_with_mock_span(self):
|
||||
# span excludes the closing </VirtualHost> tag in older versions
|
||||
# of Augeas
|
||||
return_value = [self.vh_truth[0].filep, 1, 12, 0, 0, 0, 1142]
|
||||
with mock.patch.object(self.config.aug, 'span') as mock_span:
|
||||
mock_span.return_value = return_value
|
||||
self.test_make_vhost_ssl()
|
||||
|
||||
def test_make_vhost_ssl_with_mock_span2(self):
|
||||
# span includes the closing </VirtualHost> tag in newer versions
|
||||
# of Augeas
|
||||
return_value = [self.vh_truth[0].filep, 1, 12, 0, 0, 0, 1157]
|
||||
with mock.patch.object(self.config.aug, 'span') as mock_span:
|
||||
mock_span.return_value = return_value
|
||||
self.test_make_vhost_ssl()
|
||||
|
||||
def test_make_vhost_ssl(self):
|
||||
ssl_vhost = self.config.make_vhost_ssl(self.vh_truth[0])
|
||||
|
|
|
|||
Loading…
Reference in a new issue