Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trustAll to QuarkusRestClientBuilder #38211

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}

}