Skip to content

Commit

Permalink
Fix for multiple env vars in config parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
c04x authored and Raif Bajric committed Feb 5, 2024
1 parent 8ac5518 commit 8938a09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ public Object expand(Object value, boolean keepSecrets) {
String variable = (String) value;

Matcher m = substitutionPattern.matcher(variable);
if (!m.matches()) {
return variable;

if (m.matches()) {
return replaceMatchedVariables(keepSecrets, m, variable);
} else if (m.find()) {
return m.replaceAll(matchResult -> replaceMatchedVariables(false, m, variable).toString());
}

return variable;
}

private Object replaceMatchedVariables(boolean keepSecrets, Matcher m, String variable) {
String variableName = m.group("name");

if (secretStore != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ public void testSimpleExpansion() throws Exception {
Assert.assertEquals(val, expandedValue);
}

@Test
public void testPartialExpansion() throws Exception {
String key = "foo";
String val = "bar";
ConfigVariableExpander cve = getFakeCve(Collections.emptyMap(), Collections.singletonMap(key, val));

String expandedValue = (String) cve.expand("test_partial_${" + key + "}");
Assert.assertEquals("test_partial_"+val, expandedValue);
}

@Test
public void testTwoExpansions() throws Exception {
String key1 = "foo";
String key2 = "bar";
String val1 = "foo_val";
String val2 = "bar_val";
ConfigVariableExpander cve = getFakeCve(Collections.emptyMap(), Map.of(key1, val1, key2, val2));

String expandedValue = (String) cve.expand("${" + key1 + "}${" + key2 + "}");
Assert.assertEquals(val1+val2, expandedValue);
}

@Test
public void testExpansionWithDefaultValue() throws Exception {
String key = "foo";
Expand Down

0 comments on commit 8938a09

Please sign in to comment.