Search in sources :

Example 26 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AwsSigner4RequestTest method testSign.

@Test
public void testSign() throws Exception {
    HttpPost request = new HttpPost("https://ecr.us-east-1.amazonaws.com/");
    request.setHeader("host", "ecr.us-east-1.amazonaws.com");
    request.setHeader("Content-Type", "application/x-amz-json-1.1");
    request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken");
    request.setEntity(new StringEntity("{\"registryIds\":[\"012345678901\"]}", StandardCharsets.UTF_8));
    AwsSigner4 signer = new AwsSigner4("us-east-1", "ecr");
    Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20150830T123600Z");
    AwsSigner4Request sr = new AwsSigner4Request("us-east-1", "service", request, signingTime);
    AuthConfig credentials = new AuthConfig("AKIDEXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", null, null);
    Assert.assertEquals(TASK1, signer.task1(sr));
    Assert.assertEquals(TASK2, signer.task2(sr));
    StringBuilder dst = new StringBuilder();
    AwsSigner4.hexEncode(dst, signer.task3(sr, credentials));
    Assert.assertEquals(TASK3, dst.toString());
    Assert.assertEquals(TASK4, signer.task4(sr, credentials));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Date(java.util.Date) Test(org.junit.Test)

Example 27 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method pushImage.

@Override
public void pushImage(String image, AuthConfig authConfig, String registry, int retries) throws DockerAccessException {
    ImageName name = new ImageName(image);
    String pushUrl = urlBuilder.pushImage(name, registry);
    TemporaryImageHandler temporaryImageHandler = tagTemporaryImage(name, registry);
    DockerAccessException dae = null;
    try {
        doPushImage(pushUrl, createAuthHeader(authConfig), createPullOrPushResponseHandler(), HTTP_OK, retries);
    } catch (IOException e) {
        dae = new DockerAccessException(e, "Unable to push '%s'%s", image, (registry != null) ? " to registry '" + registry + "'" : "");
        throw dae;
    } finally {
        temporaryImageHandler.handle(dae);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 28 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class JibBuildServiceTest method testGetRegistryCredentialsForPull.

@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPull() throws MojoExecutionException {
    // Given
    ImageConfiguration imageConfiguration = getImageConfiguration();
    RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
    mockAuthConfigFactory(false, registryConfig);
    // When
    Credential credential = JibBuildService.getRegistryCredentials(registryConfig, false, imageConfiguration, logger);
    // Then
    assertNotNull(credential);
    assertEquals("testuserpull", credential.getUsername());
    assertEquals("testpass", credential.getPassword());
}
Also used : Credential(com.google.cloud.tools.jib.api.Credential) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 29 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigTest method mapConstructor.

@Test
public void mapConstructor() {
    AuthConfig config = new AuthConfig("roland", "#>secrets??", "roland@jolokia.org", null);
    check(config);
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 30 with AuthConfig

use of io.fabric8.maven.docker.access.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromSettingsDefault.

@Test
public void testFromSettingsDefault() throws MojoExecutionException {
    setupServers();
    AuthConfig config = factory.createAuthConfig(isPush, false, null, settings, "fabric8io", "test.org");
    assertNotNull(config);
    verifyAuthConfig(config, "fabric8io", "secret2", "fabric8io@redhat.com");
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Aggregations

AuthConfig (io.fabric8.maven.docker.access.AuthConfig)38 Test (org.junit.Test)26 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 ImageName (io.fabric8.maven.docker.util.ImageName)4 HashMap (java.util.HashMap)4 Credential (com.google.cloud.tools.jib.api.Credential)3 JsonObject (com.google.gson.JsonObject)3 IOException (java.io.IOException)3 Date (java.util.Date)3 Map (java.util.Map)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Expectations (mockit.Expectations)2 Verifications (mockit.Verifications)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 Gson (com.google.gson.Gson)1