Skip to content

Commit

Permalink
Use joinLikeSync instead of join (and TODO cleanup) (#4546)
Browse files Browse the repository at this point in the history
* Remove AuthorizationStrategy TODO for identity type

* Use joinLikeSync instead of join

* Remove TODO about making SelectedAuthScheme SdkPublicApi
  • Loading branch information
gosar authored Oct 4, 2023
1 parent b9bd9bf commit 6ef423f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
import software.amazon.awssdk.identity.spi.IdentityProvider;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.utils.CompletableFutureUtils;
import software.amazon.awssdk.utils.Pair;
import software.amazon.awssdk.utils.Validate;

Expand Down Expand Up @@ -82,8 +83,6 @@ public void addCredentialsToExecutionAttributes(ExecutionAttributes executionAtt
IdentityProvider<? extends AwsCredentialsIdentity> credentialsProvider =
resolveCredentialsProvider(request, defaultCredentialsProvider);
AwsCredentials credentials = CredentialUtils.toCredentials(resolveCredentials(credentialsProvider, metricCollector));
// TODO(sra-identity-and-auth): Should the signer be changed to use AwsCredentialsIdentity? Maybe with Signer SRA work,
// not now.
executionAttributes.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, credentials);
}

Expand All @@ -108,9 +107,9 @@ private static AwsCredentialsIdentity resolveCredentials(
MetricCollector metricCollector) {
Validate.notNull(credentialsProvider, "No credentials provider exists to resolve credentials from.");

// TODO(sra-identity-and-auth): Exception handling for join()?
// TODO(sra-identity-and-auth): internal issue SMITHY-1677. avoid join for async clients.
Pair<? extends AwsCredentialsIdentity, Duration> measured =
MetricUtils.measureDuration(() -> credentialsProvider.resolveIdentity().join());
MetricUtils.measureDuration(() -> CompletableFutureUtils.joinLikeSync(credentialsProvider.resolveIdentity()));

metricCollector.reportMetric(CoreMetric.CREDENTIALS_FETCH_DURATION, measured.right());
AwsCredentialsIdentity credentials = measured.left();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import software.amazon.awssdk.identity.spi.IdentityProvider;
import software.amazon.awssdk.identity.spi.TokenIdentity;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.utils.CompletableFutureUtils;
import software.amazon.awssdk.utils.Pair;
import software.amazon.awssdk.utils.Validate;

Expand Down Expand Up @@ -78,16 +79,16 @@ public Signer resolveSigner() {
@Override
public void addCredentialsToExecutionAttributes(ExecutionAttributes executionAttributes) {
SdkToken token = TokenUtils.toSdkToken(resolveToken(defaultTokenProvider, metricCollector));
// TODO(sra-identity-and-auth): Should the signer be changed to use TokenIdentity? Maybe with Signer SRA work, not now.
executionAttributes.putAttribute(SdkTokenExecutionAttribute.SDK_TOKEN, token);
}

private static TokenIdentity resolveToken(IdentityProvider<? extends TokenIdentity> tokenProvider,
MetricCollector metricCollector) {
Validate.notNull(tokenProvider, "No token provider exists to resolve a token from.");

// TODO(sra-identity-and-auth): Exception handling for join()?
Pair<TokenIdentity, Duration> measured = MetricUtils.measureDuration(() -> tokenProvider.resolveIdentity().join());
// TODO(sra-identity-and-auth): internal issue SMITHY-1677. avoid join for async clients.
Pair<TokenIdentity, Duration> measured =
MetricUtils.measureDuration(() -> CompletableFutureUtils.joinLikeSync(tokenProvider.resolveIdentity()));
metricCollector.reportMetric(CoreMetric.TOKEN_FETCH_DURATION, measured.right());
TokenIdentity token = measured.left();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

/**
* A container for the identity resolver, signer and auth option that we selected for use with this service call attempt.
*
* TODO(sra-identity-auth): Should this be made public? People might treat it as such anyway so that they can change the
* identity, signer or options from the interceptors. They're doing that already with the existing execution attributes.
*/
@SdkProtectedApi
public final class SelectedAuthScheme<T extends Identity> {
Expand Down

0 comments on commit 6ef423f

Please sign in to comment.