Skip to content

Commit

Permalink
Update SmallRye Config to 2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Sep 2, 2022
1 parent 09b5d07 commit 44dca6f
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<microprofile-jwt.version>1.2</microprofile-jwt.version>
<microprofile-lra.version>1.0</microprofile-lra.version>
<smallrye-common.version>1.13.1</smallrye-common.version>
<smallrye-config.version>2.11.1</smallrye-config.version>
<smallrye-config.version>2.12.0</smallrye-config.version>
<smallrye-health.version>3.2.1</smallrye-health.version>
<smallrye-metrics.version>3.0.5</smallrye-metrics.version>
<smallrye-open-api.version>2.2.0</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ ReadResult run() {
// we always have to set the map entry ourselves
Field field = matched.findField();
Converter<?> converter = getConverter(config, field, ConverterType.of(field));
map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter));
map.put(key, config.convertValue(configValue, converter));
allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
continue;
}
Expand Down Expand Up @@ -437,7 +437,7 @@ ReadResult run() {
// we always have to set the map entry ourselves
Field field = matched.findField();
Converter<?> converter = getConverter(config, field, ConverterType.of(field));
map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter));
map.put(key, config.convertValue(configValue, converter));
// cache the resolved value
allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
buildTimeRunTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.quarkus.arc.runtime;

import static io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromInjectionPoint;

import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Optional;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.InjectionPoint;

import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.inject.ConfigProperties;

import io.quarkus.arc.BeanCreator;
import io.quarkus.arc.impl.InjectionPointProvider;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.SmallRyeConfig;

