Skip to content

Commit

Permalink
REST Client build time fix for DevServices
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Nov 8, 2024
1 parent 5810fca commit ae36baf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ interface RestClientBuildConfig {
* @return a {@link RestClientsBuildTimeConfig} with the discovered registered REST Clients configuration only.
*/
default RestClientsBuildTimeConfig get(List<RegisteredRestClient> restClients) {
SmallRyeConfig config = new SmallRyeConfigBuilder()
return getConfig(restClients).getConfigMapping(RestClientsBuildTimeConfig.class);
}

default SmallRyeConfig getConfig(List<RegisteredRestClient> restClients) {
return new SmallRyeConfigBuilder()
.withSources(
new ConfigSource() {
final SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
final ConfigSource defaultsSource = getDefaultsSource();

@Override
public Set<String> getPropertyNames() {
Expand All @@ -97,13 +102,25 @@ public Set<String> getPropertyNames() {

@Override
public String getValue(final String propertyName) {
return config.getRawValue(propertyName);
ConfigValue configValue = config.getConfigValue(propertyName);
if (configValue != null && !defaultsSource.getName().equals(configValue.getSourceName())) {
return configValue.getValue();
}
return null;
}

@Override
public String getName() {
return "SmallRye Config";
}

private ConfigSource getDefaultsSource() {
ConfigSource configSource = null;
for (ConfigSource source : config.getConfigSources()) {
configSource = source;
}
return configSource;
}
})
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
@Override
Expand All @@ -119,7 +136,5 @@ public List<RegisteredRestClient> getRestClients() {
.withMapping(RestClientsBuildTimeConfig.class)
.withMappingIgnore("quarkus.**")
.build();

return config.getConfigMapping(RestClientsBuildTimeConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -232,6 +233,19 @@ public List<RegisteredRestClient> getRestClients() {
assertThat(restClientConfig.uri().get()).isEqualTo("http://localhost:8082");
}

@Test
void buildTimeConfig() {
SmallRyeConfig config = ConfigUtils.emptyConfigBuilder()
.withMapping(RestClientsBuildTimeConfig.class)
.build();
assertNotNull(config);

RestClientsBuildTimeConfig buildTimeConfig = config.getConfigMapping(RestClientsBuildTimeConfig.class)
.get(List.of(new RegisteredRestClient(ConfigKeyRestClient.class, "key")));

assertFalse(buildTimeConfig.clients().get(ConfigKeyRestClient.class.getName()).removesTrailingSlash());
}

private void verifyConfig(RestClientConfig config) {
assertTrue(config.url().isPresent());
assertThat(config.url().get()).isEqualTo("http://localhost:8080");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.exception.UncheckedException;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
Expand All @@ -32,6 +31,7 @@
import io.quarkus.rest.client.reactive.deployment.RegisteredRestClientBuildItem;
import io.quarkus.rest.client.reactive.spi.DevServicesRestClientProxyProvider;
import io.quarkus.rest.client.reactive.spi.RestClientHttpProxyBuildItem;
import io.quarkus.restclient.config.RegisteredRestClient;
import io.quarkus.restclient.config.RestClientsBuildTimeConfig;
import io.quarkus.restclient.config.RestClientsBuildTimeConfig.RestClientBuildConfig;
import io.smallrye.config.SmallRyeConfig;
Expand Down Expand Up @@ -60,14 +60,15 @@ public void determineRequiredProxies(
CombinedIndexBuildItem combinedIndexBuildItem,
List<RegisteredRestClientBuildItem> registeredRestClientBuildItems,
BuildProducer<RestClientHttpProxyBuildItem> producer) {
Map<String, RestClientBuildConfig> configs = clientsConfig.get(toRegisteredRestClients(registeredRestClientBuildItems))
.clients();

List<RegisteredRestClient> registeredRestClients = toRegisteredRestClients(registeredRestClientBuildItems);
Map<String, RestClientBuildConfig> configs = clientsConfig.get(registeredRestClients).clients();
if (configs.isEmpty()) {
return;
}

IndexView index = combinedIndexBuildItem.getIndex();
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
SmallRyeConfig config = clientsConfig.getConfig(registeredRestClients);
for (var configEntry : configs.entrySet()) {
if (!configEntry.getValue().enableLocalProxy()) {
log.trace("Ignoring config key: '" + configEntry.getKey() + "' because enableLocalProxy is false");
Expand Down

0 comments on commit ae36baf

Please sign in to comment.