blob: 3e3ebe57a7eb51a7ca94fc3228cad1d3f3abe8c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// Copyright Yahoo. 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()));
}
}
|