Skip to content

Commit

Permalink
feat(action): Support disassociating the request validator.
Browse files Browse the repository at this point in the history
Introduced a new action named `disassociate` to delete
references from AWS::ApiGateway::Method to the
AWS::ApiGateway::RequestValidatorresources.
  • Loading branch information
jweyrich committed Dec 1, 2021
1 parent e1b27b0 commit 56f770a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
23 changes: 21 additions & 2 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Serverless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ declare namespace Serverless {
package: Serverless.Package
getAllFunctions(): string[]
custom?: {
serverlessPluginTypescript?: {
tsConfigFileLocation: string
'serverless-disable-request-validators'?: {
action: string
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface CfnResourcePair {
enum PluginAction {
// Disable the `body` and `parameters` validations directly in the validator resources.
DISABLE = 'disable',

// Delete references from AWS::ApiGateway::Method to the AWS::ApiGateway::RequestValidator resources.
DISASSOCIATE = 'disassociate',

// Delete the AWS::ApiGateway::RequestValidator resources and all their references.
DELETE = 'delete',
}
Expand Down Expand Up @@ -86,6 +90,11 @@ class Plugin {
validators.forEach((v) => this.disableValidator(v));
break;
}
case PluginAction.DISASSOCIATE:
{
validators.forEach((v) => this.disassociateValidator(v.name, resources));
break;
}
case PluginAction.DELETE:
{
validators.forEach((v) => this.deleteValidator(v.name, resources));
Expand All @@ -94,10 +103,14 @@ class Plugin {
}
}

deleteValidator(validatorRef: string, resources: Serverless.CfnResourceList) {
disassociateValidator(validatorRef: string, resources: Serverless.CfnResourceList) {
const methods = this.filterResourcesByType(resources, 'AWS::ApiGateway::Method');
this.log(`Found ${methods.length} method(s)`);
methods.forEach((m) => this.deleteValidatorRefFromMethod(validatorRef, m));
}

deleteValidator(validatorRef: string, resources: Serverless.CfnResourceList) {
this.disassociateValidator(validatorRef, resources);

const validator = resources[validatorRef];
if (!validator) {
Expand Down

0 comments on commit 56f770a

Please sign in to comment.