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(core): throw an error if the secret is not found #6495

Merged
merged 1 commit into from
Dec 17, 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
6 changes: 5 additions & 1 deletion core/src/main/java/io/kestra/core/secret/SecretService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void decode() {
}

public String findSecret(String tenantId, String namespace, String key) throws SecretNotFoundException, IOException {
return decodedSecrets.get(key.toUpperCase());
String secret = decodedSecrets.get(key.toUpperCase());
if (secret == null) {
throw new SecretNotFoundException("Cannot find secret for key '" + key + "'.");
}
return secret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

@KestraTest
public class SecretFunctionTest extends AbstractMemoryRunnerTest {
Expand Down Expand Up @@ -53,9 +54,9 @@ void getSecret() throws TimeoutException, QueueException {
}

@Test
void getUnknownSecret() throws IllegalVariableEvaluationException, IOException {
String secret = secretService.findSecret(null, null, "unknown_secret_key");
void getUnknownSecret() {
var exception = assertThrows(SecretNotFoundException.class, () -> secretService.findSecret(null, null, "unknown_secret_key"));

assertThat(secret, nullValue());
assertThat(exception.getMessage(), is("Cannot find secret for key 'unknown_secret_key'."));
}
}
Loading