mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +02:00
Merge pull request #2134 from joohoi/parse_includes
Search all paths included from across the configuration for VirtualHosts
This commit is contained in:
@@ -488,15 +488,27 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
:rtype: list
|
:rtype: list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Search vhost-root, httpd.conf for possible virtual hosts
|
# Search base config, and all included paths for VirtualHosts
|
||||||
paths = self.aug.match(
|
|
||||||
("/files%s//*[label()=~regexp('%s')]" %
|
|
||||||
(self.conf("vhost-root"), parser.case_i("VirtualHost"))))
|
|
||||||
|
|
||||||
vhs = []
|
vhs = []
|
||||||
|
vhost_paths = {}
|
||||||
|
for vhost_path in self.parser.parser_paths.keys():
|
||||||
|
paths = self.aug.match(
|
||||||
|
("/files%s//*[label()=~regexp('%s')]" %
|
||||||
|
(vhost_path, parser.case_i("VirtualHost"))))
|
||||||
|
for path in paths:
|
||||||
|
new_vhost = self._create_vhost(path)
|
||||||
|
realpath = os.path.realpath(new_vhost.filep)
|
||||||
|
if realpath not in vhost_paths.keys():
|
||||||
|
vhs.append(new_vhost)
|
||||||
|
vhost_paths[realpath] = new_vhost.filep
|
||||||
|
elif realpath == new_vhost.filep:
|
||||||
|
# Prefer "real" vhost paths instead of symlinked ones
|
||||||
|
# ex: sites-enabled/vh.conf -> sites-available/vh.conf
|
||||||
|
|
||||||
for path in paths:
|
# remove old (most likely) symlinked one
|
||||||
vhs.append(self._create_vhost(path))
|
vhs = [v for v in vhs if v.filep != vhost_paths[realpath]]
|
||||||
|
vhs.append(new_vhost)
|
||||||
|
vhost_paths[realpath] = realpath
|
||||||
|
|
||||||
return vhs
|
return vhs
|
||||||
|
|
||||||
|
|||||||
@@ -128,20 +128,10 @@ class TwoVhost80Test(util.ApacheTest):
|
|||||||
self.assertEqual(found, 6)
|
self.assertEqual(found, 6)
|
||||||
|
|
||||||
# Handle case of non-debian layout get_virtual_hosts
|
# Handle case of non-debian layout get_virtual_hosts
|
||||||
orig_conf = self.config.conf
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"letsencrypt_apache.configurator.ApacheConfigurator.conf"
|
"letsencrypt_apache.configurator.ApacheConfigurator.conf"
|
||||||
) as mock_conf:
|
) as mock_conf:
|
||||||
def conf_sideeffect(key):
|
mock_conf.return_value = False
|
||||||
"""Handle calls to configurator.conf()
|
|
||||||
:param key: configuration key
|
|
||||||
:return: configuration value
|
|
||||||
"""
|
|
||||||
if key == "handle-sites":
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return orig_conf(key)
|
|
||||||
mock_conf.side_effect = conf_sideeffect
|
|
||||||
vhs = self.config.get_virtual_hosts()
|
vhs = self.config.get_virtual_hosts()
|
||||||
self.assertEqual(len(vhs), 6)
|
self.assertEqual(len(vhs), 6)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user