From de9c9bf2ed06592bde83c358cf3eb3b781905609 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Tue, 7 Mar 2017 17:39:10 +0400 Subject: [PATCH] Take configs from global secret Change-Id: I9d22f5e81c676fdd7deff15533be15b3720776b7 --- service/files/entrypoint.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/service/files/entrypoint.py b/service/files/entrypoint.py index d20c938..e8462e8 100644 --- a/service/files/entrypoint.py +++ b/service/files/entrypoint.py @@ -18,7 +18,7 @@ logging.basicConfig(format=LOG_FORMAT, LOG = logging.getLogger(__name__) GLOBALS_PATH = '/etc/ccp/globals/globals.json' - +GLOBALS_SECRETS_PATH = '/etc/ccp/global-secrets/global-secrets.json' def retry(f): @functools.wraps(f) @@ -36,12 +36,25 @@ def retry(f): return wrap +def merge_configs(variables, new_config): + for k, v in new_config.items(): + if k not in variables: + variables[k] = v + continue + if isinstance(v, dict) and isinstance(variables[k], dict): + merge_configs(variables[k], v) + else: + variables[k] = v + + class Configuration(): - def __init__(self, config_file): - LOG.info("Getting global variables from %s", config_file) + def __init__(self): values = {} - with open(config_file) as f: + with open(GLOBALS_PATH) as f: global_conf = json.load(f) + with open(GLOBALS_SECRETS_PATH) as f: + secrets = json.load(f) + merge_configs(global_conf, secrets) for key in ['etcd', 'namespace', 'security', 'cluster_domain']: values[key] = global_conf[key] hostname = socket.gethostname() @@ -179,7 +192,7 @@ def _get_etcd_member_id(peers, name): if __name__ == "__main__": - config = Configuration(GLOBALS_PATH) + config = Configuration() etcd_members_api = config.members_api try: # The only reliable way to determine if etcd cluster exists is to query