Skip to content

Commit

Permalink
Update SmallRye Config to 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Mar 21, 2023
1 parent 8099f14 commit 5936e44
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 53 deletions.
16 changes: 13 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<microprofile-jwt.version>2.1</microprofile-jwt.version>
<microprofile-lra.version>2.0</microprofile-lra.version>
<microprofile-openapi.version>3.1</microprofile-openapi.version>
<smallrye-common.version>2.1.0</smallrye-common.version>
<smallrye-config.version>3.1.3</smallrye-config.version>
<smallrye-common.version>2.0.0</smallrye-common.version>
<smallrye-config.version>3.1.4-SNAPSHOT</smallrye-config.version>
<smallrye-health.version>4.0.1</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.3.0</smallrye-open-api.version>
Expand Down Expand Up @@ -3804,6 +3804,11 @@
<artifactId>smallrye-config-common</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-core</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-validator</artifactId>
Expand All @@ -3821,7 +3826,12 @@
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-core</artifactId>
<artifactId>smallrye-config-source-keystore</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-crypto</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> names = ServiceUtil.classNamesNamedIn(classLoader, SERVICES_PREFIX + serviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,11 +19,10 @@
public class ConfigExpanderTestCase {

private SmallRyeConfig buildConfig(Map<String, String> 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<String, String> maps(Map... maps) {
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<quarkus.version>999-SNAPSHOT</quarkus.version>
<maven-model-helper.version>21</maven-model-helper.version>
<commons-io.version>2.11.0</commons-io.version>
<smallrye-common.version>1.13.2</smallrye-common.version>
<smallrye-common.version>2.1.0</smallrye-common.version>
<jandex.version>3.0.5</jandex.version>
</properties>
<modules>
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/smallrye-config/.env
Original file line number Diff line number Diff line change
@@ -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
Binary file added integration-tests/smallrye-config/keystore
Binary file not shown.
50 changes: 25 additions & 25 deletions integration-tests/smallrye-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<!-- For https://github.com/quarkusio/quarkus/issues/17818 -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -37,10 +42,23 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing</artifactId>
</dependency>
<!-- Config -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-source-file-system</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-source-keystore</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config-crypto</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -62,23 +80,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- For https://github.com/quarkusio/quarkus/issues/17818 -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
Expand All @@ -96,7 +97,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml-deployment</artifactId>
<artifactId>quarkus-hibernate-orm-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -109,7 +110,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<artifactId>quarkus-jdbc-h2-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -122,7 +123,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -135,7 +136,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-opentracing-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -148,7 +149,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-deployment</artifactId>
<artifactId>quarkus-smallrye-opentracing-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -161,7 +162,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2-deployment</artifactId>
<artifactId>quarkus-config-yaml-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -172,7 +173,6 @@
</exclusion>
</exclusions>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.smallrye.config;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class SecretsIT extends SecretsTest {
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 5936e44

Please sign in to comment.