Skip to content

Commit

Permalink
Fixed multi secret replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
NotChristianGarcia committed Sep 26, 2024
1 parent 4a9c3ea commit ece7441
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 4 additions & 1 deletion service/api_pods_podid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<<TAPIS_*>> strings, str of inner variable without >><<]
matches = re.findall(r'<<TAPIS_(.*?)>>', val)
for match in matches:
final_pod.environment_variables[key] = val.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
val = val.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
final_pod.environment_variables[key] = new_val


return ok(result=final_pod.display(), msg="Final derived pod retrieved successfully.")
33 changes: 18 additions & 15 deletions service/kubernetes_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<<TAPIS_*>> strings, str of inner variable without >><<]
matches = re.findall(r'<<TAPIS_(.*?)>>', val)
for match in matches:
final_pod.environment_variables[key] = val.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
#command
if final_pod.command:
for key in final_pod.command:
if isinstance(key, str):
matches = re.findall(r'<<TAPIS_(.*?)>>', key)
for match in matches:
final_pod.command[key] = key.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
#arguments
if final_pod.arguments:
for key in final_pod.arguments:
if isinstance(key, str):
matches = re.findall(r'<<TAPIS_(.*?)>>', key)
for match in matches:
final_pod.arguments[key] = key.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
val = val.replace(f"<<TAPIS_{match}>>", 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'<<TAPIS_(.*?)>>', key)
# for match in matches:
# final_pod.command[key] = key.replace(f"<<TAPIS_{match}>>", pods_env.get(match))
# #arguments
# if final_pod.arguments:
# for key in final_pod.arguments:
# if isinstance(key, str):
# matches = re.findall(r'<<TAPIS_(.*?)>>', key)
# for match in matches:
# final_pod.arguments[key] = key.replace(f"<<TAPIS_{match}>>", pods_env.get(match))

volumes = []
volume_mounts = []
Expand Down

0 comments on commit ece7441

Please sign in to comment.