Example usage for com.amazonaws.services.ecr.model GetAuthorizationTokenRequest GetAuthorizationTokenRequest

List of usage examples for com.amazonaws.services.ecr.model GetAuthorizationTokenRequest GetAuthorizationTokenRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.ecr.model GetAuthorizationTokenRequest GetAuthorizationTokenRequest.

Prototype

GetAuthorizationTokenRequest

Source Link

Usage

From source file:com.cloudbees.jenkins.plugins.amazonecr.AmazonECSRegistryCredential.java

License:Open Source License

@NonNull
@Override/*from ww  w.ja  v a2s .  com*/
public Secret getPassword() {
    final AmazonWebServicesCredentials credentials = getCredentials();
    if (credentials == null)
        throw new IllegalStateException("Invalid credentials");

    final AmazonECRClient client = new AmazonECRClient(credentials.getCredentials(), new ClientConfiguration());
    final GetAuthorizationTokenResult authorizationToken = client
            .getAuthorizationToken(new GetAuthorizationTokenRequest());
    final List<AuthorizationData> authorizationData = authorizationToken.getAuthorizationData();
    if (authorizationData == null || authorizationData.isEmpty()) {
        throw new IllegalStateException("Failed to retreive authorization token for Amazon ECR");
    }
    return Secret.fromString(authorizationData.get(0).getAuthorizationToken());
}

From source file:jp.classmethod.aws.gradle.ecr.AmazonECRGetAuthorizationTokenTask.java

License:Apache License

@TaskAction
public void createRepository() {
    List<String> repositoryIds = getRepositoryIds();

    if (repositoryIds == null || repositoryIds.isEmpty()) {
        throw new GradleException("Must specify ECR repositoryIds");
    }/*from  w  w w  .j  a  va  2s  .  c o m*/

    AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class);
    AmazonECR ecr = ext.getClient();

    GetAuthorizationTokenResult result = ecr
            .getAuthorizationToken(new GetAuthorizationTokenRequest().withRegistryIds(repositoryIds));
    authorizationData = result.getAuthorizationData();
}