add support for multiple domains

This commit is contained in:
Joachim Lusiardi 2016-12-31 21:20:49 +01:00
parent 2daf41afdc
commit 9a82dea98d

View File

@ -21,7 +21,7 @@ def analyse_proxy_data(data):
"""Extracts the data for the proxy configuration (envrionment variable
'PROXY_DATA' and converts it to a dictionary."""
proxy_data = {}
for proxy_var in data['PROXY_DATA'].split(','):
for proxy_var in data.split(','):
t = proxy_var.split(":", 1)
proxy_data[t[0]] = t[1]
return proxy_data
@ -31,11 +31,18 @@ def analyse_env_vars(inspect_data):
"""Extracts the environment variables from the given result of an 'inspect
container' call."""
env_data = {}
counter = 0
if not 'Env' in inspect_data['Config'] or inspect_data['Config']['Env'] is None:
return env_data
for env_var in inspect_data['Config']['Env']:
t = env_var.split("=")
env_data[t[0]] = t[1]
key = t[0]
value = t[1]
if key == 'PROXY_DATA':
if key in env_data:
key = "{key}{postfix}".format(key=key, postfix=counter)
counter+=1
env_data[key] = value
return env_data
@ -45,11 +52,13 @@ def handle_container(docker_client, id):
written to the directory of temporary nginx files"""
inspect_data = docker_client.inspect_container(id)
env_vars = analyse_env_vars(inspect_data)
if 'PROXY_DATA' in env_vars:
proxy_data = analyse_proxy_data(env_vars)
names = get_if_available(proxy_data, 'server_names', '').split(';')
names = []
for key in env_vars:
value = env_vars[key]
proxy_data = analyse_proxy_data(value)
names += get_if_available(proxy_data, 'server_names', '').split(';')
logging.info('list of domains on: %s', str(names))
return names
return []
def get_resolving_domains_from_containers(docker_client):