summaryrefslogtreecommitdiffstats
path: root/vespa-maven-plugin
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-09-14 14:33:33 +0200
committerMartin Polden <mpolden@mpolden.no>2021-09-14 14:33:33 +0200
commit68f599df3b26084d54f7b1f83019548262f8a70e (patch)
tree0afabf0258317edc5a6e33b41dbf0825fa5e855b /vespa-maven-plugin
parent375f65f3ee2563dbddb7fe878cb7364ba6bd2bb9 (diff)
Look for API key in Vespa CLI home
Diffstat (limited to 'vespa-maven-plugin')
-rw-r--r--vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
index ad10c1af608..50bdde28180 100644
--- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
+++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
@@ -12,6 +12,7 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import java.net.URI;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
@@ -90,19 +91,29 @@ public abstract class AbstractVespaMojo extends AbstractMojo {
.orElseThrow(() -> new MojoExecutionException("'instance' must be specified as a parameter or project property"));
id = ApplicationId.from(tenant, application, instance);
+ Optional<Path> apiKeyPath = apiKeyPath(tenant);
if ( ! isNullOrBlank(apiKey)) {
controller = ControllerHttpClient.withSignatureKey(URI.create(endpoint), apiKey, id);
}
- else if ( ! isNullOrBlank(apiKeyFile)) {
+ else if (apiKeyPath.isPresent()) {
controller = isNullOrBlank(apiCertificateFile)
- ? ControllerHttpClient.withSignatureKey(URI.create(endpoint), Paths.get(apiKeyFile), id)
- : ControllerHttpClient.withKeyAndCertificate(URI.create(endpoint), Paths.get(apiKeyFile), Paths.get(apiCertificateFile));
+ ? ControllerHttpClient.withSignatureKey(URI.create(endpoint), apiKeyPath.get(), id)
+ : ControllerHttpClient.withKeyAndCertificate(URI.create(endpoint), apiKeyPath.get(), Paths.get(apiCertificateFile));
}
else {
throw new IllegalArgumentException("One of the properties 'apiKey' or 'apiKeyFile' is required.");
}
}
+ private Optional<Path> apiKeyPath(String tenant) {
+ if (!isNullOrBlank(apiKeyFile)) return Optional.of(Paths.get(apiKeyFile));
+
+ Path cliApiKeyFile = Paths.get(System.getProperty("user.home"), ".vespa", tenant + ".api-key.pem");
+ if (Files.exists(cliApiKeyFile)) return Optional.of(cliApiKeyFile);
+
+ return Optional.empty();
+ }
+
protected String projectPathOf(String first, String... rest) {
return project.getBasedir().toPath().resolve(Path.of(first, rest)).toString();
}
@@ -132,4 +143,5 @@ public abstract class AbstractVespaMojo extends AbstractMojo {
.filter(s -> !s.isBlank())
.isEmpty();
}
+
}