Skip to content

Commit

Permalink
fix(apigateway): allow overriding authorizer on methods (#30415)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

Closes #8827.

### Reason for this change

Customers could not override the authorizer defined in the default method configuration if they want to set the authorization type to None.

### Description of changes

If the customer set the authorization type to None while creating a new method, we will not use the authorizer value defined in the default configuration and instead we will set it to undefined.

### Description of how you validated changes

added unit, and integration test cases.

### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
moelasmar committed Jun 1, 2024
1 parent 09098af commit 1b8d73c
Show file tree
Hide file tree
Showing 11 changed files with 1,125 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"Resources": {
"UserPool6BA7E5F2": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"AccountRecoverySetting": {
"RecoveryMechanisms": [
{
"Name": "verified_phone_number",
"Priority": 1
},
{
"Name": "verified_email",
"Priority": 2
}
]
},
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": false
},
"AutoVerifiedAttributes": [
"email"
],
"EmailVerificationMessage": "The verification code to your new account is {####}",
"EmailVerificationSubject": "Verify your new account",
"SmsVerificationMessage": "The verification code to your new account is {####}",
"UsernameAttributes": [
"email"
],
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_CODE",
"EmailMessage": "The verification code to your new account is {####}",
"EmailSubject": "Verify your new account",
"SmsMessage": "The verification code to your new account is {####}"
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"AuthorizerBD825682": {
"Type": "AWS::ApiGateway::Authorizer",
"Properties": {
"IdentitySource": "method.request.header.Authorization",
"Name": "integtestrestapiwithoverridingdefaultauthorizerAuthorizerF0743170",
"ProviderARNs": [
{
"Fn::GetAtt": [
"UserPool6BA7E5F2",
"Arn"
]
}
],
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
},
"Type": "COGNITO_USER_POOLS"
}
},
"ActionsApiGatewayF80386B7": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "Actions-ApiGateway"
}
},
"ActionsApiGatewayDeployment50B6E6A66403e42852ae63ad13a2b7635300f8a9": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "Automatically created by the RestApi construct",
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
}
},
"DependsOn": [
"ActionsApiGatewayANY11FE5E47",
"ActionsApiGatewayGET12E87C75",
"ActionsApiGatewayOPTIONS8EA1F997",
"AuthorizerBD825682"
]
},
"ActionsApiGatewayDeploymentStageprod812022BF": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ActionsApiGatewayDeployment50B6E6A66403e42852ae63ad13a2b7635300f8a9"
},
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
},
"StageName": "prod"
}
},
"ActionsApiGatewayOPTIONS8EA1F997": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"ApiKeyRequired": false,
"AuthorizationType": "NONE",
"HttpMethod": "OPTIONS",
"Integration": {
"IntegrationResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'",
"method.response.header.Access-Control-Allow-Origin": "'*'",
"method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD'",
"method.response.header.Access-Control-Max-Age": "'864000'"
},
"StatusCode": "204"
}
],
"RequestTemplates": {
"application/json": "{ statusCode: 200 }"
},
"Type": "MOCK"
},
"MethodResponses": [
{
"ResponseParameters": {
"method.response.header.Access-Control-Allow-Headers": true,
"method.response.header.Access-Control-Allow-Origin": true,
"method.response.header.Access-Control-Allow-Methods": true,
"method.response.header.Access-Control-Max-Age": true
},
"StatusCode": "204"
}
],
"ResourceId": {
"Fn::GetAtt": [
"ActionsApiGatewayF80386B7",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
}
}
},
"ActionsApiGatewayANY11FE5E47": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
"HttpMethod": "ANY",
"Integration": {
"IntegrationResponses": [
{
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": "{ \"statusCode\": 200 }"
},
"Type": "MOCK"
},
"MethodResponses": [
{
"StatusCode": "200"
}
],
"ResourceId": {
"Fn::GetAtt": [
"ActionsApiGatewayF80386B7",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
}
}
},
"ActionsApiGatewayGET12E87C75": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationScopes": [
"scope"
],
"AuthorizationType": "COGNITO_USER_POOLS",
"AuthorizerId": {
"Ref": "AuthorizerBD825682"
},
"HttpMethod": "GET",
"Integration": {
"IntegrationResponses": [
{
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": "{ \"statusCode\": 200 }"
},
"Type": "MOCK"
},
"MethodResponses": [
{
"StatusCode": "200"
}
],
"ResourceId": {
"Fn::GetAtt": [
"ActionsApiGatewayF80386B7",
"RootResourceId"
]
},
"RestApiId": {
"Ref": "ActionsApiGatewayF80386B7"
}
}
}
},
"Outputs": {
"ActionsApiGatewayEndpoint261B645B": {
"Value": {
"Fn::Join": [
"",
[
"https://",
{
"Ref": "ActionsApiGatewayF80386B7"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".",
{
"Ref": "AWS::URLSuffix"
},
"/",
{
"Ref": "ActionsApiGatewayDeploymentStageprod812022BF"
},
"/"
]
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

0 comments on commit 1b8d73c

Please sign in to comment.