From 1332096f73f9b1fb6ea8c1de692c2b9747fc0295 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 20 Mar 2023 23:48:21 +0000 Subject: [PATCH] Consistent configuration names --- .../src/main/docs/config-sources/keystore.md | 14 +++---- sources/keystore/pom.xml | 18 +++++++++ .../source/keystore/KeyStoreConfig.java | 2 +- .../keystore/KeyStoreConfigSourceTest.java | 12 +++--- testsuite/extra/pom.xml | 10 +++++ .../secrets/MultipleSecretHandlersTest.java | 32 +++++++++++++++ .../AESGCMNoPaddingSecretKeysHandlerTest.java | 39 +++++++++++++++++-- utils/jasypt/pom.xml | 6 ++- 8 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 testsuite/extra/src/test/java/io/smallrye/config/test/secrets/MultipleSecretHandlersTest.java diff --git a/documentation/src/main/docs/config-sources/keystore.md b/documentation/src/main/docs/config-sources/keystore.md index 14463137e..5fb6a7140 100644 --- a/documentation/src/main/docs/config-sources/keystore.md +++ b/documentation/src/main/docs/config-sources/keystore.md @@ -16,10 +16,10 @@ The following dependency is required in the classpath to use the KeyStore Config | Configuration Property | Type | Default | |---------------------------------------------------------------------------------------------------------------------|--- |----| -| `io.smallrye.config.source.keystore."name".path`
The KeyStore path. | String | | -| `io.smallrye.config.source.keystore."name".password`
The KeyStore password. | String | | -| `io.smallrye.config.source.keystore."name".type`
The KeyStore type. | String | `PKCS12` | -| `io.smallrye.config.source.keystore."name".handler`
An Optional secret keys handler. | String | | -| `io.smallrye.config.source.keystore."name".aliases."key".name`
An Optional aliases key name. | String | | -| `io.smallrye.config.source.keystore."name".aliases."key".password`
An Optional aliases key password. | String | | -| `io.smallrye.config.source.keystore."name".aliases."key".handler`
An Optional aliases key secret keys handler. | String | | +| `smallrye.config.source.keystore."name".path`
The KeyStore path. | String | | +| `smallrye.config.source.keystore."name".password`
The KeyStore password. | String | | +| `smallrye.config.source.keystore."name".type`
The KeyStore type. | String | `PKCS12` | +| `smallrye.config.source.keystore."name".handler`
An Optional secret keys handler. | String | | +| `smallrye.config.source.keystore."name".aliases."key".name`
An Optional aliases key name. | String | | +| `smallrye.config.source.keystore."name".aliases."key".password`
An Optional aliases key password. | String | | +| `smallrye.config.source.keystore."name".aliases."key".handler`
An Optional aliases key secret keys handler. | String | | diff --git a/sources/keystore/pom.xml b/sources/keystore/pom.xml index 66a69504a..058851292 100644 --- a/sources/keystore/pom.xml +++ b/sources/keystore/pom.xml @@ -34,4 +34,22 @@ + + + + io.smallrye + jandex-maven-plugin + ${version.org.jboss.jandex} + + + make-index + + jandex + + + + + + + diff --git a/sources/keystore/src/main/java/io/smallrye/config/source/keystore/KeyStoreConfig.java b/sources/keystore/src/main/java/io/smallrye/config/source/keystore/KeyStoreConfig.java index 6ac03d66d..248d26009 100644 --- a/sources/keystore/src/main/java/io/smallrye/config/source/keystore/KeyStoreConfig.java +++ b/sources/keystore/src/main/java/io/smallrye/config/source/keystore/KeyStoreConfig.java @@ -7,7 +7,7 @@ import io.smallrye.config.WithDefault; import io.smallrye.config.WithParentName; -@ConfigMapping(prefix = "io.smallrye.config.source.keystore") +@ConfigMapping(prefix = "smallrye.config.source.keystore") public interface KeyStoreConfig { @WithParentName Map keystores(); diff --git a/sources/keystore/src/test/java/io/smallrye/config/source/keystore/KeyStoreConfigSourceTest.java b/sources/keystore/src/test/java/io/smallrye/config/source/keystore/KeyStoreConfigSourceTest.java index 2dd74c6ac..8af2fd79f 100644 --- a/sources/keystore/src/test/java/io/smallrye/config/source/keystore/KeyStoreConfigSourceTest.java +++ b/sources/keystore/src/test/java/io/smallrye/config/source/keystore/KeyStoreConfigSourceTest.java @@ -18,8 +18,8 @@ class KeyStoreConfigSourceTest { void keystore() { // keytool -importpass -alias my.secret -keystore keystore -storepass secret -storetype PKCS12 -v Map properties = Map.of( - "io.smallrye.config.source.keystore.test.path", "keystore", - "io.smallrye.config.source.keystore.test.password", "secret"); + "smallrye.config.source.keystore.test.path", "keystore", + "smallrye.config.source.keystore.test.password", "secret"); SmallRyeConfig config = new SmallRyeConfigBuilder() .withProfile("prod") @@ -39,8 +39,8 @@ void keyStoreNotFound() { .addDefaultInterceptors() .addDiscoveredSources() .withSources(new PropertiesConfigSource(Map.of( - "io.smallrye.config.source.keystore.test.path", "not.found", - "io.smallrye.config.source.keystore.test.password", "secret"), "", 0)) + "smallrye.config.source.keystore.test.path", "not.found", + "smallrye.config.source.keystore.test.password", "secret"), "", 0)) .build(); ConfigValue secret = config.getConfigValue("my.secret"); @@ -49,8 +49,8 @@ void keyStoreNotFound() { assertThrows(IllegalArgumentException.class, () -> new SmallRyeConfigBuilder() .addDiscoveredSources() .withSources(new PropertiesConfigSource(Map.of( - "io.smallrye.config.source.keystore.test.path", "file:/not.found", - "io.smallrye.config.source.keystore.test.password", "secret"), "", 0)) + "smallrye.config.source.keystore.test.path", "file:/not.found", + "smallrye.config.source.keystore.test.password", "secret"), "", 0)) .build()); } } diff --git a/testsuite/extra/pom.xml b/testsuite/extra/pom.xml index f0aeca197..e17c67dee 100644 --- a/testsuite/extra/pom.xml +++ b/testsuite/extra/pom.xml @@ -53,6 +53,16 @@ smallrye-config-source-yaml ${project.version} + + io.smallrye.config + smallrye-config-crypto + ${project.version} + + + io.smallrye.config + smallrye-config-jasypt + ${project.version} + diff --git a/testsuite/extra/src/test/java/io/smallrye/config/test/secrets/MultipleSecretHandlersTest.java b/testsuite/extra/src/test/java/io/smallrye/config/test/secrets/MultipleSecretHandlersTest.java new file mode 100644 index 000000000..60ada1a03 --- /dev/null +++ b/testsuite/extra/src/test/java/io/smallrye/config/test/secrets/MultipleSecretHandlersTest.java @@ -0,0 +1,32 @@ +package io.smallrye.config.test.secrets; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import io.smallrye.config.PropertiesConfigSource; +import io.smallrye.config.SmallRyeConfig; +import io.smallrye.config.SmallRyeConfigBuilder; + +class MultipleSecretHandlersTest { + @Test + void multipleHandlers() { + Map properties = Map.of( + "smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key", "somearbitrarycrazystringthatdoesnotmatter", + "aes-gcm-nopadding.secret", "${aes-gcm-nopadding::DJNrZ6LfpupFv6QbXyXhvzD8eVDnDa_kTliQBpuzTobDZxlg}", + "smallrye.config.secret-handler.jasypt.password", "jasypt", + "smallrye.config.secret-handler.jasypt.algorithm", "PBEWithHMACSHA512AndAES_256", + "jasypt.secret", "${jasypt::ENC(wqp8zDeiCQ5JaFvwDtoAcr2WMLdlD0rjwvo8Rh0thG5qyTQVGxwJjBIiW26y0dtU)}"); + + SmallRyeConfig config = new SmallRyeConfigBuilder() + .addDefaultInterceptors() + .addDiscoveredSecretKeysHandlers() + .withSources(new PropertiesConfigSource(properties, "", 0)) + .build(); + + assertEquals("decoded", config.getRawValue("aes-gcm-nopadding.secret")); + assertEquals("12345678", config.getRawValue("jasypt.secret")); + } +} diff --git a/utils/crypto/src/test/java/io/smallrye/config/crypto/AESGCMNoPaddingSecretKeysHandlerTest.java b/utils/crypto/src/test/java/io/smallrye/config/crypto/AESGCMNoPaddingSecretKeysHandlerTest.java index 87ead4f5e..b91b87c11 100644 --- a/utils/crypto/src/test/java/io/smallrye/config/crypto/AESGCMNoPaddingSecretKeysHandlerTest.java +++ b/utils/crypto/src/test/java/io/smallrye/config/crypto/AESGCMNoPaddingSecretKeysHandlerTest.java @@ -4,11 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import org.eclipse.microprofile.config.spi.ConfigSource; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import io.smallrye.config.ConfigSourceContext; +import io.smallrye.config.ConfigSourceFactory; import io.smallrye.config.ConfigValue; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SmallRyeConfig; @@ -38,9 +43,9 @@ void handler() { void keystore() { Map properties = Map.of( "smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key", "somearbitrarycrazystringthatdoesnotmatter", - "io.smallrye.config.source.keystore.test.path", "keystore", - "io.smallrye.config.source.keystore.test.password", "secret", - "io.smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding"); + "smallrye.config.source.keystore.test.path", "keystore", + "smallrye.config.source.keystore.test.password", "secret", + "smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding"); SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() @@ -68,4 +73,32 @@ void noEncriptionKey() { .build(); assertTrue(true); } + + @Test + @Disabled + void configurableSource() { + Map properties = Map.of( + "smallrye.config.source.keystore.test.path", "keystore", + "smallrye.config.source.keystore.test.password", "secret", + "smallrye.config.source.keystore.test.handler", "aes-gcm-nopadding"); + + SmallRyeConfig config = new SmallRyeConfigBuilder() + .addDefaultInterceptors() + .addDiscoveredSources() + .addDiscoveredSecretKeysHandlers() + .withSources(new PropertiesConfigSource(properties, "", 0)) + .withSources(new ConfigSourceFactory() { + @Override + public Iterable getConfigSources(final ConfigSourceContext context) { + return List.of(new PropertiesConfigSource( + Map.of("smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key", + "somearbitrarycrazystringthatdoesnotmatter"), + "", 0)); + } + }) + .build(); + + ConfigValue secret = config.getConfigValue("my.secret"); + assertEquals("decoded", secret.getValue()); + } } diff --git a/utils/jasypt/pom.xml b/utils/jasypt/pom.xml index 4823bff13..5da623277 100644 --- a/utils/jasypt/pom.xml +++ b/utils/jasypt/pom.xml @@ -12,6 +12,10 @@ SmallRye Config: Jasypt + + 1.9.3 + + io.smallrye.config @@ -20,7 +24,7 @@ org.jasypt jasypt - 1.9.3 + ${version.jasypt}