diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2021-12-14 08:35:52 +0100 |
---|---|---|
committer | Morten Tokle <mortent@verizonmedia.com> | 2021-12-14 08:36:53 +0100 |
commit | 59ae4058e6107f276bdb22bcd018f36927d9da4a (patch) | |
tree | ff3d1553c97541ddfcd23e9d485aed091bfca5e1 /tenant-cd-commons | |
parent | f16f20804691546bba8c234c47fb713ab9db1a18 (diff) |
Provide feed client builder implementation
Diffstat (limited to 'tenant-cd-commons')
4 files changed, 38 insertions, 2 deletions
diff --git a/tenant-cd-commons/pom.xml b/tenant-cd-commons/pom.xml index 1d76654fbf7..4c81142aa2d 100644 --- a/tenant-cd-commons/pom.xml +++ b/tenant-cd-commons/pom.xml @@ -42,6 +42,12 @@ <artifactId>config-provisioning</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>vespa-feed-client</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> </dependencies> <build> diff --git a/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/EndpointAuthenticator.java b/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/EndpointAuthenticator.java index 90775ab76af..5317cf01e21 100644 --- a/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/EndpointAuthenticator.java +++ b/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/EndpointAuthenticator.java @@ -4,6 +4,7 @@ package ai.vespa.hosted.cd.commons; import javax.net.ssl.SSLContext; import java.net.http.HttpRequest; import java.security.NoSuchAlgorithmException; +import java.util.Map; /** * Adds environment dependent authentication to HTTP request against Vespa deployments. @@ -20,8 +21,7 @@ public interface EndpointAuthenticator { default SSLContext sslContext() { try { return SSLContext.getDefault(); - } - catch (NoSuchAlgorithmException e) { + } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } @@ -31,4 +31,7 @@ public interface EndpointAuthenticator { return request; } + default Map<String, String> authorizationHeaders() { + return Map.of(); + } } diff --git a/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/FeedClientBuilder.java b/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/FeedClientBuilder.java new file mode 100644 index 00000000000..892c8b63645 --- /dev/null +++ b/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/FeedClientBuilder.java @@ -0,0 +1,25 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package ai.vespa.hosted.cd.commons; + +import ai.vespa.feed.client.impl.FeedClientBuilderImpl; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author mortent + */ +public class FeedClientBuilder extends FeedClientBuilderImpl { + + static AtomicReference<EndpointAuthenticator> endpointAuthenticator = new AtomicReference<>(); + + public static void setEndpointAuthenticator(EndpointAuthenticator authenticator) { + endpointAuthenticator.set(authenticator); + } + + public FeedClientBuilder() { + super.setSslContext(Objects.requireNonNull(endpointAuthenticator.get(), FeedClientBuilder.class.getName() + " is not initialized").sslContext()); + endpointAuthenticator.get().authorizationHeaders().forEach(super::addRequestHeader); + } +} diff --git a/tenant-cd-commons/src/main/resources/META-INF.services/ai.vespa.feed.client.FeedClientBuilder b/tenant-cd-commons/src/main/resources/META-INF.services/ai.vespa.feed.client.FeedClientBuilder new file mode 100644 index 00000000000..69073a3951c --- /dev/null +++ b/tenant-cd-commons/src/main/resources/META-INF.services/ai.vespa.feed.client.FeedClientBuilder @@ -0,0 +1,2 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +ai.vespa.hosted.cd.commons.FeedClientBuilder
\ No newline at end of file |