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());
}
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");
}
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());
}
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());
}
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"));
}
};
}
Aggregations