-
Notifications
You must be signed in to change notification settings - Fork 916
Adds accountId to STS credentials providers #4040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d9a4675
23a9f8b
c341bc7
cfb4013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
|
||
package software.amazon.awssdk.auth.credentials; | ||
|
||
import java.time.Instant; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import software.amazon.awssdk.annotations.Immutable; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.identity.spi.AwsSessionCredentialsIdentity; | ||
|
@@ -34,11 +36,19 @@ public final class AwsSessionCredentials implements AwsCredentials, AwsSessionCr | |
private final String accessKeyId; | ||
private final String secretAccessKey; | ||
private final String sessionToken; | ||
private final String accountId; | ||
private final Instant expiration; | ||
|
||
private AwsSessionCredentials(String accessKey, String secretKey, String sessionToken) { | ||
this.accessKeyId = Validate.paramNotNull(accessKey, "accessKey"); | ||
this.secretAccessKey = Validate.paramNotNull(secretKey, "secretKey"); | ||
this.sessionToken = Validate.paramNotNull(sessionToken, "sessionToken"); | ||
private AwsSessionCredentials(Builder builder) { | ||
this.accessKeyId = Validate.paramNotNull(builder.accessKeyId, "accessKey"); | ||
this.secretAccessKey = Validate.paramNotNull(builder.secretAccessKey, "secretKey"); | ||
this.sessionToken = Validate.paramNotNull(builder.sessionToken, "sessionToken"); | ||
this.accountId = builder.accountId; | ||
this.expiration = builder.expiration; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** | ||
|
@@ -50,7 +60,7 @@ private AwsSessionCredentials(String accessKey, String secretKey, String session | |
* received temporary permission to access some resource. | ||
*/ | ||
public static AwsSessionCredentials create(String accessKey, String secretKey, String sessionToken) { | ||
return new AwsSessionCredentials(accessKey, secretKey, sessionToken); | ||
return builder().accessKeyId(accessKey).secretAccessKey(secretKey).sessionToken(sessionToken).build(); | ||
} | ||
|
||
@Override | ||
|
@@ -68,10 +78,20 @@ public String sessionToken() { | |
return sessionToken; | ||
} | ||
|
||
@Override | ||
public Optional<String> accountId() { | ||
return Optional.ofNullable(accountId); | ||
} | ||
|
||
public Optional<Instant> expiration() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this makes sense to add to this interface, why not add it to AwsSessionCredentialsIdentity and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, the top |
||
return Optional.ofNullable(expiration); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("AwsSessionCredentials") | ||
.add("accessKeyId", accessKeyId()) | ||
.add("accountId", accountId) | ||
.build(); | ||
} | ||
|
||
|
@@ -87,7 +107,9 @@ public boolean equals(Object o) { | |
AwsSessionCredentials that = (AwsSessionCredentials) o; | ||
return Objects.equals(accessKeyId, that.accessKeyId) && | ||
Objects.equals(secretAccessKey, that.secretAccessKey) && | ||
Objects.equals(sessionToken, that.sessionToken); | ||
Objects.equals(sessionToken, that.sessionToken) && | ||
Objects.equals(accountId, that.accountId().orElse(null)) && | ||
Objects.equals(expiration, that.expiration().orElse(null)); | ||
} | ||
|
||
@Override | ||
|
@@ -96,6 +118,45 @@ public int hashCode() { | |
hashCode = 31 * hashCode + Objects.hashCode(accessKeyId()); | ||
hashCode = 31 * hashCode + Objects.hashCode(secretAccessKey()); | ||
hashCode = 31 * hashCode + Objects.hashCode(sessionToken()); | ||
hashCode = 31 * hashCode + Objects.hashCode(accountId); | ||
hashCode = 31 * hashCode + Objects.hashCode(expiration); | ||
return hashCode; | ||
} | ||
|
||
public static final class Builder { | ||
cenedhryn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private String accessKeyId; | ||
private String secretAccessKey; | ||
private String sessionToken; | ||
private String accountId; | ||
private Instant expiration; | ||
|
||
public Builder accessKeyId(String accessKeyId) { | ||
this.accessKeyId = accessKeyId; | ||
return this; | ||
} | ||
|
||
public Builder secretAccessKey(String secretAccessKey) { | ||
this.secretAccessKey = secretAccessKey; | ||
return this; | ||
} | ||
|
||
public Builder sessionToken(String sessionToken) { | ||
this.sessionToken = sessionToken; | ||
return this; | ||
} | ||
|
||
public Builder accountId(String accountId) { | ||
this.accountId = accountId; | ||
return this; | ||
} | ||
|
||
public Builder expiration(Instant expiration) { | ||
this.expiration = expiration; | ||
return this; | ||
} | ||
|
||
public AwsSessionCredentials build() { | ||
return new AwsSessionCredentials(this); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this can be
boolean
too.