Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to ignore certificates when waiting for https ping. #559

Merged
merged 1 commit into from
Sep 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/fabric8/maven/docker/StartMojo.java
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ private WaitUtil.WaitChecker getUrlWaitChecker(String imageConfigDesc,
WaitConfiguration.HttpConfiguration httpConfig = wait.getHttp();
WaitUtil.HttpPingChecker checker;
if (httpConfig != null) {
checker = new WaitUtil.HttpPingChecker(waitUrl, httpConfig.getMethod(), httpConfig.getStatus());
checker = new WaitUtil.HttpPingChecker(waitUrl, httpConfig.getMethod(), httpConfig.getStatus(), httpConfig.isIgnoreCertificates());
log.info("%s: Waiting on url %s with method %s for status %s.",
imageConfigDesc, waitUrl, httpConfig.getMethod(), httpConfig.getStatus());
} else {
Original file line number Diff line number Diff line change
@@ -201,6 +201,9 @@ public static class HttpConfiguration {
@Parameter
private String status;

@Parameter
private boolean ignoreCertificates;

public HttpConfiguration() {}

private HttpConfiguration(String url, String method, String status) {
@@ -219,6 +222,10 @@ public String getMethod() {
public String getStatus() {
return status;
}

public boolean isIgnoreCertificates() {
return ignoreCertificates;
}
}

public enum TcpConfigMode {
38 changes: 34 additions & 4 deletions src/main/java/io/fabric8/maven/docker/util/WaitUtil.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -14,9 +17,12 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContextBuilder;


/**
@@ -125,6 +131,7 @@ public static class HttpPingChecker implements WaitChecker {
private int statusMin, statusMax;
private String url;
private String method;
private boolean ignoreCertificates;

/**
* Ping the given URL
@@ -159,6 +166,11 @@ public HttpPingChecker(String waitUrl) {
this(waitUrl, null, null);
}

public HttpPingChecker(String url, String method, String status, boolean ignoreCertificates) {
this(url, method, status);
this.ignoreCertificates = ignoreCertificates;
}

@Override
public boolean check() {
try {
@@ -176,10 +188,28 @@ private boolean ping() throws IOException {
.setConnectionRequestTimeout(HTTP_PING_TIMEOUT)
.setRedirectsEnabled(false)
.build();
CloseableHttpClient httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false))
.build();

CloseableHttpClient httpClient = null;
if (ignoreCertificates) {
SSLContextBuilder builder = new SSLContextBuilder();
try {
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false))
.setSSLSocketFactory(socketFactory)
.build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new RuntimeException("Unable to set self signed strategy on http wait", e);
}
} else {
httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_CLIENT_RETRIES, false))
.build();
}

try {
CloseableHttpResponse response = httpClient.execute(RequestBuilder.create(method.toUpperCase()).setUri(url).build());
try {