Skip to content

Commit

Permalink
Erv2 outpouts don't need to have __ to get populated (#4882)
Browse files Browse the repository at this point in the history
  • Loading branch information
lechuk47 authored Feb 19, 2025
1 parent ea067a2 commit c421272
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 6 additions & 12 deletions reconcile/external_resources/secrets_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,13 @@ class OutputSecretsFormatter:
def __init__(self, secret_reader: SecretReaderBase) -> None:
self.secret_reader = secret_reader

def _key_must_be_populated(self, key: str) -> bool:
"Only keys containing '__' must be populated to Secrets"
return "__" in key

def _format_key(self, key: str) -> str:
if "__" not in key:
return key
k_split = key.split("__")
output_key = k_split[1]
if output_key.startswith("db"):
output_key = output_key.replace("db_", "db.")
return output_key
# The "__" separator is a legacy feature of terraform resources
# This should be removed once all modules don't have outputs with this format.
if "__" in key:
_, key = key.split("__", 1)

return key.replace("db_", "db.", 1) if key.startswith("db_") else key

def _format_value(self, value: str) -> str:
decoded_value = base64.b64decode(value).decode("utf-8")
Expand All @@ -130,7 +125,6 @@ def format(self, data: Mapping[str, str]) -> dict[str, str]:
return {
self._format_key(key): self._format_value(value)
for key, value in data.items()
if self._key_must_be_populated(key)
}


Expand Down
3 changes: 2 additions & 1 deletion reconcile/test/external_resources/test_outputs_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ def test_outputs(mocker: MockerFixture) -> None:
secret_data = {
"test-01__arn": base64.b64encode(b"an_arn").decode(),
"test-01__resource_name": base64.b64encode(b"a_resource_name").decode(),
"debug_output": "Zm9vCg==", # Should not land into the secret as it not contains "__"
"debug_output": "Zm9vCg==",
}

expected_data = {
"arn": "an_arn",
"resource_name": "a_resource_name",
"debug_output": "foo\n",
}

formatter = OutputSecretsFormatter(secret_reader=mocker.Mock())
Expand Down

0 comments on commit c421272

Please sign in to comment.