Skip to content

Commit

Permalink
Merge pull request #38211 from geoand/trustAll-restclient
Browse files Browse the repository at this point in the history
Add trustAll to QuarkusRestClientBuilder
  • Loading branch information
geoand committed Jan 16, 2024
2 parents d672c6d + 650603d commit 84abc29
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ static QuarkusRestClientBuilder newBuilder() {
*/
QuarkusRestClientBuilder loggingBodyLimit(Integer limit);

/**
* Enable trusting all certificates. Disable by default.
*/
QuarkusRestClientBuilder trustAll(boolean trustAll);

/**
* Based on the configured QuarkusRestClientBuilder, creates a new instance of the given REST interface to invoke API calls
* against.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ public QuarkusRestClientBuilder loggingBodyLimit(Integer limit) {
return this;
}

@Override
public QuarkusRestClientBuilder trustAll(boolean trustAll) {
proxy.trustAll(trustAll);
return this;
}

@Override
public <T> T build(Class<T> clazz) throws IllegalStateException, RestClientDefinitionException {
return proxy.build(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class RestClientBuilderImpl implements RestClientBuilder {
private LoggingScope loggingScope;
private Integer loggingBodyLimit;

private Boolean trustAll;

@Override
public RestClientBuilderImpl baseUrl(URL url) {
try {
Expand Down Expand Up @@ -179,6 +181,11 @@ public RestClientBuilderImpl loggingBodyLimit(Integer limit) {
return this;
}

public RestClientBuilderImpl trustAll(boolean trustAll) {
this.trustAll = trustAll;
return this;
}

@Override
public RestClientBuilderImpl executorService(ExecutorService executor) {
throw new IllegalArgumentException("Specifying executor service is not supported. " +
Expand Down Expand Up @@ -370,10 +377,13 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi

clientBuilder.multiQueryParamMode(toMultiQueryParamMode(queryParamStyle));

Boolean trustAll = ConfigProvider.getConfig().getOptionalValue(TLS_TRUST_ALL, Boolean.class)
.orElse(false);
Boolean effectiveTrustAll = trustAll;
if (effectiveTrustAll == null) {
effectiveTrustAll = ConfigProvider.getConfig().getOptionalValue(TLS_TRUST_ALL, Boolean.class)
.orElse(false);
}

clientBuilder.trustAll(trustAll);
clientBuilder.trustAll(effectiveTrustAll);
restClientsConfig.verifyHost.ifPresent(clientBuilder::verifyHost);

String userAgent = (String) getConfiguration().getProperty(QuarkusRestClientProperties.USER_AGENT);
Expand Down Expand Up @@ -452,5 +462,4 @@ private MultiQueryParamMode toMultiQueryParamMode(QueryParamStyle queryParamStyl
}
return null;
}

}

0 comments on commit 84abc29

Please sign in to comment.