public class ConfigMappingCreator implements BeanCreator<Object> {
Expand All @@ -27,4 +30,34 @@ public Object create(CreationalContext<Object> creationalContext, Map<String, Ob
SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
return config.getConfigMapping(interfaceType, getPrefixFromInjectionPoint(injectionPoint).orElse(prefix));
}

private static Optional<String> getPrefixFromInjectionPoint(final InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
if (annotated != null) {
ConfigMapping configMapping = annotated.getAnnotation(ConfigMapping.class);
if (configMapping != null) {
if (!configMapping.prefix().isEmpty()) {
return Optional.of(configMapping.prefix());
}
}

ConfigProperties configProperties = annotated.getAnnotation(ConfigProperties.class);
if (configProperties != null) {
if (!ConfigProperties.UNCONFIGURED_PREFIX.equals(configProperties.prefix())) {
return Optional.of(configProperties.prefix());
}
}
}

for (Annotation qualifier : injectionPoint.getQualifiers()) {
if (qualifier instanceof ConfigProperties) {
ConfigProperties configPropertiesQualifier = (ConfigProperties) qualifier;
if (!ConfigProperties.UNCONFIGURED_PREFIX.equals(configPropertiesQualifier.prefix())) {
return Optional.of(configPropertiesQualifier.prefix());
}
}
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.smallrye.jwt.deployment;

import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
import java.util.function.BooleanSupplier;
Expand Down Expand Up @@ -120,18 +119,16 @@ FeatureBuildItem feature() {
* @return NativeImageResourceBuildItem
*/
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
NativeImageResourceBuildItem registerNativeImageResources() {
final Config config = ConfigProvider.getConfig();
try {
Optional<String> publicKeyLocationOpt = config.getOptionalValue("mp.jwt.verify.publickey.location", String.class);
if (publicKeyLocationOpt.isPresent()) {
final String publicKeyLocation = publicKeyLocationOpt.get();
if (publicKeyLocation.indexOf(':') < 0 || publicKeyLocation.startsWith("classpath:")) {
log.infof("Adding %s to native image", publicKeyLocation);
return new NativeImageResourceBuildItem(publicKeyLocation);
}
void registerNativeImageResources(BuildProducer<NativeImageResourceBuildItem> nativeImageResource) {
Config config = ConfigProvider.getConfig();
Optional<String> publicKeyLocationOpt = config.getOptionalValue("mp.jwt.verify.publickey.location", String.class);
if (publicKeyLocationOpt.isPresent()) {
String publicKeyLocation = publicKeyLocationOpt.get();
if (publicKeyLocation.indexOf(':') < 0 || publicKeyLocation.startsWith("classpath:")) {
log.infof("Adding %s to native image", publicKeyLocation);
nativeImageResource.produce(new NativeImageResourceBuildItem(publicKeyLocation));
}
} catch (NoSuchElementException e) {
} else {
// The Config may contain expansion variables. Don't fail in this case because the config is not build time.
// The user will have to provide the config for runtime and register the resource manually
String publicKeyRawValue = Expressions.withoutExpansion(new Supplier<String>() {
Expand All @@ -142,9 +139,7 @@ public String get() {
});
log.warnf("Cannot determine %s of mp.jwt.verify.publickey.location to register with the native image",
publicKeyRawValue);
return null;
}
return null;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions integration-tests/smallrye-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<!-- Add opentracing to ensure that it works in native when undertow isn't present -->
<!-- See https://github.com/quarkusio/quarkus/issues/14966 -->
Expand Down Expand Up @@ -80,7 +80,6 @@
<scope>test</scope>
</dependency>


<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -110,7 +109,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -123,7 +122,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.config.SmallRyeConfig;

Expand All @@ -29,6 +31,12 @@ public Response profiles() {
return Response.ok(config.getProfiles()).build();
}

@GET
@Path("/uuid")
public Response uuid() {
return Response.ok(ConfigProvider.getConfig().getConfigValue("quarkus.uuid")).build();
}

@RegisterForReflection(targets = {
org.eclipse.microprofile.config.ConfigValue.class,
io.smallrye.config.ConfigValue.class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.it.smallrye.config;

import static io.restassured.RestAssured.given;
import static javax.ws.rs.core.Response.Status.OK;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class QuarkusConfigTest {
@Test
void uuid() {
given()
.get("/config/{name}", "quarkus.uuid")
.then()
.statusCode(OK.getStatusCode())
.body("value", is(notNullValue()))
.body("configSourceName", equalTo("DefaultValuesConfigSource"));

given()
.get("/config/uuid")
.then()
.statusCode(OK.getStatusCode())
.body("value", is(notNullValue()))
.body("configSourceName", equalTo("DefaultValuesConfigSource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.Header;

@QuarkusTest
class ServerResourceTest {
@BeforeAll
static void beforeAll() {
RestAssured.filters(
(requestSpec, responseSpec, ctx) -> {
requestSpec.header(new Header(CONTENT_TYPE, APPLICATION_JSON));
requestSpec.header(new Header(ACCEPT, APPLICATION_JSON));
return ctx.next(requestSpec, responseSpec);
});
}

@Test
void mapping() {
given()
Expand Down Expand Up @@ -99,7 +87,10 @@ void info() {

@Test
void invalid() {
given().get("/server/validator/{prefix}", "cloud")
given()
.header(new Header(CONTENT_TYPE, APPLICATION_JSON))
.header(new Header(ACCEPT, APPLICATION_JSON))
.get("/server/validator/{prefix}", "cloud")
.then()
.statusCode(OK.getStatusCode())
.body("errors", hasSize(9))
Expand Down
4 changes: 2 additions & 2 deletions jakarta/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ displayName: Adjust SmallRye dependencies
recipeList:
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-common.version
newValue: 2.0.0-RC3
newValue: 2.0.0
- org.openrewrite.maven.ChangePropertyValue:
key: microprofile-context-propagation.version
newValue: 1.3
Expand All @@ -514,7 +514,7 @@ recipeList:
newValue: 3.0
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-config.version
newValue: 3.0.0-RC4
newValue: 3.0.0
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-fault-tolerance.version
newValue: 6.0.0-RC4
Expand Down

0 comments on commit 44dca6f

Please sign in to comment.