forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apigateway): lambda request authorizer (aws#5642)
This creates a common LambdaAuthorizer base class so that the token and request authorizers can share common functionality. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* <!-- Please read the contribution guidelines and follow the pull-request checklist: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md -->
- Loading branch information
1 parent
9d11c4e
commit 031932d
Showing
18 changed files
with
878 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ pack/ | |
.tools/ | ||
coverage/ | ||
.nyc_output | ||
.nycrc | ||
.LAST_BUILD | ||
*.sw[a-z] | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/@aws-cdk/aws-apigateway/lib/authorizers/identity-source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Represents an identity source. | ||
* | ||
* The source can be specified either as a literal value (e.g: `Auth`) which | ||
* cannot be blank, or as an unresolved string token. | ||
*/ | ||
export class IdentitySource { | ||
/** | ||
* Provides a properly formatted header identity source. | ||
* @param headerName the name of the header the `IdentitySource` will represent. | ||
* | ||
* @returns a header identity source. | ||
*/ | ||
public static header(headerName: string): string { | ||
return IdentitySource.toString(headerName, 'method.request.header'); | ||
} | ||
|
||
/** | ||
* Provides a properly formatted query string identity source. | ||
* @param queryString the name of the query string the `IdentitySource` will represent. | ||
* | ||
* @returns a query string identity source. | ||
*/ | ||
public static queryString(queryString: string): string { | ||
return IdentitySource.toString(queryString, 'method.request.querystring'); | ||
} | ||
|
||
/** | ||
* Provides a properly formatted API Gateway stage variable identity source. | ||
* @param stageVariable the name of the stage variable the `IdentitySource` will represent. | ||
* | ||
* @returns an API Gateway stage variable identity source. | ||
*/ | ||
public static stageVariable(stageVariable: string): string { | ||
return IdentitySource.toString(stageVariable, 'stageVariables'); | ||
} | ||
|
||
/** | ||
* Provides a properly formatted request context identity source. | ||
* @param context the name of the context variable the `IdentitySource` will represent. | ||
* | ||
* @returns a request context identity source. | ||
*/ | ||
public static context(context: string): string { | ||
return IdentitySource.toString(context, 'context'); | ||
} | ||
|
||
private static toString(source: string, type: string) { | ||
if (!source.trim()) { | ||
throw new Error(`IdentitySources must be a non-empty string.`); | ||
} | ||
|
||
return `${type}.${source}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './lambda'; | ||
export * from './lambda'; | ||
export * from './identity-source'; |
Oops, something went wrong.