Search in sources :

Example 16 with AuthConfig

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

the class AwsSdkAuthConfigFactoryTest method reflectionWorksForBasicCredentials.

@Test
public void reflectionWorksForBasicCredentials() {
    String accessKey = randomUUID().toString();
    String secretKey = randomUUID().toString();
    environmentVariables.set("AWSCredentials.AWSAccessKeyId", accessKey);
    environmentVariables.set("AWSCredentials.AWSSecretKey", secretKey);
    AuthConfig authConfig = objectUnderTest.createAuthConfig();
    assertNotNull(authConfig);
    assertEquals(accessKey, authConfig.getUsername());
    assertEquals(secretKey, authConfig.getPassword());
    assertNull(authConfig.getAuth());
    assertNull(authConfig.getIdentityToken());
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 17 with AuthConfig

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

the class EcrExtendedAuth method extendedAuth.

/**
 * Perform extended authentication.  Use the provided credentials as IAM credentials and
 * get a temporary ECR token.
 *
 * @param localCredentials IAM id/secret
 * @return ECR base64 encoded username:password
 * @throws IOException
 * @throws MojoExecutionException
 */
public AuthConfig extendedAuth(AuthConfig localCredentials) throws IOException, MojoExecutionException {
    JsonObject jo = getAuthorizationToken(localCredentials);
    JsonArray authorizationDatas = jo.getAsJsonArray("authorizationData");
    JsonObject authorizationData = authorizationDatas.get(0).getAsJsonObject();
    String authorizationToken = authorizationData.get("authorizationToken").getAsString();
    return new AuthConfig(authorizationToken, "none");
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Example 18 with AuthConfig

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

the class EcrExtendedAuthTest method testHeaders.

@Test
public void testHeaders() throws ParseException {
    EcrExtendedAuth eea = new EcrExtendedAuth(logger, "123456789012.dkr.ecr.eu-west-1.amazonaws.com");
    AuthConfig localCredentials = new AuthConfig("username", "password", null, null);
    Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20161217T211058Z");
    HttpPost request = eea.createSignedRequest(localCredentials, signingTime);
    assertEquals("api.ecr.eu-west-1.amazonaws.com", request.getFirstHeader("host").getValue());
    assertEquals("20161217T211058Z", request.getFirstHeader("X-Amz-Date").getValue());
    assertEquals("AWS4-HMAC-SHA256 Credential=username/20161217/eu-west-1/ecr/aws4_request, SignedHeaders=content-type;host;x-amz-target, Signature=2ae11d499499cc951900aac0fbec96009382ba4f735bd14baa375c3e51d50aa9", request.getFirstHeader("Authorization").getValue());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Date(java.util.Date) Test(org.junit.Test)

Example 19 with AuthConfig

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

the class JibBuildServiceTest method testGetRegistryCredentialsForPush.

@Test
@java.lang.SuppressWarnings("squid:S00112")
public void testGetRegistryCredentialsForPush() throws MojoExecutionException {
    // Given
    ImageConfiguration imageConfiguration = getImageConfiguration();
    RegistryService.RegistryConfig registryConfig = new RegistryService.RegistryConfig.Builder().authConfig(Collections.emptyMap()).authConfigFactory(authConfigFactory).settings(settings).build();
    mockAuthConfigFactory(true, registryConfig);
    // When
    Credential credential = JibBuildService.getRegistryCredentials(registryConfig, true, imageConfiguration, logger);
    // Then
    assertNotNull(credential);
    assertEquals("testuserpush", 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 20 with AuthConfig

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

the class RegistryServiceTest method pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull.

@Test
public void pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull() throws DockerAccessException {
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().createImageOptions(Collections.singletonMap("platform", "linux/amd64")).build();
    imageConfiguration = new ImageConfiguration.Builder().name("myregistry.com/user/app:1.0.1").buildConfig(buildImageConfiguration).build();
    givenAnImage("myregistry.com/user/test:1.0.1");
    givenHasImage(false);
    givenPreviousPulled(false);
    givenRegistry("anotherRegistry.com");
    givenImagePullPolicy(ImagePullPolicy.Always);
    whenAutoPullImage();
    new Verifications() {

        {
            String pulledImage;
            CreateImageOptions createImageOptions;
            docker.pullImage(pulledImage = withCapture(), (AuthConfig) any, anyString, createImageOptions = withCapture());
            times = 1;
            assertEquals("myregistry.com/user/test:1.0.1", pulledImage);
            assertNotNull(createImageOptions);
            assertEquals(3, createImageOptions.getOptions().size());
            assertEquals("linux/amd64", createImageOptions.getOptions().get("platform"));
            assertEquals("1.0.1", createImageOptions.getOptions().get("tag"));
            assertEquals("myregistry.com/user/test", createImageOptions.getOptions().get("fromImage"));
        }
    };
}
Also used : CreateImageOptions(io.fabric8.maven.docker.access.CreateImageOptions) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) 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