aboutsummaryrefslogtreecommitdiffstats
path: root/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/FeedClientBuilder.java
blob: 7e7355ae6d44b30637d4a1bd2d60c0e6e0a835fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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 ai.vespa.hosted.cd.EndpointAuthenticator;

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);
    }
}