-
Notifications
You must be signed in to change notification settings - Fork 966
Add support for "derived" execution attributes. #4396
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
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 |
|---|---|---|
|
|
@@ -7,7 +7,12 @@ import software.amazon.awssdk.annotations.SdkProtectedApi; | |
| import software.amazon.awssdk.awscore.endpoints.authscheme.EndpointAuthScheme; | ||
| import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme; | ||
| import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme; | ||
| import software.amazon.awssdk.core.SelectedAuthScheme; | ||
| import software.amazon.awssdk.core.exception.SdkClientException; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
| import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; | ||
| import software.amazon.awssdk.http.auth.spi.AuthSchemeOption; | ||
| import software.amazon.awssdk.identity.spi.Identity; | ||
| import software.amazon.awssdk.utils.Logger; | ||
|
|
||
| @SdkProtectedApi | ||
|
|
@@ -50,56 +55,71 @@ public final class AuthSchemeUtils { | |
|
|
||
| String authSchemeName = scheme.get(Identifier.of("name")).expectString(); | ||
| switch (authSchemeName) { | ||
| case SIGV4A_NAME: { | ||
| SigV4aAuthScheme.Builder schemeBuilder = SigV4aAuthScheme.builder(); | ||
| case SIGV4A_NAME: { | ||
| SigV4aAuthScheme.Builder schemeBuilder = SigV4aAuthScheme.builder(); | ||
|
|
||
| Value signingName = scheme.get(Identifier.of("signingName")); | ||
| if (signingName != null) { | ||
| schemeBuilder.signingName(signingName.expectString()); | ||
| } | ||
|
|
||
| Value signingRegionSet = scheme.get(Identifier.of("signingRegionSet")); | ||
| if (signingRegionSet != null) { | ||
| Value.Array signingRegionSetArray = signingRegionSet.expectArray(); | ||
| for (int j = 0; j < signingRegionSetArray.size(); ++j) { | ||
| schemeBuilder.addSigningRegion(signingRegionSetArray.get(j).expectString()); | ||
| } | ||
| } | ||
| Value signingName = scheme.get(Identifier.of("signingName")); | ||
| if (signingName != null) { | ||
| schemeBuilder.signingName(signingName.expectString()); | ||
| } | ||
|
|
||
| Value disableDoubleEncoding = scheme.get(Identifier.of("disableDoubleEncoding")); | ||
| if (disableDoubleEncoding != null) { | ||
| schemeBuilder.disableDoubleEncoding(disableDoubleEncoding.expectBool()); | ||
| Value signingRegionSet = scheme.get(Identifier.of("signingRegionSet")); | ||
| if (signingRegionSet != null) { | ||
| Value.Array signingRegionSetArray = signingRegionSet.expectArray(); | ||
| for (int j = 0; j < signingRegionSetArray.size(); ++j) { | ||
| schemeBuilder.addSigningRegion(signingRegionSetArray.get(j).expectString()); | ||
| } | ||
| } | ||
|
|
||
| authSchemes.add(schemeBuilder.build()); | ||
| Value disableDoubleEncoding = scheme.get(Identifier.of("disableDoubleEncoding")); | ||
| if (disableDoubleEncoding != null) { | ||
| schemeBuilder.disableDoubleEncoding(disableDoubleEncoding.expectBool()); | ||
| } | ||
| break; | ||
| case SIGV4_NAME: { | ||
| SigV4AuthScheme.Builder schemeBuilder = SigV4AuthScheme.builder(); | ||
|
|
||
| Value signingName = scheme.get(Identifier.of("signingName")); | ||
| if (signingName != null) { | ||
| schemeBuilder.signingName(signingName.expectString()); | ||
| } | ||
| authSchemes.add(schemeBuilder.build()); | ||
| } | ||
| break; | ||
| case SIGV4_NAME: { | ||
| SigV4AuthScheme.Builder schemeBuilder = SigV4AuthScheme.builder(); | ||
|
|
||
| Value signingRegion = scheme.get(Identifier.of("signingRegion")); | ||
| if (signingRegion != null) { | ||
| schemeBuilder.signingRegion(signingRegion.expectString()); | ||
| } | ||
| Value signingName = scheme.get(Identifier.of("signingName")); | ||
| if (signingName != null) { | ||
| schemeBuilder.signingName(signingName.expectString()); | ||
| } | ||
|
|
||
| Value disableDoubleEncoding = scheme.get(Identifier.of("disableDoubleEncoding")); | ||
| if (disableDoubleEncoding != null) { | ||
| schemeBuilder.disableDoubleEncoding(disableDoubleEncoding.expectBool()); | ||
| } | ||
| Value signingRegion = scheme.get(Identifier.of("signingRegion")); | ||
| if (signingRegion != null) { | ||
| schemeBuilder.signingRegion(signingRegion.expectString()); | ||
| } | ||
|
|
||
| authSchemes.add(schemeBuilder.build()); | ||
| Value disableDoubleEncoding = scheme.get(Identifier.of("disableDoubleEncoding")); | ||
| if (disableDoubleEncoding != null) { | ||
| schemeBuilder.disableDoubleEncoding(disableDoubleEncoding.expectBool()); | ||
| } | ||
|
|
||
| authSchemes.add(schemeBuilder.build()); | ||
| } | ||
| break; | ||
| default: | ||
| LOG.debug(() -> "Ignoring unknown auth scheme: " + authSchemeName); | ||
| break; | ||
| default: | ||
| LOG.debug(() -> "Ignoring unknown auth scheme: " + authSchemeName); | ||
| break; | ||
| } | ||
| } | ||
| return authSchemes; | ||
| } | ||
|
|
||
| public static <T extends Identity> void putSelectedAuthScheme(ExecutionAttributes attributes, | ||
| SelectedAuthScheme<T> selectedAuthScheme) { | ||
| SelectedAuthScheme<?> existingAuthScheme = attributes.getAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME); | ||
| if (existingAuthScheme != null) { | ||
| AuthSchemeOption.Builder selectedOption = selectedAuthScheme.authSchemeOption().toBuilder(); | ||
| existingAuthScheme.authSchemeOption().forEachIdentityProperty(selectedOption::putIdentityPropertyIfAbsent); | ||
| existingAuthScheme.authSchemeOption().forEachSignerProperty(selectedOption::putSignerPropertyIfAbsent); | ||
gosar marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+116
to
+117
Contributor
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. the putIfAbsent here means if the selectedAuthScheme overwrites the existingAuthScheme's values - this seems fine. IIUC, the only case where existingAuthScheme would be non-null when it reaches this code path would be for attributes set here before calling the AuthSchemeInterceptor (which calls this AuthSchemeUtils) few lines later here. Though makes me wonder if this method should have comments on appropriate use and prevent it getting used in some other context. Not a big deal I think, though probably another reason to move this method inside AuthSchemeInterceptor. |
||
| selectedAuthScheme = new SelectedAuthScheme<>(selectedAuthScheme.identity(), | ||
| selectedAuthScheme.signer(), | ||
| selectedOption.build()); | ||
| } | ||
|
|
||
| attributes.putAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME, selectedAuthScheme); | ||
| } | ||
| } | ||
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.
This method is unrelated to endpoint rules, but I guess it is convenient to put this method in endpoint rules related utils class; instead of a new one or generate it in AuthSchemeInterceptorSpec itself.