@Test public void testHeaders() throws ParseException { EcrExtendedAuth eea = new EcrExtendedAuth(logger, "123456789012.dkr.ecr.eu-west-1.amazonaws.com"); AuthConfig localCredentials = new AuthConfig.Builder() .username("username") .password("password") .build(); Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20161217T211058Z"); HttpPost request = eea.createSignedRequest(localCredentials, signingTime); assertEquals("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=1bab0f5c269debe913e532011d5d192b190bb4c55d3de1bc1506eefb93e058e1", request.getFirstHeader("Authorization").getValue()); }
HttpPost createSignedRequest(AuthConfig localCredentials, Date time) { String host = "ecr." + region + ".amazonaws.com"; logger.debug("Get ECR AuthorizationToken from %s", host); HttpPost request = new HttpPost("https: request.setHeader("host", host); request.setHeader("Content-Type", "application/x-amz-json-1.1"); request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken"); request.setEntity(new StringEntity("{\"registryIds\":[\""+ accountId + "\"]}", StandardCharsets.UTF_8)); AwsSigner4 signer = new AwsSigner4(region, "ecr"); signer.sign(request, localCredentials, time); return request; }
EcrExtendedAuth { HttpPost createSignedRequest(AuthConfig localCredentials, Date time) { String host = "ecr." + region + ".amazonaws.com"; logger.debug("Get ECR AuthorizationToken from %s", host); HttpPost request = new HttpPost("https: request.setHeader("host", host); request.setHeader("Content-Type", "application/x-amz-json-1.1"); request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken"); request.setEntity(new StringEntity("{\"registryIds\":[\""+ accountId + "\"]}", StandardCharsets.UTF_8)); AwsSigner4 signer = new AwsSigner4(region, "ecr"); signer.sign(request, localCredentials, time); return request; } }
EcrExtendedAuth { HttpPost createSignedRequest(AuthConfig localCredentials, Date time) { String host = "ecr." + region + ".amazonaws.com"; logger.debug("Get ECR AuthorizationToken from %s", host); HttpPost request = new HttpPost("https: request.setHeader("host", host); request.setHeader("Content-Type", "application/x-amz-json-1.1"); request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken"); request.setEntity(new StringEntity("{\"registryIds\":[\""+ accountId + "\"]}", StandardCharsets.UTF_8)); AwsSigner4 signer = new AwsSigner4(region, "ecr"); signer.sign(request, localCredentials, time); return request; } EcrExtendedAuth(KitLogger logger, String registry); }
EcrExtendedAuth { HttpPost createSignedRequest(AuthConfig localCredentials, Date time) { String host = "ecr." + region + ".amazonaws.com"; logger.debug("Get ECR AuthorizationToken from %s", host); HttpPost request = new HttpPost("https: request.setHeader("host", host); request.setHeader("Content-Type", "application/x-amz-json-1.1"); request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken"); request.setEntity(new StringEntity("{\"registryIds\":[\""+ accountId + "\"]}", StandardCharsets.UTF_8)); AwsSigner4 signer = new AwsSigner4(region, "ecr"); signer.sign(request, localCredentials, time); return request; } EcrExtendedAuth(KitLogger logger, String registry); static boolean isAwsRegistry(String registry); boolean isAwsRegistry(); AuthConfig extendedAuth(AuthConfig localCredentials); }
EcrExtendedAuth { HttpPost createSignedRequest(AuthConfig localCredentials, Date time) { String host = "ecr." + region + ".amazonaws.com"; logger.debug("Get ECR AuthorizationToken from %s", host); HttpPost request = new HttpPost("https: request.setHeader("host", host); request.setHeader("Content-Type", "application/x-amz-json-1.1"); request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken"); request.setEntity(new StringEntity("{\"registryIds\":[\""+ accountId + "\"]}", StandardCharsets.UTF_8)); AwsSigner4 signer = new AwsSigner4(region, "ecr"); signer.sign(request, localCredentials, time); return request; } EcrExtendedAuth(KitLogger logger, String registry); static boolean isAwsRegistry(String registry); boolean isAwsRegistry(); AuthConfig extendedAuth(AuthConfig localCredentials);  }