Expose controller client factory with SSL context argument
@@ -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)));
@@ -410,14 +416,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;
