Skip to content

Commit c22e382

Browse files
pandheradavidh44
authored andcommitted
Addressing PR Comments
1 parent e488ba6 commit c22e382

File tree

8 files changed

+115
-46
lines changed

8 files changed

+115
-46
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AxdbFrontend",
4+
"contributor": "APandher",
5+
"description": "Add IAM Token Generation Utility for AxdbFrontend"
6+
}

docs/LaunchChangelog.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,6 @@ The S3 client in 2.0 is drastically different from the client in 1.11, because i
453453

454454
1. The class`RdsIamAuthTokenGenerator` has been replaced with `RdsUtilities#generateAuthenticationToken`.
455455

456-
## 4.5. Axdbfrontend Changes
457-
458-
1. The class `AxdbfrontendUtilities#generateAuthenticationToken` can now be used to generate an Authentication token to connect to a Xanadu database.
459-
460456
# 5. Profile File Changes
461457

462458
The parsing of the `~/.aws/config` and `~/.aws/credentials` has changed to more closely emulate that used by the AWS CLI.

services/axdbfrontend/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
</plugins>
4242
</build>
4343
<dependencies>
44+
<dependency>
45+
<groupId>nl.jqno.equalsverifier</groupId>
46+
<artifactId>equalsverifier</artifactId>
47+
<scope>test</scope>
48+
</dependency>
4449
<dependency>
4550
<groupId>software.amazon.awssdk</groupId>
4651
<artifactId>protocol-core</artifactId>

services/axdbfrontend/src/main/java/software/amazon/awssdk/services/axdbfrontend/AxdbFrontendUtilities.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,32 @@
2121
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
2222
import software.amazon.awssdk.identity.spi.IdentityProvider;
2323
import software.amazon.awssdk.regions.Region;
24+
import software.amazon.awssdk.services.axdbfrontend.internal.DefaultAxdbFrontendUtilities;
2425
import software.amazon.awssdk.services.axdbfrontend.model.GenerateAuthenticationTokenRequest;
2526

2627
/**
2728
* Utilities for working with AxdbFrontend. An instance of this class can be created by:
2829
* <p>
2930
* 1) Using the low-level client {@link AxdbFrontendClient#utilities()} (or {@link AxdbFrontendAsyncClient#utilities()}} method.
30-
* This is
31-
* recommended as SDK will use the same configuration from the {@link AxdbFrontendClient} object to create the
32-
* {@link AxdbFrontendUtilities}
33-
* object.
31+
* This is recommended as SDK will use the same configuration from the {@link AxdbFrontendClient} object to create the
32+
* {@link AxdbFrontendUtilities} object.
3433
*
35-
* <pre>
34+
* @snippet :
35+
* {@code
3636
* AxdbFrontendClient AxdbFrontendClient = AxdbFrontendClient.create();
3737
* AxdbFrontendUtilities utilities = AxdbFrontendClient.utilities();
38-
* </pre>
39-
* </p>
38+
* }
4039
*
4140
* <p>
4241
* 2) Directly using the {@link #builder()} method.
4342
*
44-
* <pre>
43+
* @snippet :
44+
* {@code
4545
* AxdbFrontendUtilities utilities = AxdbFrontendUtilities.builder()
4646
* .credentialsProvider(DefaultCredentialsProvider.create())
4747
* .region(Region.US_WEST_2)
4848
* .build()
49-
* </pre>
50-
* </p>
49+
* }
5150
*
5251
* Note: This class does not make network calls.
5352
*/
@@ -61,7 +60,7 @@ static Builder builder() {
6160
}
6261

