aboutsummaryrefslogtreecommitdiffstats
path: root/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/EndpointAuthenticator.java
blob: e7936ddea7a4b5f65be3395d90cdc4ce2a4164aa (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
27
28
29
30
31
32
33
34
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.hosted.cd.commons;

import javax.net.ssl.SSLContext;
import java.net.http.HttpRequest;
import java.security.NoSuchAlgorithmException;

/**
 * Adds environment dependent authentication to HTTP request against Vespa deployments.
 *
 * An implementation typically needs to override either of the methods in this interface,
 * and needs to run in different environments, e.g., local user testing and automatic testing
 * in a deployment pipeline.
 *
 * @author jonmv
 */
public interface EndpointAuthenticator {

    /** Returns an SSLContext which provides authentication against a Vespa endpoint. */
    default SSLContext sslContext() {
        try {
            return SSLContext.getDefault();
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    /** Adds necessary authentication data to the given HTTP request builder, to pass the data plane of a Vespa endpoint. */
    default HttpRequest.Builder authenticated(HttpRequest.Builder request) {
        return request;
    }

}