com.amazonaws.services.ecr.AmazonECRClient Java Examples

The following examples show how to use com.amazonaws.services.ecr.AmazonECRClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsService.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Override
public AwsToken load(AwsCredentials awsCredentials) throws Exception {
    AmazonECR amazonECR = new AmazonECRClient(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return awsCredentials;
        }

        @Override
        public void refresh() {
        }
    });
    amazonECR.setRegion(RegionUtils.getRegion(awsCredentials.getRegion()));
    GetAuthorizationTokenResult authorizationToken = amazonECR.getAuthorizationToken(new GetAuthorizationTokenRequest());
    List<AuthorizationData> authorizationData = authorizationToken.getAuthorizationData();
    Assert.isTrue(!CollectionUtils.isEmpty(authorizationData), "authorizationData is null or empty for token " + authorizationToken);
    AuthorizationData data = authorizationData.get(0);
    byte[] decode = Base64.getDecoder().decode(data.getAuthorizationToken());
    String token = new String(decode);
    String[] split = token.split(":");
    log.info("about to connect to AWS endpoint: {}", data.getProxyEndpoint());
    return AwsToken.builder().username(split[0]).password(split[1])
            .expiresAt(data.getExpiresAt()).proxyEndpoint(data.getProxyEndpoint()).build();
}
 
Example #2
Source File: AwsEcrAuthResolver.java    From codenvy with Eclipse Public License 1.0 6 votes vote down vote up
@VisibleForTesting
String getAwsAuthorizationToken(String accessKeyId, String secretAccessKey) {
  try {
    AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);
    AmazonECRClient amazonECRClient = new AmazonECRClient(credentials);
    GetAuthorizationTokenResult tokenResult =
        amazonECRClient.getAuthorizationToken(new GetAuthorizationTokenRequest());
    List<AuthorizationData> authData = tokenResult.getAuthorizationData();

    if (!authData.isEmpty()) {
      return authData.get(0).getAuthorizationToken();
    }

    LOG.warn("Failed to retrieve AWS ECR token");
  } catch (AmazonECRException e) {
    LOG.warn(e.getLocalizedMessage());
  }
  return null;
}
 
Example #3
Source File: AWSTokenRequestGenerator.java    From docker-registry-artifact-plugin with Apache License 2.0 4 votes vote down vote up
AWSTokenRequestGenerator() {
    builder = AmazonECRClient.builder();
}