forked from smallrye/smallrye-config
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support configurable SecretKeyHandlers
- Loading branch information
Showing
18 changed files
with
301 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
implementation/src/main/java/io/smallrye/config/SecretKeysHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.smallrye.config; | ||
|
||
import io.smallrye.common.annotation.Experimental; | ||
|
||
@Experimental("") | ||
public interface SecretKeysHandlerFactory { | ||
SecretKeysHandler getSecretKeysHandler(ConfigSourceContext context); | ||
|
||
String getName(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
implementation/src/test/java/io/smallrye/config/SecretKeysHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.smallrye.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class SecretKeysHandlerTest { | ||
@Test | ||
void notFound() { | ||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.addDefaultInterceptors() | ||
.withDefaultValue("my.secret", "${missing::secret}") | ||
.build(); | ||
|
||
assertThrows(NoSuchElementException.class, () -> config.getConfigValue("my.secret")); | ||
} | ||
|
||
@Test | ||
void handler() { | ||
SmallRyeConfig config = new SmallRyeConfigBuilder() | ||
.addDefaultInterceptors() | ||
.withSecretKeysHandlers(new SecretKeysHandler() { | ||
@Override | ||
public String decode(final String secret) { | ||
return "decoded"; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "handler"; | ||
} | ||
}) | ||
.withDefaultValue("my.secret", "${handler::secret}") | ||
.build(); | ||
|
||
assertEquals("decoded", config.getRawValue("my.secret")); | ||
} | ||
} |
40 changes: 37 additions & 3 deletions
40
utils/crypto/src/main/java/io/smallrye/config/crypto/AESGCMNoPaddingSecretKeysHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.