Commit d16efd15 authored by Nicolas Wavrant's avatar Nicolas Wavrant

monitor_config_write: CORS apache conf should be rendered from a slapos...

monitor_config_write: CORS apache conf should be rendered from a slapos template instead of being hardcoded
parent bf04a66f
Pipeline #4034 skipped
......@@ -3,6 +3,7 @@
import sys
import os
import re
import jinja2
import json
import argparse
import subprocess
......@@ -21,15 +22,18 @@ def parseArguments():
help='Path apache htpasswd binary. Needed to write htpasswd file.')
help='Ouput parameters in cfg file.')
help='Path to the CORS httpd template.')
return parser.parse_args()
class MonitorConfigWrite(object):
def __init__(self, config_json_file, htpasswd_bin, output_cfg_file=""):
def __init__(self, config_json_file, htpasswd_bin, output_cfg_file="", monitor_https_cors=""):
self.config_json_file = config_json_file
self.output_cfg_file = output_cfg_file
self.htpasswd_bin = htpasswd_bin
self.monitor_https_cors = monitor_https_cors
def _fileWrite(self, file_path, content):
if os.path.exists(file_path):
......@@ -76,14 +80,12 @@ class MonitorConfigWrite(object):
return True
except OSError, e:
print "Failed to open file at %s. \n%s" % (old_httpd_cors_file, str(e))
for domain in cors_domain_list:
if cors_string:
cors_string += '|'
cors_string += re.escape(domain)
with open(self.monitor_https_cors, 'r') as cors_template:
template = jinja2.Template(
rendered_string = template.render(domain=cors_domain)
with open(httpd_cors_file, 'w') as file:
file.write('SetEnvIf Origin "^http(s)?://(.+\.)?(%s)$" origin_is=$0\n' % cors_string)
file.write('Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is')
except OSError, e:
print "ERROR while writing CORS changes to %s.\n %s" % (httpd_cors_file, str(e))
return False
......@@ -176,7 +178,8 @@ def main():
instance = MonitorConfigWrite(
while True:
result_dict = instance.applyConfigChanges()
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