Skip to content

Commit

Permalink
Filter SWADL files and change prefix to WDK_SECRET_
Browse files Browse the repository at this point in the history
  • Loading branch information
Yong Sheng Tan committed Jul 25, 2023
1 parent 21748a7 commit fe7e943
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ This allows secrets to be used in production when API-based deployments are not
monitoring-token: mysecretpassphrase
management-token: mysecretpassphrase
````
3. Add secrets via environment variables prefixed with `WDK_` in the runtime location
- e.g. adding a `WDK_secretToken` environment variable with a `abc` value will create a WDK secret at startup named `secretToken` with a value of `abc`
3. Add secrets via environment variables prefixed with `WDK_SECRET_` in the runtime location
- e.g. adding a `WDK_SECRET_secretToken` environment variable with a `abc` value will create a WDK secret at startup named `secretToken` with a value of `abc`
8 changes: 6 additions & 2 deletions src/main/java/com/symphony/wdk/WdkLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public void init() throws IOException {
// Deploy workflows
log.info("Loading workflows from: {}", path);
for (String file : listFiles(path)) {
if (!file.toLowerCase().endsWith(".swadl.yaml")) {
continue;
}
log.info("Loading: {}", file);
Path swadlPath = Path.of(path + "/" + file);
String swadl = String.join("\n", Files.readAllLines(swadlPath));
Expand All @@ -42,11 +45,12 @@ public void init() throws IOException {
}

// Deploy secrets
String prefix = "WDK_SECRET_";
System.getenv().entrySet().stream()
.filter(e -> e.getKey().startsWith("WDK_"))
.filter(e -> e.getKey().startsWith(prefix))
.forEach(e -> {
log.info("Loading secret: {}", e.getKey());
String key = e.getKey().substring(4);
String key = e.getKey().substring(prefix.length());
byte[] secret = e.getValue().getBytes(StandardCharsets.UTF_8);
secretKeeper.save(key, secret);
});
Expand Down

0 comments on commit fe7e943

Please sign in to comment.