Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: secret enhancements #4341

Merged
merged 1 commit into from
Jul 19, 2024
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 @@ -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