com.amazonaws.services.ecr.model.AuthorizationData Java Examples
The following examples show how to use
com.amazonaws.services.ecr.model.AuthorizationData.
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: RegistryAuthSupplierChainTest.java From docker-registry-artifact-plugin with Apache License 2.0 | 6 votes |
@Test public void shouldSetUsernameAndPasswordByMakingARequestToECRIfTypeIsEcr() { GetAuthorizationTokenResult mockAuthorizationTokenResult = mock(GetAuthorizationTokenResult.class); AuthorizationData mockAuthorization = mock(AuthorizationData.class); List<AuthorizationData> authorizationData = new ArrayList<>(); authorizationData.add(mockAuthorization); final ArtifactStoreConfig artifactStoreConfig = new ArtifactStoreConfig("https://12345.dkr.ecr.region.amazonaws.com", "ecr", "awsAccessKeyId", "awsSecretAccessKey", "awsRegion"); String usernameAndPassword="AWS:secretAuthorizationToken"; when(mockAmazonEcrClient.getAuthorizationToken(any(GetAuthorizationTokenRequest.class))).thenReturn(mockAuthorizationTokenResult); when(mockAuthorizationTokenResult.getAuthorizationData()).thenReturn(authorizationData); when(mockAuthorization.getAuthorizationToken()).thenReturn(Base64.getEncoder().encodeToString(usernameAndPassword.getBytes())); final RegistryAuthSupplierChain registryAuthSupplierChain = new RegistryAuthSupplierChain(artifactStoreConfig, new AWSTokenRequestGenerator(new MockAwsECRClientBuilder(new ClientConfigurationFactory()))); final RegistryAuth registryAuth = registryAuthSupplierChain.authFor("foo"); assertThat(registryAuth.serverAddress()).isEqualTo(artifactStoreConfig.getRegistryUrl()); assertThat(registryAuth.username()).isEqualTo("AWS"); assertThat(registryAuth.password()).isEqualTo("secretAuthorizationToken"); }
Example #2
Source File: ECRLoginStep.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Override protected String run() throws Exception { AmazonECR ecr = AWSClientFactory.create(AmazonECRClientBuilder.standard(), this.getContext()); GetAuthorizationTokenRequest request = new GetAuthorizationTokenRequest(); List<String> registryIds; if((registryIds = this.step.getRegistryIds()) != null) { request.setRegistryIds(registryIds); } GetAuthorizationTokenResult token = ecr.getAuthorizationToken(request); if (token.getAuthorizationData().size() != 1) { throw new RuntimeException("Did not get authorizationData from AWS"); } AuthorizationData authorizationData = token.getAuthorizationData().get(0); byte[] bytes = org.apache.commons.codec.binary.Base64.decodeBase64(authorizationData.getAuthorizationToken()); String data = new String(bytes, Charsets.UTF_8); String[] parts = data.split(":"); if (parts.length != 2) { throw new RuntimeException("Got invalid authorizationData from AWS"); } String emailString = this.step.getEmail() ? "-e none" : ""; return String.format("docker login -u %s -p %s %s %s", parts[0], parts[1], emailString, authorizationData.getProxyEndpoint()); }
Example #3
Source File: AwsEcrAuthResolver.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@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; }