-
Notifications
You must be signed in to change notification settings - Fork 866
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
Override RegionSet in EnpointResolverInterceptor after fetching the Signing Properties from Endpoint rules #5825
base: feature/master/multi-auth-sigv4a
Are you sure you want to change the base?
Changes from 4 commits
082a218
81cca37
5953fdf
94f3951
9bd5a75
e517fc4
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 |
---|---|---|
|
@@ -99,6 +99,7 @@ public class EndpointResolverInterceptorSpec implements ClassSpec { | |
private final JmesPathAcceptorGenerator jmesPathGenerator; | ||
private final boolean dependsOnHttpAuthAws; | ||
private final boolean useSraAuth; | ||
private final boolean multiAuthSigv4a; | ||
|
||
|
||
public EndpointResolverInterceptorSpec(IntermediateModel model) { | ||
|
@@ -116,6 +117,7 @@ public EndpointResolverInterceptorSpec(IntermediateModel model) { | |
supportedAuthSchemes.contains(AwsV4aAuthScheme.class); | ||
|
||
this.useSraAuth = new AuthSchemeSpecUtils(model).useSraAuth(); | ||
this.multiAuthSigv4a = new AuthSchemeSpecUtils(model).usesSigV4a(); | ||
} | ||
|
||
@Override | ||
|
@@ -155,6 +157,10 @@ public TypeSpec poetSpec() { | |
b.addMethod(signerProviderMethod()); | ||
} | ||
|
||
if (multiAuthSigv4a) { | ||
b.addMethod(createHasRegionSetMethod()); | ||
b.addMethod(createUpdateAuthSchemeWithRegionSetMethod()); | ||
} | ||
endpointParamsKnowledgeIndex.addAccountIdMethodsIfPresent(b); | ||
return b.build(); | ||
} | ||
|
@@ -192,7 +198,9 @@ private MethodSpec modifyRequestMethod(String endpointAuthSchemeStrategyFieldNam | |
endpointRulesSpecUtils.providerInterfaceName(), providerVar, SdkInternalExecutionAttribute.class); | ||
b.beginControlFlow("try"); | ||
b.addStatement("long resolveEndpointStart = $T.nanoTime()", System.class); | ||
b.addStatement("$T endpoint = $N.resolveEndpoint(ruleParams(result, executionAttributes)).join()", | ||
b.addStatement("$T endpointParams = ruleParams(result, executionAttributes)", | ||
endpointRulesSpecUtils.parametersClassName()); | ||
b.addStatement("$T endpoint = $N.resolveEndpoint(endpointParams).join()", | ||
Endpoint.class, providerVar); | ||
b.addStatement("$1T resolveEndpointDuration = $1T.ofNanos($2T.nanoTime() - resolveEndpointStart)", Duration.class, | ||
System.class); | ||
|
@@ -219,7 +227,11 @@ private MethodSpec modifyRequestMethod(String endpointAuthSchemeStrategyFieldNam | |
SelectedAuthScheme.class, SdkInternalExecutionAttribute.class); | ||
b.beginControlFlow("if (endpointAuthSchemes != null && selectedAuthScheme != null)"); | ||
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. Is 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. Removed this check 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. My bad , we need this check , the S3 integ test failed , will revert this
|
||
b.addStatement("selectedAuthScheme = authSchemeWithEndpointSignerProperties(endpointAuthSchemes, selectedAuthScheme)"); | ||
|
||
if (multiAuthSigv4a) { | ||
b.beginControlFlow("if(!hasRegionSet(selectedAuthScheme))"); | ||
b.addStatement("selectedAuthScheme = updateAuthSchemeWithRegionSet(selectedAuthScheme, endpointParams)"); | ||
b.endControlFlow(); | ||
} | ||
b.addStatement("executionAttributes.putAttribute($T.SELECTED_AUTH_SCHEME, selectedAuthScheme)", | ||
SdkInternalExecutionAttribute.class); | ||
b.endControlFlow(); | ||
|
@@ -774,7 +786,7 @@ private static CodeBlock copyV4EndpointSignerPropertiesToAuth() { | |
return code.build(); | ||
} | ||
|
||
private static CodeBlock copyV4aEndpointSignerPropertiesToAuth() { | ||
private CodeBlock copyV4aEndpointSignerPropertiesToAuth() { | ||
CodeBlock.Builder code = CodeBlock.builder(); | ||
|
||
code.beginControlFlow("if (endpointAuthScheme instanceof $T)", SigV4aAuthScheme.class); | ||
|
@@ -784,10 +796,12 @@ private static CodeBlock copyV4aEndpointSignerPropertiesToAuth() { | |
code.addStatement("option.putSignerProperty($T.DOUBLE_URL_ENCODE, !v4aAuthScheme.disableDoubleEncoding())", | ||
AwsV4aHttpSigner.class); | ||
code.endControlFlow(); | ||
|
||
code.beginControlFlow("if (v4aAuthScheme.signingRegionSet() != null)"); | ||
if (multiAuthSigv4a) { | ||
code.beginControlFlow("if (!hasRegionSet(selectedAuthScheme) && v4aAuthScheme.signingRegionSet() != null)"); | ||
} else { | ||
code.beginControlFlow("if (v4aAuthScheme.signingRegionSet() != null)"); | ||
} | ||
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.
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. I have made |
||
code.addStatement("$1T regionSet = $1T.create(v4aAuthScheme.signingRegionSet())", RegionSet.class); | ||
|
||
code.addStatement("option.putSignerProperty($T.REGION_SET, regionSet)", AwsV4aHttpSigner.class); | ||
code.endControlFlow(); | ||
|
||
|
@@ -882,4 +896,51 @@ private MethodSpec constructorMethodSpec(String endpointAuthSchemeFieldName) { | |
return b.build(); | ||
} | ||
|
||
private MethodSpec createHasRegionSetMethod() { | ||
TypeVariableName tExtendsIdentity = TypeVariableName.get("T", Identity.class); | ||
TypeName selectedAuthSchemeOfT = ParameterizedTypeName.get(ClassName.get(SelectedAuthScheme.class), | ||
TypeVariableName.get("T")); | ||
|
||
return | ||
MethodSpec.methodBuilder("hasRegionSet") | ||
.addModifiers(Modifier.PRIVATE) | ||
.addTypeVariable(tExtendsIdentity) | ||
.returns(boolean.class) | ||
.addParameter(selectedAuthSchemeOfT, "selectedAuthScheme") | ||
.addCode( | ||
CodeBlock.builder() | ||
.addStatement("return selectedAuthScheme.authSchemeOption().schemeId().equals($T.SCHEME_ID)" | ||
+ " && selectedAuthScheme.authSchemeOption().signerProperty($T.REGION_SET) != " | ||
+ "null", AwsV4aAuthScheme.class, AwsV4aHttpSigner.class) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
private MethodSpec createUpdateAuthSchemeWithRegionSetMethod() { | ||
TypeVariableName tExtendsIdentity = TypeVariableName.get("T", Identity.class); | ||
TypeName selectedAuthSchemeOfT = ParameterizedTypeName.get( | ||
ClassName.get(SelectedAuthScheme.class), | ||
TypeVariableName.get("T") | ||
); | ||
|
||
return MethodSpec.methodBuilder("updateAuthSchemeWithRegionSet") | ||
.addModifiers(Modifier.PRIVATE) | ||
.addTypeVariable(tExtendsIdentity) | ||
.returns(selectedAuthSchemeOfT) | ||
.addParameter(selectedAuthSchemeOfT, "selectedAuthScheme") | ||
.addParameter(endpointRulesSpecUtils.parametersClassName(), "endpointParams") | ||
.addCode(CodeBlock.builder() | ||
.addStatement("$T optionBuilder = selectedAuthScheme.authSchemeOption().toBuilder()", | ||
ClassName.get(AuthSchemeOption.Builder.class)) | ||
.addStatement("$T regionSet = $T.create(endpointParams.region().id())", | ||
RegionSet.class, RegionSet.class) | ||
.addStatement("optionBuilder.putSignerProperty($T.REGION_SET, regionSet)", | ||
AwsV4aHttpSigner.class) | ||
.addStatement("return new $T<>(selectedAuthScheme.identity(), " + | ||
"selectedAuthScheme.signer(), optionBuilder.build())", | ||
SelectedAuthScheme.class) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"version": "1.2", | ||
"serviceId": "Database Service", | ||
"parameters": { | ||
"region": { | ||
"type": "string", | ||
"builtIn": "AWS::Region", | ||
"required": true, | ||
"documentation": "The region to send requests to" | ||
}, | ||
"useDualStackEndpoint": { | ||
"type": "boolean", | ||
"builtIn": "AWS::UseDualStack" | ||
}, | ||
"useFIPSEndpoint": { | ||
"type": "boolean", | ||
"builtIn": "AWS::UseFIPS" | ||
}, | ||
"AccountId": { | ||
"type": "String", | ||
"builtIn": "AWS::Auth::AccountId" | ||
}, | ||
"operationContextParam": { | ||
"type": "string" | ||
} | ||
}, | ||
"rules": [ | ||
{ | ||
"conditions": [ | ||
{ | ||
"fn": "aws.partition", | ||
"argv": [ | ||
{ | ||
"ref": "region" | ||
} | ||
], | ||
"assign": "partitionResult" | ||
} | ||
], | ||
"rules": [ | ||
{ | ||
"conditions": [ | ||
{ | ||
"fn": "isSet", | ||
"argv": [ | ||
{ | ||
"ref": "endpointId" | ||
} | ||
] | ||
} | ||
], | ||
"rules": [ | ||
{ | ||
"conditions": [ | ||
{ | ||
"fn": "isSet", | ||
"argv": [ | ||
{ | ||
"ref": "useFIPSEndpoint" | ||
} | ||
] | ||
} | ||
], | ||
"error": "FIPS endpoints not supported with multi-region endpoints", | ||
"type": "error" | ||
}, | ||
{ | ||
"endpoint": { | ||
"url": "https://{endpointId}.query.{partitionResult#dualStackDnsSuffix}", | ||
"properties": { | ||
"authSchemes": [ | ||
{ | ||
"name": "sigv4a", | ||
"signingName": "query", | ||
"signingRegionSet": ["*"] | ||
} | ||
] | ||
} | ||
}, | ||
"type": "endpoint" | ||
} | ||
], | ||
"type": "tree" | ||
} | ||
], | ||
"type": "tree" | ||
} | ||
] | ||
} | ||
|
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.
When can this be null?
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.
The specifications states
Thus for new services which will be completed based on multi-auth
signatureVersion
will be null.I added a test case for in codegen-tst when a new service is added with just multi-auth supporting only
sigv4a