Skip to content

Commit

Permalink
feat: secret enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Jul 19, 2024
1 parent 2027053 commit ca78d85
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.runners.RunVariables;
import io.kestra.core.secret.SecretNotFoundException;
import io.kestra.core.secret.SecretService;
import io.pebbletemplates.pebble.error.PebbleException;
import io.pebbletemplates.pebble.extension.Function;
Expand All @@ -14,6 +15,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;

@Slf4j
Expand All @@ -32,7 +34,6 @@ public List<String> getArgumentNames() {
public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
String key = getSecretKey(args, self, lineNumber);
Map<String, String> flow = (Map<String, String>) context.getVariable("flow");

try {
String secret = secretService.findSecret(flow.get("tenantId"), flow.get("namespace"), key);

Expand All @@ -44,7 +45,7 @@ public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationC
}

return secret;
} catch (IllegalVariableEvaluationException | IOException e) {
} catch (SecretNotFoundException | IOException e) {
throw new PebbleException(e, e.getMessage(), lineNumber, self.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.kestra.core.secret;

import io.kestra.core.exceptions.KestraRuntimeException;

import java.io.Serial;

/**
* Exception when a secret is not found.
*/
public class SecretNotFoundException extends KestraRuntimeException {

@Serial
private static final long serialVersionUID = 1L;

public SecretNotFoundException(String message) {
super(message);
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/io/kestra/core/secret/SecretService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.kestra.core.secret;

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import jakarta.inject.Singleton;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -34,7 +33,7 @@ private void postConstruct() {
));
}

public String findSecret(String tenantId, String namespace, String key) throws IOException, IllegalVariableEvaluationException {
public String findSecret(String tenantId, String namespace, String key) throws SecretNotFoundException, IOException {
return decodedSecrets.get(key.toUpperCase());
}
}
1 change: 1 addition & 0 deletions platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dependencies {
api "org.xhtmlrenderer:flying-saucer-pdf:$flyingSaucerVersion"
api group: 'jakarta.mail', name: 'jakarta.mail-api', version: '2.1.3'
api group: 'org.eclipse.angus', name: 'jakarta.mail', version: '2.0.3'
api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '3.1.8'
// Json Diff
api group: 'com.github.java-json-tools', name: 'json-patch', version: '1.13'

Expand Down

0 comments on commit ca78d85

Please sign in to comment.