@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAuthorizationData() == null) ? 0 : getAuthorizationData().hashCode()); return hashCode; }
/** * <p> * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the request. * </p> * * @param authorizationData * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the * request. * @return Returns a reference to this object so that method calls can be chained together. */ public GetAuthorizationTokenResult withAuthorizationData(java.util.Collection<AuthorizationData> authorizationData) { setAuthorizationData(authorizationData); return this; }
@Nonnull @Override public Secret getPassword() { final AmazonWebServicesCredentials credentials = getCredentials(); if (credentials == null) throw new IllegalStateException("Invalid credentials"); LOG.log(Level.FINE,"Get Password for {0} region : {1}", new Object[]{credentials.getDisplayName(), region}); if(LOG.isLoggable(Level.ALL)){ String fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(new Throwable()); LOG.log(Level.ALL,"Trace : {0}", fullStackTrace); } com.amazonaws.AmazonECRClientFactory factory = new com.amazonaws.AmazonECRClientFactory(); final AmazonECRClient client = factory.getAmazonECRClientWithProxy(credentials.getCredentials()); client.setRegion(Region.getRegion(region)); GetAuthorizationTokenRequest request = new GetAuthorizationTokenRequest(); final GetAuthorizationTokenResult authorizationToken = client.getAuthorizationToken(request); final List<AuthorizationData> authorizationData = authorizationToken.getAuthorizationData(); if (authorizationData == null || authorizationData.isEmpty()) { throw new IllegalStateException("Failed to retrieve authorization token for Amazon ECR"); } LOG.fine("Success "); if(LOG.isLoggable(Level.ALL)){ LOG.finest("Auth token: " + authorizationToken.toString()); LOG.finest("Request: " + request.toString()); } return Secret.fromString(authorizationData.get(0).getAuthorizationToken()); }
public GetAuthorizationTokenResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetAuthorizationTokenResult getAuthorizationTokenResult = new GetAuthorizationTokenResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) { return getAuthorizationTokenResult; } while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("authorizationData", targetDepth)) { context.nextToken(); getAuthorizationTokenResult.setAuthorizationData(new ListUnmarshaller<AuthorizationData>(AuthorizationDataJsonUnmarshaller.getInstance()) .unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return getAuthorizationTokenResult; }
public GetAuthorizationTokenResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetAuthorizationTokenResult getAuthorizationTokenResult = new GetAuthorizationTokenResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) { return getAuthorizationTokenResult; } while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("authorizationData", targetDepth)) { context.nextToken(); getAuthorizationTokenResult.setAuthorizationData(new ListUnmarshaller<AuthorizationData>(AuthorizationDataJsonUnmarshaller.getInstance()) .unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return getAuthorizationTokenResult; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetAuthorizationTokenResult == false) return false; GetAuthorizationTokenResult other = (GetAuthorizationTokenResult) obj; if (other.getAuthorizationData() == null ^ this.getAuthorizationData() == null) return false; if (other.getAuthorizationData() != null && other.getAuthorizationData().equals(this.getAuthorizationData()) == false) return false; return true; }
/** * <p> * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the request. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setAuthorizationData(java.util.Collection)} or {@link #withAuthorizationData(java.util.Collection)} if * you want to override the existing values. * </p> * * @param authorizationData * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the * request. * @return Returns a reference to this object so that method calls can be chained together. */ public GetAuthorizationTokenResult withAuthorizationData(AuthorizationData... authorizationData) { if (this.authorizationData == null) { setAuthorizationData(new java.util.ArrayList<AuthorizationData>(authorizationData.length)); } for (AuthorizationData ele : authorizationData) { this.authorizationData.add(ele); } return this; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAuthorizationData() != null) sb.append("AuthorizationData: ").append(getAuthorizationData()); sb.append("}"); return sb.toString(); }
/** * <p> * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the request. * </p> * * @param authorizationData * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the * request. * @return Returns a reference to this object so that method calls can be chained together. */ public GetAuthorizationTokenResult withAuthorizationData(java.util.Collection<AuthorizationData> authorizationData) { setAuthorizationData(authorizationData); return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAuthorizationData() == null) ? 0 : getAuthorizationData().hashCode()); return hashCode; }
/** * <p> * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the request. * </p> * <p> * <b>NOTE:</b> This method appends the values to the existing list (if any). Use * {@link #setAuthorizationData(java.util.Collection)} or {@link #withAuthorizationData(java.util.Collection)} if * you want to override the existing values. * </p> * * @param authorizationData * A list of authorization token data objects that correspond to the <code>registryIds</code> values in the * request. * @return Returns a reference to this object so that method calls can be chained together. */ public GetAuthorizationTokenResult withAuthorizationData(AuthorizationData... authorizationData) { if (this.authorizationData == null) { setAuthorizationData(new java.util.ArrayList<AuthorizationData>(authorizationData.length)); } for (AuthorizationData ele : authorizationData) { this.authorizationData.add(ele); } return this; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof GetAuthorizationTokenResult == false) return false; GetAuthorizationTokenResult other = (GetAuthorizationTokenResult) obj; if (other.getAuthorizationData() == null ^ this.getAuthorizationData() == null) return false; if (other.getAuthorizationData() != null && other.getAuthorizationData().equals(this.getAuthorizationData()) == false) return false; return true; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAuthorizationData() != null) sb.append("AuthorizationData: ").append(getAuthorizationData()); sb.append("}"); return sb.toString(); }
@Override protected String run() throws Exception { AmazonECR ecr = AWSClientFactory.create(AmazonECRClientBuilder.standard(), this.getContext()); GetAuthorizationTokenResult token = ecr.getAuthorizationToken(new GetAuthorizationTokenRequest()); 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()); }
@TaskAction public void createRepository() { List<String> repositoryIds = getRepositoryIds(); if (repositoryIds == null || repositoryIds.isEmpty()) { throw new GradleException("Must specify ECR repositoryIds"); } AmazonECRPluginExtension ext = getProject().getExtensions().getByType(AmazonECRPluginExtension.class); AmazonECR ecr = ext.getClient(); GetAuthorizationTokenResult result = ecr.getAuthorizationToken(new GetAuthorizationTokenRequest() .withRegistryIds(repositoryIds)); authorizationData = result.getAuthorizationData(); } }
public AuthorizationToken getAuthorizationToken(String registryId) { List<AuthorizationData> authList = _awsEcrClient.getAuthorizationToken(new GetAuthorizationTokenRequest() .withRegistryIds(registryId)) .getAuthorizationData(); if ( null == authList || authList.isEmpty() ) return null; AuthorizationData data = authList.get(0); if ( null == data ) return null; return AuthorizationToken.builder() .token(data.getAuthorizationToken()) .endpoint(URI.create(data.getProxyEndpoint())) .build(); }
@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(); }