From 5936e445c6a104ebad277d30260bc11eb358fa67 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 13 Mar 2023 21:05:24 +0000 Subject: [PATCH] Update SmallRye Config to 3.2.0 --- bom/application/pom.xml | 16 ++++-- .../quarkus/deployment/QuarkusAugmentor.java | 6 +-- .../deployment/steps/ConfigBuildSteps.java | 4 ++ .../runtime/configuration/ConfigUtils.java | 21 ++++---- .../configuration/QuarkusConfigFactory.java | 2 +- .../configuration/ConfigExpanderTestCase.java | 10 ++-- independent-projects/tools/pom.xml | 2 +- integration-tests/smallrye-config/.env | 6 +-- integration-tests/smallrye-config/keystore | Bin 0 -> 443 bytes integration-tests/smallrye-config/pom.xml | 50 +++++++++--------- .../src/main/resources/application.properties | 6 +++ .../quarkus/it/smallrye/config/SecretsIT.java | 7 +++ .../it/smallrye/config/SecretsTest.java | 21 ++++++++ .../extest/UnknownBuildConfigTest.java | 2 +- 14 files changed, 100 insertions(+), 53 deletions(-) create mode 100644 integration-tests/smallrye-config/keystore create mode 100644 integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsIT.java create mode 100644 integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsTest.java diff --git a/bom/application/pom.xml b/bom/application/pom.xml index fccb16fc3e572..044e9f8114a88 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -54,8 +54,8 @@ 2.1 2.0 3.1 - 2.1.0 - 3.1.3 + 2.0.0 + 3.1.4-SNAPSHOT 4.0.1 4.0.0 3.3.0 @@ -3804,6 +3804,11 @@ smallrye-config-common ${smallrye-config.version} + + io.smallrye.config + smallrye-config-core + ${smallrye-config.version} + io.smallrye.config smallrye-config-validator @@ -3821,7 +3826,12 @@ io.smallrye.config - smallrye-config-core + smallrye-config-source-keystore + ${smallrye-config.version} + + + io.smallrye.config + smallrye-config-crypto ${smallrye-config.version} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java index dba8f2b5eeb88..c5380c77d5664 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java @@ -13,7 +13,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.jboss.logging.Logger; import io.quarkus.bootstrap.classloading.QuarkusClassLoader; @@ -38,6 +37,7 @@ import io.quarkus.paths.PathCollection; import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.util.JavaVersionUtil; +import io.smallrye.config.SmallRyeConfigProviderResolver; public class QuarkusAugmentor { @@ -177,8 +177,8 @@ public BuildResult run() throws Exception { return buildResult; } finally { try { - ConfigProviderResolver.instance() - .releaseConfig(ConfigProviderResolver.instance().getConfig(deploymentClassLoader)); + ((SmallRyeConfigProviderResolver) SmallRyeConfigProviderResolver.instance()) + .releaseConfig(deploymentClassLoader); } catch (Exception ignore) { } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigBuildSteps.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigBuildSteps.java index 51eab2942912f..a3bdf3071a2c9 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigBuildSteps.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigBuildSteps.java @@ -34,6 +34,8 @@ import io.smallrye.config.ConfigSourceInterceptor; import io.smallrye.config.ConfigSourceInterceptorFactory; import io.smallrye.config.ConfigValidator; +import io.smallrye.config.SecretKeysHandler; +import io.smallrye.config.SecretKeysHandlerFactory; import io.smallrye.config.SmallRyeConfigProviderResolver; class ConfigBuildSteps { @@ -90,6 +92,8 @@ void nativeServiceProviders( Converter.class, ConfigSourceInterceptor.class, ConfigSourceInterceptorFactory.class, + SecretKeysHandler.class, + SecretKeysHandlerFactory.class, ConfigValidator.class)) { final String serviceName = serviceClass.getName(); final Set names = ServiceUtil.classNamesNamedIn(classLoader, SERVICES_PREFIX + serviceName); diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java index 5c04a6a4f4199..e9fe18f97ed53 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java @@ -90,14 +90,8 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b final boolean addDiscovered, final LaunchMode launchMode) { SmallRyeConfigBuilder builder = emptyConfigBuilder(); - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - builder.forClassLoader(classLoader); - builder.addDefaultSources(); - builder.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem()); - builder.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath()); - builder.withSources(new DotEnvConfigSourceProvider()); if (launchMode.isDevOrTest() && (runTime || bootstrap)) { - builder.withSources(new RuntimeOverrideConfigSource(classLoader)); + builder.withSources(new RuntimeOverrideConfigSource(Thread.currentThread().getContextClassLoader())); } if (runTime || bootstrap) { // Validator only for runtime. We cannot use the current validator for build time (chicken / egg problem) @@ -184,9 +178,16 @@ public OptionalInt getPriority() { // Ignore unmapped quarkus properties, because properties in the same root may be split between build / runtime builder.withMappingIgnore("quarkus.**"); - builder.addDefaultInterceptors(); - builder.addDiscoveredInterceptors(); - builder.addDiscoveredConverters(); + builder.forClassLoader(Thread.currentThread().getContextClassLoader()) + .addDiscoveredConverters() + .addDefaultInterceptors() + .addDiscoveredInterceptors() + .addDiscoveredSecretKeysHandlers() + .addDefaultSources() + .withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem()) + .withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath()) + .withSources(new DotEnvConfigSourceProvider()); + return builder; } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java index eafd80022e91b..9f168ae907e6f 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java @@ -26,7 +26,7 @@ public SmallRyeConfig getConfigFor(final SmallRyeConfigProviderResolver configPr //TODO: this code path is only hit when start fails in dev mode very early in the process //the recovery code will fail without this as it cannot read any properties such as //the HTTP port or logging info - return ConfigUtils.emptyConfigBuilder().addDefaultSources().addDiscoveredSources().build(); + return ConfigUtils.emptyConfigBuilder().addDiscoveredSources().build(); } return config; } diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java index 3c62be1e69f18..897d54d1c4cf3 100644 --- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java +++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigExpanderTestCase.java @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test; -import io.smallrye.config.ExpressionConfigSourceInterceptor; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfigBuilder; @@ -20,11 +19,10 @@ public class ConfigExpanderTestCase { private SmallRyeConfig buildConfig(Map configMap) { - final SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder(); - builder.withInterceptors(new ExpressionConfigSourceInterceptor()); - builder.withSources(new PropertiesConfigSource(configMap, "test input", 500)); - final SmallRyeConfig config = (SmallRyeConfig) builder.build(); - return config; + return new SmallRyeConfigBuilder() + .addDefaultInterceptors() + .withSources(new PropertiesConfigSource(configMap, "test input", 500)) + .build(); } private Map maps(Map... maps) { diff --git a/independent-projects/tools/pom.xml b/independent-projects/tools/pom.xml index c4846aeaec8cf..7560284cdbeac 100644 --- a/independent-projects/tools/pom.xml +++ b/independent-projects/tools/pom.xml @@ -66,7 +66,7 @@ 999-SNAPSHOT 21 2.11.0 - 1.13.2 + 2.1.0 3.0.5 diff --git a/integration-tests/smallrye-config/.env b/integration-tests/smallrye-config/.env index 5d20f3e113b6f..decac569ed32d 100644 --- a/integration-tests/smallrye-config/.env +++ b/integration-tests/smallrye-config/.env @@ -1,6 +1,6 @@ DOTENV_SERVER_NAME=localhost DOTENV_SERVER_PORT=8080 -_TEST_QUARKUS_DATASOURCE_DB_KIND=h2 -_TEST_QUARKUS_DATASOURCE_JDBC_URL=jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1 -_TEST_QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=drop-and-create +QUARKUS_DATASOURCE_DB_KIND=h2 +QUARKUS_DATASOURCE_JDBC_URL=jdbc:h2:mem:test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1 +QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION=drop-and-create diff --git a/integration-tests/smallrye-config/keystore b/integration-tests/smallrye-config/keystore new file mode 100644 index 0000000000000000000000000000000000000000..74db4bb9a9dc92c8494f7afa43e7a81ecf03f9fd GIT binary patch literal 443 zcmXqLV%*Ne$ZXKWn8?Pd)#lOmotKfFaX}Mf5K9xIA5ho}h}}@7%z;wIKw*6#)@I{| z>f+&IWL?mB*`VDtfVVqIlK;_kHGmuh=w~Xil0F&+$Ct?Mg=$k%!Ff?-V(h*8EXc R^i;YSxQOS>n^I7~000*PkVpUk literal 0 HcmV?d00001 diff --git a/integration-tests/smallrye-config/pom.xml b/integration-tests/smallrye-config/pom.xml index ece98c2440a4c..190438f577f7f 100644 --- a/integration-tests/smallrye-config/pom.xml +++ b/integration-tests/smallrye-config/pom.xml @@ -19,9 +19,14 @@ io.quarkus quarkus-hibernate-validator + io.quarkus - quarkus-config-yaml + quarkus-hibernate-orm + + + io.quarkus + quarkus-jdbc-h2 io.quarkus @@ -37,10 +42,23 @@ io.quarkus quarkus-smallrye-opentracing + + + io.quarkus + quarkus-config-yaml + io.smallrye.config smallrye-config-source-file-system + + io.smallrye.config + smallrye-config-source-keystore + + + io.smallrye.config + smallrye-config-crypto + io.quarkus @@ -62,23 +80,6 @@ rest-assured test - - - io.quarkus - quarkus-hibernate-orm - test - - - net.bytebuddy - byte-buddy - - - - - io.quarkus - quarkus-jdbc-h2 - test - @@ -96,7 +97,7 @@ io.quarkus - quarkus-config-yaml-deployment + quarkus-hibernate-orm-deployment ${project.version} pom test @@ -109,7 +110,7 @@ io.quarkus - quarkus-resteasy-reactive-deployment + quarkus-jdbc-h2-deployment ${project.version} pom test @@ -122,7 +123,7 @@ io.quarkus - quarkus-resteasy-reactive-jackson-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test @@ -135,7 +136,7 @@ io.quarkus - quarkus-smallrye-opentracing-deployment + quarkus-resteasy-reactive-jackson-deployment ${project.version} pom test @@ -148,7 +149,7 @@ io.quarkus - quarkus-hibernate-orm-deployment + quarkus-smallrye-opentracing-deployment ${project.version} pom test @@ -161,7 +162,7 @@ io.quarkus - quarkus-jdbc-h2-deployment + quarkus-config-yaml-deployment ${project.version} pom test @@ -172,7 +173,6 @@ - diff --git a/integration-tests/smallrye-config/src/main/resources/application.properties b/integration-tests/smallrye-config/src/main/resources/application.properties index d44dc7bbd9af3..960766adbc554 100644 --- a/integration-tests/smallrye-config/src/main/resources/application.properties +++ b/integration-tests/smallrye-config/src/main/resources/application.properties @@ -22,3 +22,9 @@ smallrye.config.source.file.locations=src/main/smallrye-config-source-file-syste no.profile=any profile.main.properties=main + +#secrets +smallrye.config.secret-handler.aes-gcm-nopadding.encryption-key=somearbitrarycrazystringthatdoesnotmatter +smallrye.config.source.keystore.test.path=keystore +smallrye.config.source.keystore.test.password=secret +smallrye.config.source.keystore.test.handler=aes-gcm-nopadding diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsIT.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsIT.java new file mode 100644 index 0000000000000..4ee4c0fc3b5f3 --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.smallrye.config; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class SecretsIT extends SecretsTest { +} diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsTest.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsTest.java new file mode 100644 index 0000000000000..3128db8329916 --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/SecretsTest.java @@ -0,0 +1,21 @@ +package io.quarkus.it.smallrye.config; + +import static io.restassured.RestAssured.given; +import static jakarta.ws.rs.core.Response.Status.OK; +import static org.hamcrest.Matchers.equalTo; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class SecretsTest { + @Test + void secrets() { + given() + .get("/config/{name}", "my.secret") + .then() + .statusCode(OK.getStatusCode()) + .body("value", equalTo("decoded")); + } +} diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/UnknownBuildConfigTest.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/UnknownBuildConfigTest.java index 2bb9c6a755c60..4b9ad31019f5f 100644 --- a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/UnknownBuildConfigTest.java +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/extest/UnknownBuildConfigTest.java @@ -39,7 +39,7 @@ void unknownBuildConfig() { .orElse(new Object[0])) .collect(toSet()); - assertEquals(7, logRecords.size()); + assertEquals(7, unrecognized.size()); assertTrue(unrecognized.contains("quarkus.unknown.prop")); assertTrue(unrecognized.contains("quarkus.build.unknown.prop")); assertTrue(unrecognized.contains("quarkus.rename-old.prop"));