From ece7441f3178c0b36e2c80eb497dae1886ae26ca Mon Sep 17 00:00:00 2001 From: "Christian R. Garcia" Date: Wed, 25 Sep 2024 23:16:27 -0700 Subject: [PATCH] Fixed multi secret replacements --- service/api_pods_podid.py | 5 ++++- service/kubernetes_templates.py | 33 ++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/service/api_pods_podid.py b/service/api_pods_podid.py index b2a23d3..5243635 100644 --- a/service/api_pods_podid.py +++ b/service/api_pods_podid.py @@ -130,10 +130,13 @@ async def get_derived_pod(pod_id): pods_env = Password.db_get_with_pk(pod.pod_id, pod.tenant_id, pod.site_id) pods_env = pods_env.dict() for key, val in final_pod.environment_variables.items(): + new_val = val.copy() if isinstance(val, str): # regex to create list of [<> strings, str of inner variable without >><<] matches = re.findall(r'<>', val) for match in matches: - final_pod.environment_variables[key] = val.replace(f"<>", pods_env.get(match)) + val = val.replace(f"<>", pods_env.get(match)) + final_pod.environment_variables[key] = new_val + return ok(result=final_pod.display(), msg="Final derived pod retrieved successfully.") diff --git a/service/kubernetes_templates.py b/service/kubernetes_templates.py index b22ba0d..a2c1a54 100644 --- a/service/kubernetes_templates.py +++ b/service/kubernetes_templates.py @@ -117,25 +117,28 @@ def start_generic_pod(input_pod, revision: int): pods_env = pods_env.dict() if final_pod.environment_variables: for key, val in final_pod.environment_variables.items(): + new_val = val.copy() if isinstance(val, str): # regex to create list of [<> strings, str of inner variable without >><<] matches = re.findall(r'<>', val) for match in matches: - final_pod.environment_variables[key] = val.replace(f"<>", pods_env.get(match)) - #command - if final_pod.command: - for key in final_pod.command: - if isinstance(key, str): - matches = re.findall(r'<>', key) - for match in matches: - final_pod.command[key] = key.replace(f"<>", pods_env.get(match)) - #arguments - if final_pod.arguments: - for key in final_pod.arguments: - if isinstance(key, str): - matches = re.findall(r'<>', key) - for match in matches: - final_pod.arguments[key] = key.replace(f"<>", pods_env.get(match)) + val = val.replace(f"<>", pods_env.get(match)) + final_pod.environment_variables[key] = new_val + + # #command + # if final_pod.command: + # for key in final_pod.command: + # if isinstance(key, str): + # matches = re.findall(r'<>', key) + # for match in matches: + # final_pod.command[key] = key.replace(f"<>", pods_env.get(match)) + # #arguments + # if final_pod.arguments: + # for key in final_pod.arguments: + # if isinstance(key, str): + # matches = re.findall(r'<>', key) + # for match in matches: + # final_pod.arguments[key] = key.replace(f"<>", pods_env.get(match)) volumes = [] volume_mounts = []