Skip to content

Commit

Permalink
feat(core): throw an error if the secret is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Dec 17, 2024
1 parent b133210 commit da1bbb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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'."));
}
}

0 comments on commit da1bbb5

Please sign in to comment.