diff options
Diffstat (limited to 'hosted-api/src/main/java/ai/vespa/hosted/api/DefaultApiAuthenticator.java')
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/DefaultApiAuthenticator.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/DefaultApiAuthenticator.java b/hosted-api/src/main/java/ai/vespa/hosted/api/DefaultApiAuthenticator.java new file mode 100644 index 00000000000..cdd9a9a56dc --- /dev/null +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/DefaultApiAuthenticator.java @@ -0,0 +1,21 @@ +// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.hosted.api; + +public class DefaultApiAuthenticator implements ai.vespa.hosted.api.ApiAuthenticator { + + /** Returns a controller client using mTLS if a key and certificate pair is provided, or signed requests otherwise. */ + @Override + public ControllerHttpClient controller() { + return Properties.apiCertificateFile() + .map(certificateFile -> ControllerHttpClient.withKeyAndCertificate(Properties.apiEndpoint(), + Properties.apiKeyFile(), + certificateFile)) + .or(() -> Properties.apiKey().map(apiKey -> ControllerHttpClient.withSignatureKey(Properties.apiEndpoint(), + apiKey, + Properties.application()))) + .orElseGet(() -> ControllerHttpClient.withSignatureKey(Properties.apiEndpoint(), + Properties.apiKeyFile(), + Properties.application())); + } + +} |