Skip to content

Commit

Permalink
Process env vars referenced in target vars (#164)
Browse files Browse the repository at this point in the history
* Process env vars referenced in target vars

* add logging for parameter replacement
  • Loading branch information
psegedy authored Jan 10, 2022
1 parent 3a083ea commit a6fe845
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bonfire/qontract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import copy
import logging
import re
from urllib.parse import urlparse

from gql import gql
Expand Down Expand Up @@ -218,6 +219,21 @@ def _add_component_if_priority_higher(
)


def _process_env_parameters(parameters):
"""Process variable reference in place, e.g. KAFKA_URL='${KAFKA_HOST}:9092'"""
for key, val in parameters.items():
if isinstance(val, str):
found = re.findall(r"\$\{([^$]+)\}", val)
for var in found:
if var in parameters:
parameters[key] = parameters[key].replace("${" + var + "}", parameters[var])
log.debug(
"parameter %s found and replaced with %s",
var,
parameters[var],
)


def _add_component(apps, env, app_name, saas_file, resource_template, target, defined_multiple):
component_name = resource_template["name"]
env_name = env["name"]
Expand All @@ -244,6 +260,7 @@ def _add_component(apps, env, app_name, saas_file, resource_template, target, de
p.update(_to_dict(saas_file["parameters"]))
p.update(_to_dict(resource_template["parameters"]))
p.update(_to_dict(target["parameters"]))
_process_env_parameters(p)

component = {
"name": component_name,
Expand Down

0 comments on commit a6fe845

Please sign in to comment.