com.amazonaws.services.ecr.model.GetAuthorizationTokenRequest Java Examples
The following examples show how to use
com.amazonaws.services.ecr.model.GetAuthorizationTokenRequest.
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; }
Example #4
Source File: AWSTokenRequestGenerator.java From docker-registry-artifact-plugin with Apache License 2.0 | 5 votes |
String[] getUsernameAndPasswordFromECRToken(ArtifactStoreConfig artifactStoreConfig) { builder.setRegion(artifactStoreConfig.getAwsRegion()); setCredentialsProvider(artifactStoreConfig); GetAuthorizationTokenResult authorizationTokenResult = builder.build().getAuthorizationToken(new GetAuthorizationTokenRequest().withRegistryIds(artifactStoreConfig.getRegistryId())); String authorizationToken = authorizationTokenResult.getAuthorizationData().get(0).getAuthorizationToken(); return new String(Base64.getDecoder().decode(authorizationToken)).split(":"); }
Example #5
Source File: AwsEcrAuthorizer.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public HttpHeaders getAuthorizationHeaders(ContainerImage containerImage, RegistryConfiguration registryConfiguration) { Assert.isTrue(registryConfiguration.getAuthorizationType() == this.getType(), "Incorrect type: " + registryConfiguration.getAuthorizationType()); AmazonECRClientBuilder ecrBuilder = AmazonECRClientBuilder.standard(); if (registryConfiguration.getExtra().containsKey(AWS_REGION)) { ecrBuilder.withRegion(registryConfiguration.getExtra().get(AWS_REGION)); } if (StringUtils.hasText(registryConfiguration.getUser()) && StringUtils.hasText(registryConfiguration.getSecret())) { // Expects that the 'user' == 'Access Key ID' and 'secret' == 'Secret Access Key' ecrBuilder.withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials(registryConfiguration.getUser(), registryConfiguration.getSecret()))); } AmazonECR client = ecrBuilder.build(); GetAuthorizationTokenRequest request = new GetAuthorizationTokenRequest(); if (registryConfiguration.getExtra().containsKey(REGISTRY_IDS)) { request.withRegistryIds(registryConfiguration.getExtra().get(REGISTRY_IDS).split(",")); } GetAuthorizationTokenResult response = client.getAuthorizationToken(request); String token = response.getAuthorizationData().iterator().next().getAuthorizationToken(); final HttpHeaders headers = new HttpHeaders(); headers.setBasicAuth(token); return headers; }