6362
/**
64-
* Generates an authentication token for IAM authentication to a Xanadu database.
63+
* Generates an authentication token for IAM authentication to an AxdbFrontend database.
6564
*
6665
* @param request The request used to generate the authentication token
6766
* @return String to use as the AxdbFrontend authentication token
@@ -72,7 +71,7 @@ default String generateAuthenticationToken(Consumer<GenerateAuthenticationTokenR
7271
}
7372

7473
/**
75-
* Generates an authentication token for IAM authentication to an Xanadu database.
74+
* Generates an authentication token for IAM authentication to an AxdbFrontend database.
7675
*
7776
* @param request The request used to generate the authentication token
7877
* @return String to use as the AxdbFrontend authentication token
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.services.axdbfrontend;
16+
package software.amazon.awssdk.services.axdbfrontend.internal;
1717

1818
import java.time.Clock;
1919
import java.time.Instant;
@@ -30,28 +30,29 @@
3030
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
3131
import software.amazon.awssdk.identity.spi.IdentityProvider;
3232
import software.amazon.awssdk.regions.Region;
33+
import software.amazon.awssdk.services.axdbfrontend.AxdbFrontendUtilities;
3334
import software.amazon.awssdk.services.axdbfrontend.model.GenerateAuthenticationTokenRequest;
3435
import software.amazon.awssdk.utils.CompletableFutureUtils;
3536
import software.amazon.awssdk.utils.Logger;
3637
import software.amazon.awssdk.utils.StringUtils;
3738

3839
@Immutable
3940
@SdkInternalApi
40-
final class DefaultAxdbFrontendUtilities implements AxdbFrontendUtilities {
41+
public final class DefaultAxdbFrontendUtilities implements AxdbFrontendUtilities {
4142
private static final Logger log = Logger.loggerFor(AxdbFrontendUtilities.class);
4243
private final Aws4Signer signer = Aws4Signer.create();
4344
private final Region region;
4445
private final IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider;
4546
private final Clock clock;
4647

47-
DefaultAxdbFrontendUtilities(DefaultBuilder builder) {
48+
public DefaultAxdbFrontendUtilities(DefaultBuilder builder) {
4849
this(builder, Clock.systemUTC());
4950
}
5051

5152
/**
5253
* For testing purposes only
5354
*/
54-
DefaultAxdbFrontendUtilities(DefaultBuilder builder, Clock clock) {
55+
public DefaultAxdbFrontendUtilities(DefaultBuilder builder, Clock clock) {
5556
this.credentialsProvider = builder.credentialsProvider;
5657
this.region = builder.region;
5758
this.clock = clock;
@@ -72,7 +73,7 @@ public String generateAuthenticationToken(GenerateAuthenticationTokenRequest req
7273
.protocol("https")
7374
.host(request.hostname())
7475
.encodedPath("/")
75-
.putRawQueryParameter("Action", request.action().name())
76+
.putRawQueryParameter("Action", request.action().getAction())
7677
.build();
7778

7879
Instant expirationTime = Instant.now(clock).plus(request.expiresIn());
@@ -105,6 +106,7 @@ private Region resolveRegion(GenerateAuthenticationTokenRequest request) {
105106
"or AxdbFrontendUtilities object");
106107
}
107108

109+
// TODO: update this to use AwsCredentialsIdentity when we migrate Signers to accept the new type.
108110
private AwsCredentials resolveCredentials(GenerateAuthenticationTokenRequest request) {
109111
if (request.credentialsIdentityProvider() != null) {
110112
return CredentialUtils.toCredentials(
@@ -120,11 +122,11 @@ private AwsCredentials resolveCredentials(GenerateAuthenticationTokenRequest req
120122
}
121123

122124
@SdkInternalApi
123-
static final class DefaultBuilder implements Builder {
125+
public static final class DefaultBuilder implements Builder {
124126
private Region region;
125127
private IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider;
126128

127-
DefaultBuilder() {
129+
public DefaultBuilder() {
128130
}
129131

130132
Builder clientConfiguration(SdkClientConfiguration clientConfiguration) {

services/axdbfrontend/src/main/java/software/amazon/awssdk/services/axdbfrontend/model/Action.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,32 @@
1616
package software.amazon.awssdk.services.axdbfrontend.model;
1717

1818
import java.io.Serializable;
19+
import software.amazon.awssdk.annotations.SdkPublicApi;
1920

2021
/**
21-
* Enumerations of possible actions that can be performed on a Xanadu database.
22+
* Enumerations of possible actions that can be performed on an AxdbFrontend database.
2223
*/
24+
@SdkPublicApi
2325
public enum Action implements Serializable {
24-
DbConnect,
25-
DbConnectSuperuser;
26+
DB_CONNECT("DbConnect"),
27+
DB_CONNECT_SUPERUSER("DbConnectSuperuser");
28+
29+
private final String action;
30+
31+
Action(String action) {
32+
this.action = action;
33+
}
34+
35+
public String getAction() {
36+
return action;
37+
}
2638

2739
public static Action variant(String value) {
28-
if (value.equalsIgnoreCase(Action.DbConnect.name())) {
29-
return Action.DbConnect;
30-
} else if (value.equalsIgnoreCase(Action.DbConnectSuperuser.name())) {
31-
return Action.DbConnectSuperuser;
32-
} else {
33-
throw new IllegalArgumentException("Invalid action: " + value);
40+
for (Action action : Action.values()) {
41+
if (value.equalsIgnoreCase(action.name())) {
42+
return action;
43+
}
3444
}
45+
throw new IllegalArgumentException("Invalid action: " + value);
3546
}
3647
}

services/axdbfrontend/src/main/java/software/amazon/awssdk/services/axdbfrontend/model/GenerateAuthenticationTokenRequest.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.services.axdbfrontend.model;
1717

1818
import java.time.Duration;
19+
import java.util.Objects;
1920
import software.amazon.awssdk.annotations.NotThreadSafe;
2021
import software.amazon.awssdk.annotations.SdkPublicApi;
2122
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
@@ -25,6 +26,7 @@
2526
import software.amazon.awssdk.regions.Region;
2627
import software.amazon.awssdk.services.axdbfrontend.AxdbFrontendUtilities;
2728
import software.amazon.awssdk.services.axdbfrontend.model.Action;
29+
import software.amazon.awssdk.utils.ToString;
2830
import software.amazon.awssdk.utils.Validate;
2931
import software.amazon.awssdk.utils.builder.CopyableBuilder;
3032
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
@@ -37,6 +39,8 @@
3739
public final class GenerateAuthenticationTokenRequest implements
3840
ToCopyableBuilder<GenerateAuthenticationTokenRequest.Builder,
3941
GenerateAuthenticationTokenRequest> {
42+
// The time the IAM token is good for based on RDS. https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html
43+
private static final Duration EXPIRATION_DURATION = Duration.ofSeconds(900L);
4044

4145
private final String hostname;
4246
private final Region region;
@@ -47,11 +51,49 @@ public final class GenerateAuthenticationTokenRequest implements
4751
private GenerateAuthenticationTokenRequest(BuilderImpl builder) {
4852
this.hostname = Validate.notEmpty(builder.hostname, "hostname");
4953
this.action = Validate.notNull(builder.action, "action");
50-
Validate.isTrue(this.action == Action.DbConnect || this.action == Action.DbConnectSuperuser, "invalid action");
54+
Validate.isTrue(this.action == Action.DB_CONNECT || this.action == Action.DB_CONNECT_SUPERUSER, "invalid action");
5155
this.region = builder.region;
5256
this.credentialsProvider = builder.credentialsProvider;
5357
this.expiresIn = (builder.expiresIn != null) ? builder.expiresIn :
54-
Duration.ofSeconds(900L);
58+
EXPIRATION_DURATION;
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return ToString.builder("GenerateAuthenticationTokenRequest")
64+
.add("hostname", hostname)
65+
.add("region", region)
66+
.add("action", action)
67+
.add("expiresIn", expiresIn)
68+
.add("credentialsProvider", credentialsProvider)
69+
.build();
70+
}
71+
72+
@Override
73+
public boolean equals(Object o) {
74+
if (this == o) {
75+
return true;
76+
}
77+
if (o == null || getClass() != o.getClass()) {
78+
return false;
79+
}
80+
GenerateAuthenticationTokenRequest that = (GenerateAuthenticationTokenRequest) o;
81+
return Objects.equals(hostname, that.hostname) &&
82+
Objects.equals(region, that.region) &&
83+
Objects.equals(action, that.action) &&
84+
Objects.equals(expiresIn, that.expiresIn) &&
85+
Objects.equals(credentialsProvider, that.credentialsProvider);
86+
}
87+
88+
@Override
89+
public int hashCode() {
90+
int hashCode = 1;
91+
hashCode = 31 * hashCode + Objects.hashCode(hostname);
92+
hashCode = 31 * hashCode + Objects.hashCode(region);
93+
hashCode = 31 * hashCode + Objects.hashCode(action);
94+
hashCode = 31 * hashCode + Objects.hashCode(expiresIn);
95+
hashCode = 31 * hashCode + Objects.hashCode(credentialsProvider);
96+
return hashCode;
5597
}
5698

5799
/**
@@ -62,7 +104,7 @@ public String hostname() {
62104
}
63105

64106
/**
65-
* @return The token expiry duration in seconds
107+
* @return The token expiry duration
66108
*/
67109
public Duration expiresIn() {
68110
return expiresIn;
@@ -141,8 +183,7 @@ public interface Builder extends CopyableBuilder<Builder, GenerateAuthentication
141183
Builder region(Region region);
142184

143185
/**
144-
* The region the database is hosted in. If specified, takes precedence over the value specified in
145-
* {@link AxdbFrontendUtilities.Builder#region(Region)}
186+
* The duration a token is valid for.
146187
*
147188
* @return This object for method chaining
148189
*/

0 commit comments

Comments
 (0)