diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-06-10 15:46:26 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-06-10 16:45:37 +0200 |
commit | 8919e8a2cf399fcf775a48c5a4818f034b71d6e0 (patch) | |
tree | 74307f453c05a32fe1731a02ae90a572ef9581eb /vespa-feed-client | |
parent | af935e9a62a6b62f0ecae9b01680e2761d8dac11 (diff) |
Rename variables and add shared config validation
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/ApacheCluster.java | 8 | ||||
-rw-r--r-- | vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java | 26 |
2 files changed, 18 insertions, 16 deletions
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/ApacheCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/ApacheCluster.java index 672f5f080b5..7939e884551 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/ApacheCluster.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/ApacheCluster.java @@ -145,11 +145,11 @@ class ApacheCluster implements Cluster { private static SSLContext constructSslContext(FeedClientBuilder builder) throws IOException { if (builder.sslContext != null) return builder.sslContext; SslContextBuilder sslContextBuilder = new SslContextBuilder(); - if (builder.certificate != null && builder.privateKey != null) { - sslContextBuilder.withCertificateAndKey(builder.certificate, builder.privateKey); + if (builder.certificateFile != null && builder.privateKeyFile != null) { + sslContextBuilder.withCertificateAndKey(builder.certificateFile, builder.privateKeyFile); } - if (builder.caCertificates != null) { - sslContextBuilder.withCaCertificates(builder.caCertificates); + if (builder.caCertificatesFile != null) { + sslContextBuilder.withCaCertificates(builder.caCertificatesFile); } return sslContextBuilder.build(); } diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java index d0a221ed358..bc9fa6b7e36 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java @@ -35,9 +35,9 @@ public class FeedClientBuilder { int maxStreamsPerConnection = 128; FeedClient.RetryStrategy retryStrategy = defaultRetryStrategy; FeedClient.CircuitBreaker circuitBreaker = new GracePeriodCircuitBreaker(Duration.ofSeconds(1), Duration.ofMinutes(10)); - Path certificate; - Path privateKey; - Path caCertificates; + Path certificateFile; + Path privateKeyFile; + Path caCertificatesFile; public static FeedClientBuilder create(URI endpoint) { return new FeedClientBuilder(Collections.singletonList(endpoint)); } @@ -81,9 +81,6 @@ public class FeedClientBuilder { } public FeedClientBuilder setSslContext(SSLContext context) { - if (certificate != null || caCertificates != null || privateKey != null) { - throw new IllegalArgumentException("Cannot set both SSLContext and certificate / CA certificates"); - } this.sslContext = requireNonNull(context); return this; } @@ -113,24 +110,29 @@ public class FeedClientBuilder { } public FeedClientBuilder setCertificate(Path certificatePemFile, Path privateKeyPemFile) { - if (sslContext != null) throw new IllegalArgumentException("Cannot set both SSLContext and certificate"); - this.certificate = certificatePemFile; - this.privateKey = privateKeyPemFile; + this.certificateFile = certificatePemFile; + this.privateKeyFile = privateKeyPemFile; return this; } - public FeedClientBuilder setCaCertificates(Path caCertificatesFile) { - if (sslContext != null) throw new IllegalArgumentException("Cannot set both SSLContext and CA certificate"); - this.caCertificates = caCertificatesFile; + public FeedClientBuilder setCaCertificatesFile(Path caCertificatesFile) { + this.caCertificatesFile = caCertificatesFile; return this; } public FeedClient build() { try { + validateConfiguration(); return new HttpFeedClient(this); } catch (IOException e) { throw new UncheckedIOException(e); } } + private void validateConfiguration() { + if (sslContext != null && (certificateFile != null || caCertificatesFile != null || privateKeyFile != null)) { + throw new IllegalArgumentException("Cannot set both SSLContext and certificate / CA certificates"); + } + } + } |