Search in sources :

Example 1 with DockerCertificateException

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);
        }
    }
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) DockerCredentialsException(com.epam.pipeline.exception.docker.DockerCredentialsException) HttpEntity(org.springframework.http.HttpEntity) DockerCertificateException(com.epam.pipeline.exception.docker.DockerCertificateException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException)

Example 2 with DockerCertificateException

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);
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) Arrays(java.util.Arrays) CertificateFactory(java.security.cert.CertificateFactory) HTTPException(javax.xml.ws.http.HTTPException) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) StringUtils(org.apache.commons.lang3.StringUtils) TagsListing(com.epam.pipeline.entity.docker.TagsListing) Base64(org.apache.commons.codec.binary.Base64) GeneralSecurityException(java.security.GeneralSecurityException) ByteArrayInputStream(java.io.ByteArrayInputStream) DockerCredentialsException(com.epam.pipeline.exception.docker.DockerCredentialsException) Constants(com.epam.pipeline.config.Constants) URI(java.net.URI) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) RestTemplate(org.springframework.web.client.RestTemplate) HttpHeaders(org.springframework.http.HttpHeaders) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MediaType(org.springframework.http.MediaType) DockerCertificateException(com.epam.pipeline.exception.docker.DockerCertificateException) Set(java.util.Set) HttpEntity(org.springframework.http.HttpEntity) List(java.util.List) RawImageDescription(com.epam.pipeline.entity.docker.RawImageDescription) RegistryListing(com.epam.pipeline.entity.docker.RegistryListing) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Optional(java.util.Optional) DockerConnectionException(com.epam.pipeline.exception.docker.DockerConnectionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClients(org.apache.http.impl.client.HttpClients) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Logger(org.slf4j.Logger) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) ResourceAccessException(org.springframework.web.client.ResourceAccessException) CertificateException(java.security.cert.CertificateException) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) HttpStatus(org.springframework.http.HttpStatus) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) URLEncoder(java.net.URLEncoder) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ImageDescription(com.epam.pipeline.entity.docker.ImageDescription) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) DockerCertificateException(com.epam.pipeline.exception.docker.DockerCertificateException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

DockerCertificateException (com.epam.pipeline.exception.docker.DockerCertificateException)2 DockerConnectionException (com.epam.pipeline.exception.docker.DockerConnectionException)2 DockerCredentialsException (com.epam.pipeline.exception.docker.DockerCredentialsException)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 HTTPException (javax.xml.ws.http.HTTPException)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 ResourceAccessException (org.springframework.web.client.ResourceAccessException)2 Constants (com.epam.pipeline.config.Constants)1 ImageDescription (com.epam.pipeline.entity.docker.ImageDescription)1 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)1 RawImageDescription (com.epam.pipeline.entity.docker.RawImageDescription)1 RegistryListing (com.epam.pipeline.entity.docker.RegistryListing)1 TagsListing (com.epam.pipeline.entity.docker.TagsListing)1 ToolVersion (com.epam.pipeline.entity.docker.ToolVersion)1 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)1 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1