Skip to content

Commit

Permalink
Added a (Key/Trust)StoreOptions configuration properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mskacelik committed Sep 20, 2024
1 parent b0eb3f2 commit b4dc09d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
import io.smallrye.graphql.client.vertx.ssl.SSLTools;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.KeyCertOptions;
import io.vertx.core.net.ProxyOptions;
import io.vertx.core.net.TrustOptions;

public class VertxClientOptionsHelper {

public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLClientConfiguration configuration) {
if (options.getTrustStoreOptions() == null && configuration.getTrustStore() != null) {
TrustOptions tlsTrustStoreOptions = (TrustOptions) configuration.getTlsTrustStoreOptions();
KeyCertOptions tlsKeyStoreOptions = (KeyCertOptions) configuration.getTlsKeyStoreOptions();
if (tlsTrustStoreOptions != null) {
options.setSsl(true);
options.setTrustOptions(tlsTrustStoreOptions);
} else if (options.getTrustStoreOptions() == null && configuration.getTrustStore() != null) { // deprecated in Quarkus
options.setSsl(true);
JksOptions trustStoreOptions = new JksOptions();
KeyStore trustStore = SSLTools.createKeyStore(configuration.getTrustStore(),
Expand All @@ -21,8 +28,10 @@ public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLC
trustStoreOptions.setPassword(new String(configuration.getTrustStorePassword()));
options.setTrustStoreOptions(trustStoreOptions);
}

if (options.getKeyStoreOptions() == null && configuration.getKeyStore() != null) {
if (tlsKeyStoreOptions != null) {
options.setSsl(true);
options.setKeyCertOptions(tlsKeyStoreOptions);
} else if (options.getKeyStoreOptions() == null && configuration.getKeyStore() != null) { // deprecated in Quarkus
options.setSsl(true);
JksOptions keyStoreOptions = new JksOptions();
KeyStore keyStore = SSLTools.createKeyStore(configuration.getKeyStore(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public class GraphQLClientConfiguration {
*/
private String keyStoreType;

/**
* The key store options, already contains key tore.
*/
private Object tlsKeyStoreOptions;

/**
* The trust store options, already contains trust tore.
*/
private Object tlsTrustStoreOptions;

/**
* Hostname of the proxy to use.
*/
Expand Down Expand Up @@ -273,6 +283,22 @@ public void setAllowUnexpectedResponseFields(Boolean allowUnexpectedResponseFiel
this.allowUnexpectedResponseFields = allowUnexpectedResponseFields;
}

public Object getTlsKeyStoreOptions() {
return tlsKeyStoreOptions;
}

public void setTlsKeyStoreOptions(Object tlsKeyStoreOptions) {
this.tlsKeyStoreOptions = tlsKeyStoreOptions;
}

public Object getTlsTrustStoreOptions() {
return tlsTrustStoreOptions;
}

public void setTlsTrustStoreOptions(Object tlsTrustStoreOptions) {
this.tlsTrustStoreOptions = tlsTrustStoreOptions;
}

/**
* Merge the `other` configuration into this one. Values in `other` take precedence.
* This method has to be idempotent because it can be called multiple times to allow for changes in configuration.
Expand Down Expand Up @@ -350,6 +376,12 @@ public GraphQLClientConfiguration merge(GraphQLClientConfiguration other) {
if (other.allowUnexpectedResponseFields != null) {
this.allowUnexpectedResponseFields = other.allowUnexpectedResponseFields;
}
if (other.tlsKeyStoreOptions != null) {
this.tlsKeyStoreOptions = other.tlsKeyStoreOptions;
}
if (other.tlsTrustStoreOptions != null) {
this.tlsTrustStoreOptions = other.tlsTrustStoreOptions;
}
return this;
}
}

0 comments on commit b4dc09d

Please sign in to comment.