diff options
Diffstat (limited to 'hosted-api/src/main/java/ai/vespa/hosted/api/EndpointAuthenticator.java')
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/EndpointAuthenticator.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/EndpointAuthenticator.java b/hosted-api/src/main/java/ai/vespa/hosted/api/EndpointAuthenticator.java new file mode 100644 index 00000000000..20e3b18eb56 --- /dev/null +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/EndpointAuthenticator.java @@ -0,0 +1,34 @@ +package ai.vespa.hosted.api; + +import javax.net.ssl.SSLContext; +import java.net.http.HttpRequest; +import java.security.NoSuchAlgorithmException; +import java.util.Optional; + +/** + * 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; + } + +} |