Skip to content
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

fix(apigatewayv2): defaultAuthorizer cannot be applied to HttpRoute #27576

Merged
merged 28 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
21785e2
docs(secretsmanager): doc when automaticallyAfter for RotationSchedul…
go-to-k Oct 17, 2023
de950c7
fix(apigatewayv2): can't apply defaultAuthorizer to HttpRoute
go-to-k Oct 17, 2023
1efb3d6
add an integ test
go-to-k Oct 17, 2023
1e10a0d
refactor for route.ts
go-to-k Oct 17, 2023
21e4aee
fix miss
go-to-k Oct 17, 2023
ebacc8e
change integ tests for circular dependency
go-to-k Oct 19, 2023
aa00748
tweak
go-to-k Oct 19, 2023
afb9bda
tweak
go-to-k Oct 19, 2023
df3155b
tweak
go-to-k Oct 19, 2023
9062e3a
add comments
go-to-k Oct 19, 2023
4fc75f4
apply defaultAuthorizationScopes
go-to-k Oct 19, 2023
5c2208f
change tests
go-to-k Oct 19, 2023
81bcb9c
change comments and an integ
go-to-k Oct 19, 2023
4e76464
change integ snapshots
go-to-k Oct 20, 2023
ae2a40c
add properties to IHttpApi
go-to-k Oct 23, 2023
2a76067
change integs
go-to-k Oct 23, 2023
5df276c
changed integ.lambda.ts
go-to-k Oct 23, 2023
e3e3f9e
change integ.user-pool
go-to-k Oct 23, 2023
afd941c
change integ.lambda.ts
go-to-k Oct 23, 2023
5f248aa
change integ.lambda
go-to-k Oct 23, 2023
4e5942f
change integ.lambda before modification
go-to-k Oct 23, 2023
0a188ee
change integs
go-to-k Oct 23, 2023
9e09c7c
change integ.user-pool
go-to-k Oct 23, 2023
40819a1
change align and docs
go-to-k Oct 24, 2023
ee11394
change integ.lambda
go-to-k Oct 24, 2023
7ea3c89
change message
go-to-k Oct 24, 2023
0bb478e
tweak for msgs
go-to-k Oct 24, 2023
375b130
Merge branch 'main' into fix/apgwv2-route-authorizer
mergify[bot] Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigatewayv2-alpha/lib/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class HttpApi extends HttpApiBase {

private readonly _apiEndpoint: string;

private readonly defaultAuthorizer?: IHttpRouteAuthorizer;
public readonly defaultAuthorizer?: IHttpRouteAuthorizer;
private readonly defaultAuthorizationScopes?: string[];

constructor(scope: Construct, id: string, props?: HttpApiProps) {
Expand Down
18 changes: 13 additions & 5 deletions packages/@aws-cdk/aws-apigatewayv2-alpha/lib/http/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as iam from 'aws-cdk-lib/aws-iam';
import { Aws, Resource } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { IHttpApi } from './api';
import { HttpApi, IHttpApi } from './api';
import { HttpRouteAuthorizerConfig, IHttpRouteAuthorizer } from './authorizer';
import { HttpRouteIntegration } from './integration';
import { CfnRoute, CfnRouteProps } from 'aws-cdk-lib/aws-apigatewayv2';
Expand Down Expand Up @@ -193,10 +193,18 @@ export class HttpRoute extends Resource implements IHttpRoute {
scope: this,
});

this.authBindResult = props.authorizer?.bind({
route: this,
scope: this.httpApi instanceof Construct ? this.httpApi : this, // scope under the API if it's not imported
});
this.authBindResult = props.authorizer
? props.authorizer.bind({
route: this,
scope: this.httpApi instanceof Construct ? this.httpApi : this, // scope under the API if it's not imported
})
: this.httpApi instanceof HttpApi
? this.httpApi.defaultAuthorizer?.bind({
route: this,
scope: this.httpApi,
})
: undefined;
;

if (this.authBindResult && !(this.authBindResult.authorizationType in HttpRouteAuthorizationType)) {
throw new Error(`authorizationType should either be AWS_IAM, JWT, CUSTOM, or NONE but was '${this.authBindResult.authorizationType}'`);
Expand Down
29 changes: 29 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2-alpha/test/http/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,35 @@ describe('HttpRoute', () => {
});
});

test('can create route without an authorizer when api has defaultAuthorizer', () => {
const stack = new Stack();

const authorizer = new DummyAuthorizer();
const httpApi = new HttpApi(stack, 'HttpApi', {
defaultAuthorizer: authorizer,
});

const route = new HttpRoute(stack, 'HttpRoute', {
httpApi,
integration: new DummyIntegration(),
routeKey: HttpRouteKey.with('/books', HttpMethod.GET),
});

Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Integration', {
ApiId: stack.resolve(httpApi.apiId),
IntegrationType: 'HTTP_PROXY',
PayloadFormatVersion: '2.0',
IntegrationUri: 'some-uri',
});

Template.fromStack(stack).resourceCountIs('AWS::ApiGatewayV2::Authorizer', 1);

Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Route', {
AuthorizerId: stack.resolve(authorizer.bind({ scope: stack, route: route }).authorizerId),
AuthorizationType: 'JWT',
});
});

test('can attach additional scopes to a route with an authorizer attached', () => {
const stack = new Stack();
const httpApi = new HttpApi(stack, 'HttpApi');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface RotationScheduleOptions {
* Specifies the number of days after the previous rotation before
* Secrets Manager triggers the next automatic rotation.
*
* A value of zero will disable automatic rotation - `Duration.days(0)`.
* A value of zero (`Duration.days(0)`) will not to create RotationRules.
*
* @default Duration.days(30)
*/
Expand Down
Loading