@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAuthorizationToken() == null) ? 0 : getAuthorizationToken().hashCode()); hashCode = prime * hashCode + ((getExpiresAt() == null) ? 0 : getExpiresAt().hashCode()); hashCode = prime * hashCode + ((getProxyEndpoint() == null) ? 0 : getProxyEndpoint().hashCode()); return hashCode; }
/** * <p> * A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the string * is decoded, it is presented in the format <code>user:password</code> for private registry authentication using * <code>docker login</code>. * </p> * * @param authorizationToken * A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the * string is decoded, it is presented in the format <code>user:password</code> for private registry * authentication using <code>docker login</code>. * @return Returns a reference to this object so that method calls can be chained together. */ public AuthorizationData withAuthorizationToken(String authorizationToken) { setAuthorizationToken(authorizationToken); return this; }
/** * <p> * The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are valid * for 12 hours. * </p> * * @param expiresAt * The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are * valid for 12 hours. * @return Returns a reference to this object so that method calls can be chained together. */ public AuthorizationData withExpiresAt(java.util.Date expiresAt) { setExpiresAt(expiresAt); return this; }
@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()); }
@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 AuthorizationData unmarshall(JsonUnmarshallerContext context) throws Exception { AuthorizationData authorizationData = new AuthorizationData(); if (context.testExpression("authorizationToken", targetDepth)) { context.nextToken(); authorizationData.setAuthorizationToken(context.getUnmarshaller(String.class).unmarshall(context)); authorizationData.setExpiresAt(DateJsonUnmarshallerFactory.getInstance("unixTimestamp").unmarshall(context)); authorizationData.setProxyEndpoint(context.getUnmarshaller(String.class).unmarshall(context));
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(); }
public AuthorizationData unmarshall(JsonUnmarshallerContext context) throws Exception { AuthorizationData authorizationData = new AuthorizationData(); if (context.testExpression("authorizationToken", targetDepth)) { context.nextToken(); authorizationData.setAuthorizationToken(context.getUnmarshaller(String.class).unmarshall(context)); authorizationData.setExpiresAt(DateJsonUnmarshallerFactory.getInstance("unixTimestamp").unmarshall(context)); authorizationData.setProxyEndpoint(context.getUnmarshaller(String.class).unmarshall(context));
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof AuthorizationData == false) return false; AuthorizationData other = (AuthorizationData) obj; if (other.getAuthorizationToken() == null ^ this.getAuthorizationToken() == null) return false; if (other.getAuthorizationToken() != null && other.getAuthorizationToken().equals(this.getAuthorizationToken()) == false) return false; if (other.getExpiresAt() == null ^ this.getExpiresAt() == null) return false; if (other.getExpiresAt() != null && other.getExpiresAt().equals(this.getExpiresAt()) == false) return false; if (other.getProxyEndpoint() == null ^ this.getProxyEndpoint() == null) return false; if (other.getProxyEndpoint() != null && other.getProxyEndpoint().equals(this.getProxyEndpoint()) == false) return false; return true; }
/** * <p> * The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are valid * for 12 hours. * </p> * * @param expiresAt * The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are * valid for 12 hours. * @return Returns a reference to this object so that method calls can be chained together. */ public AuthorizationData withExpiresAt(java.util.Date expiresAt) { setExpiresAt(expiresAt); return this; }
/** * <p> * A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the string * is decoded, it is presented in the format <code>user:password</code> for private registry authentication using * <code>docker login</code>. * </p> * * @param authorizationToken * A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the * string is decoded, it is presented in the format <code>user:password</code> for private registry * authentication using <code>docker login</code>. * @return Returns a reference to this object so that method calls can be chained together. */ public AuthorizationData withAuthorizationToken(String authorizationToken) { setAuthorizationToken(authorizationToken); 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 (getAuthorizationToken() != null) sb.append("AuthorizationToken: ").append(getAuthorizationToken()).append(","); if (getExpiresAt() != null) sb.append("ExpiresAt: ").append(getExpiresAt()).append(","); if (getProxyEndpoint() != null) sb.append("ProxyEndpoint: ").append(getProxyEndpoint()); sb.append("}"); return sb.toString(); }
/** * Marshall the given parameter object. */ public void marshall(AuthorizationData authorizationData, ProtocolMarshaller protocolMarshaller) { if (authorizationData == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(authorizationData.getAuthorizationToken(), AUTHORIZATIONTOKEN_BINDING); protocolMarshaller.marshall(authorizationData.getExpiresAt(), EXPIRESAT_BINDING); protocolMarshaller.marshall(authorizationData.getProxyEndpoint(), PROXYENDPOINT_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAuthorizationToken() == null) ? 0 : getAuthorizationToken().hashCode()); hashCode = prime * hashCode + ((getExpiresAt() == null) ? 0 : getExpiresAt().hashCode()); hashCode = prime * hashCode + ((getProxyEndpoint() == null) ? 0 : getProxyEndpoint().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof AuthorizationData == false) return false; AuthorizationData other = (AuthorizationData) obj; if (other.getAuthorizationToken() == null ^ this.getAuthorizationToken() == null) return false; if (other.getAuthorizationToken() != null && other.getAuthorizationToken().equals(this.getAuthorizationToken()) == false) return false; if (other.getExpiresAt() == null ^ this.getExpiresAt() == null) return false; if (other.getExpiresAt() != null && other.getExpiresAt().equals(this.getExpiresAt()) == false) return false; if (other.getProxyEndpoint() == null ^ this.getProxyEndpoint() == null) return false; if (other.getProxyEndpoint() != null && other.getProxyEndpoint().equals(this.getProxyEndpoint()) == 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 (getAuthorizationToken() != null) sb.append("AuthorizationToken: ").append(getAuthorizationToken()).append(","); if (getExpiresAt() != null) sb.append("ExpiresAt: ").append(getExpiresAt()).append(","); if (getProxyEndpoint() != null) sb.append("ProxyEndpoint: ").append(getProxyEndpoint()); sb.append("}"); return sb.toString(); }
/** * Marshall the given parameter object. */ public void marshall(AuthorizationData authorizationData, ProtocolMarshaller protocolMarshaller) { if (authorizationData == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(authorizationData.getAuthorizationToken(), AUTHORIZATIONTOKEN_BINDING); protocolMarshaller.marshall(authorizationData.getExpiresAt(), EXPIRESAT_BINDING); protocolMarshaller.marshall(authorizationData.getProxyEndpoint(), PROXYENDPOINT_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@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(); }