Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;

public class ConfigSecretManager implements SecretManager {
Expand All @@ -41,9 +42,21 @@ private Map<String, Object> buildMap(String secretName) {
if (name.startsWith(prefix)) {
configManager
.config(name, String.class)
.ifPresent(v -> map.put(name.substring(prefix.length()), v));
.ifPresent(v -> addToMap(map, name.substring(prefix.length()), v));
}
}
return map;
}

private void addToMap(Map<String, Object> map, String name, Object v) {
StringTokenizer tokenizer = new StringTokenizer(name, ".");
while (tokenizer.hasMoreTokens()) {
name = tokenizer.nextToken();
if (tokenizer.hasMoreTokens()) {
map = (Map<String, Object>) map.computeIfAbsent(name, k -> new HashMap<>());
} else {
map.put(name, v);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ static void init() throws IOException {
@ResourceLock(Resources.SYSTEM_PROPERTIES)
void testDefault() {
System.setProperty("superman.name", "ClarkKent");
System.setProperty("superman.enemy.name", "Lex Luthor");
System.setProperty("superman.enemy.isHuman", "true");
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
assertThat(
appl.workflowDefinition(workflow)
.instance(Map.of())
.start()
.join()
.asMap()
.orElseThrow()
.get("superSecret"))
.isEqualTo("ClarkKent");
Map<String, Object> map =
appl.workflowDefinition(workflow).instance(Map.of()).start().join().asMap().orElseThrow();
assertThat(map.get("superSecret")).isEqualTo("ClarkKent");
assertThat(map.get("theEnemy")).isEqualTo("Lex Luthor");
assertThat(map.get("humanEnemy")).isEqualTo("true");
} finally {
System.clearProperty("superman.name");
System.clearProperty("superman.enemy.name");
System.clearProperty("superman.enemy.isHuman");
}
}

Expand All @@ -78,16 +78,20 @@ void testMissing() {
@Test
void testCustom() {
try (WorkflowApplication appl =
WorkflowApplication.builder().withSecretManager(k -> Map.of("name", "ClarkKent")).build()) {
assertThat(
appl.workflowDefinition(workflow)
.instance(Map.of())
.start()
.join()
.asMap()
.orElseThrow()
.get("superSecret"))
.isEqualTo("ClarkKent");
WorkflowApplication.builder()
.withSecretManager(
k ->
Map.of(
"name",
"ClarkKent",
"enemy",
Map.of("name", "Lex Luthor", "isHuman", true)))
.build()) {
Map<String, Object> map =
appl.workflowDefinition(workflow).instance(Map.of()).start().join().asMap().orElseThrow();
assertThat(map.get("superSecret")).isEqualTo("ClarkKent");
assertThat(map.get("theEnemy")).isEqualTo("Lex Luthor");
assertThat(map.get("humanEnemy")).isEqualTo(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ use:
do:
- useExpression:
set:
superSecret: ${$secret.superman.name}
superSecret: ${$secret.superman.name}
theEnemy: ${$secret.superman.enemy.name}
humanEnemy: ${$secret.superman.enemy.isHuman}