From 9a82dea98d2b77ab429c9afb160dd8bd6ec9fb36 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sat, 31 Dec 2016 21:20:49 +0100 Subject: [PATCH] add support for multiple domains --- list_domains.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/list_domains.py b/list_domains.py index 2ef3c10..b35e8b2 100644 --- a/list_domains.py +++ b/list_domains.py @@ -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(';') - return names - return [] + 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 def get_resolving_domains_from_containers(docker_client):