Commit 41d6bf1f authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code to create only one file to define all virtual hosts

parent 696e48f2
...@@ -64,7 +64,7 @@ class Recipe(BaseSlapRecipe): ...@@ -64,7 +64,7 @@ class Recipe(BaseSlapRecipe):
port=8080, name=frontend_domain_name, port=8080, name=frontend_domain_name,
key=key, certificate=certificate) key=key, certificate=certificate)
self.setConnectionDict(dict(site_url=site_url, )) self.setConnectionDict(dict(site_url=site_url))
return self.path_list return self.path_list
def installLogrotate(self): def installLogrotate(self):
...@@ -203,23 +203,22 @@ class Recipe(BaseSlapRecipe): ...@@ -203,23 +203,22 @@ class Recipe(BaseSlapRecipe):
apache_conf['pid_file'] + ' SIGUSR1') apache_conf['pid_file'] + ' SIGUSR1')
return apache_conf return apache_conf
def generateNewId(self): def generateRewriteRule(self, parameter_dict):
"""Temporary way to generate id""" return "RewriteRule ^/%(id)s($|/.*) %(url)s/VirtualHostBase/" % parameter_dict + \
import random "https/%(domain)s:%(port)s/VirtualHostRoot/_vh_%(id)s$1 [L,P]" % parameter_dict
return str(random.randint(2**9,9**9))
def installFrontendApache(self, ip, port, key, certificate, def installFrontendApache(self, ip, port, key, certificate,
name, access_control_string=None): name, access_control_string=None):
rewrite_rule_include_path = self.createDataDirectory('apachevhost') vhost_name = "apachevhost.conf"
slave_instance_list = self.parameter_dict.get("slave_instance_list", []) slave_instance_list = self.parameter_dict.get("slave_instance_list", [])
rewrite_rule_list = []
for slave_instance in slave_instance_list: for slave_instance in slave_instance_list:
id = self.generateNewId()
url = slave_instance.get("url") url = slave_instance.get("url")
rewrite_rule_content = self.substituteTemplate( id = str(slave_instance_list.index(slave_instance))
self.getTemplateFilename('apache.vhost.conf.in'), vhost_dict = dict(id=id, ip=ip, port=port,
dict(id=id, ip=ip, port=port, domain=name, url=url)) domain=name, url=url)
self._writeFile(os.path.join(rewrite_rule_include_path, id), rewrite_rule_list.append(self.generateRewriteRule(vhost_dict))
rewrite_rule_content) self.createConfigurationFile(vhost_name, "\n".join(rewrite_rule_list))
apache_conf = self._getApacheConfigurationDict(name, ip, port) apache_conf = self._getApacheConfigurationDict(name, ip, port)
apache_conf['ssl_snippet'] = self.substituteTemplate( apache_conf['ssl_snippet'] = self.substituteTemplate(
self.getTemplateFilename('apache.ssl-snippet.conf.in'), self.getTemplateFilename('apache.ssl-snippet.conf.in'),
...@@ -231,7 +230,7 @@ class Recipe(BaseSlapRecipe): ...@@ -231,7 +230,7 @@ class Recipe(BaseSlapRecipe):
apache_conf.update(**dict( apache_conf.update(**dict(
path_enable=path, path_enable=path,
rewrite_rule_include_path=rewrite_rule_include_path rewrite_rule_path=os.path.join(self.etc_directory, vhost_name),
)) ))
apache_conf_string = self.substituteTemplate( apache_conf_string = self.substituteTemplate(
......
...@@ -37,7 +37,7 @@ CustomLog "%(access_log)s" common ...@@ -37,7 +37,7 @@ CustomLog "%(access_log)s" common
# Magic of Zope related rewrite # Magic of Zope related rewrite
RewriteEngine On RewriteEngine On
Include %(rewrite_rule_include_path)s/*.conf Include %(rewrite_rule_path)s
# List of modules # List of modules
LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_host_module modules/mod_authz_host.so
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment