diff options
Diffstat (limited to 'hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java')
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java b/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java index 6fba083e607..79c11cf86de 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/ControllerHttpClient.java @@ -17,6 +17,7 @@ import com.yahoo.slime.JsonFormat; import com.yahoo.slime.ObjectTraverser; import com.yahoo.slime.Slime; +import javax.net.ssl.SSLContext; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -77,6 +78,11 @@ public abstract class ControllerHttpClient { return new SigningControllerHttpClient(endpoint, privateKeyFile, id); } + /** Creates an HTTP client against the given endpoint, which uses the given SSL context for authentication. */ + public static ControllerHttpClient withSSLContext(URI endpoint, SSLContext sslContext) { + return new MutualTlsControllerHttpClient(endpoint, sslContext); + } + /** Creates an HTTP client against the given endpoint, which uses the given private key and certificate identity. */ public static ControllerHttpClient withKeyAndCertificate(URI endpoint, Path privateKeyFile, Path certificateFile) { var privateKey = unchecked(() -> KeyUtils.fromPemEncodedPrivateKey(Files.readString(privateKeyFile, UTF_8))); @@ -150,11 +156,12 @@ public abstract class ControllerHttpClient { public DeploymentLog followDeploymentUntilDone(ApplicationId id, ZoneId zone, long run, Consumer<DeploymentLog.Entry> out) { long last = -1; - DeploymentLog log; + DeploymentLog log = null; while (true) { - log = deploymentLog(id, zone, run, last); - for (DeploymentLog.Entry entry : log.entries()) + DeploymentLog update = deploymentLog(id, zone, run, last); + for (DeploymentLog.Entry entry : update.entries()) out.accept(entry); + log = (log == null ? update : log.updatedWith(update)); last = log.last().orElse(last); if ( ! log.isActive()) @@ -410,14 +417,17 @@ public abstract class ControllerHttpClient { /** Client that uses a given key / certificate identity to authenticate to the remote controller. */ private static class MutualTlsControllerHttpClient extends ControllerHttpClient { + private MutualTlsControllerHttpClient(URI endpoint, SSLContext sslContext) { + super(endpoint, HttpClient.newBuilder().sslContext(sslContext)); + } + private MutualTlsControllerHttpClient(URI endpoint, PrivateKey privateKey, List<X509Certificate> certs) { - super(endpoint, - HttpClient.newBuilder() - .sslContext(new SslContextBuilder().withKeyStore(privateKey, certs).build())); + this(endpoint, new SslContextBuilder().withKeyStore(privateKey, certs).build()); } } + private static DeploymentLog.Status valueOf(String status) { switch (status) { case "running": return DeploymentLog.Status.running; |