use of com.epam.pipeline.exception.docker.DockerCertificateException in project cloud-pipeline by epam.
the class DockerClient method checkAvailability.
public void checkAvailability() {
HttpEntity entity = getAuthHeaders();
String uri = String.format(HEALTH_ENTRY_POINT, hostName);
try {
getRestTemplate().exchange(uri, HttpMethod.GET, entity, String.class);
} catch (HTTPException | ResourceAccessException e) {
if (e.getCause() instanceof SSLHandshakeException) {
throw new DockerCertificateException(hostName, e.getCause());
} else {
throw new DockerConnectionException(hostName, e.getMessage(), e);
}
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new DockerCredentialsException(hostName, userName, password, e);
} else {
throw new DockerConnectionException(hostName, e.getMessage(), e);
}
}
}
use of com.epam.pipeline.exception.docker.DockerCertificateException in project cloud-pipeline by epam.
the class DockerClient method getHttpRequestFactory.
private ClientHttpRequestFactory getHttpRequestFactory(String caCert) {
try {
X509Certificate providedCert = getCertificate(caCert);
TrustStrategy acceptingTrustStrategy = (x509Certificates, s) -> Arrays.stream(x509Certificates).anyMatch(cert -> cert.getSerialNumber().equals(providedCert.getSerialNumber()));
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return requestFactory;
} catch (GeneralSecurityException e) {
throw new DockerCertificateException(hostName);
}
}
Aggregations