Skip to content

Commit

Permalink
Merge branch 'release/1.5.2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Ionita committed Nov 14, 2020
2 parents f583e46 + c4d1b22 commit 21e4916
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-api-gateway-caching",
"version": "1.5.1",
"version": "1.5.2",
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.",
"main": "src/apiGatewayCachingPlugin.js",
"scripts": {
Expand Down
74 changes: 74 additions & 0 deletions src/apiGatewayCachingPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ApiGatewayCachingPlugin {
'before:package:finalize': this.updateCloudFormationTemplate.bind(this),
'after:aws:deploy:finalize:cleanup': this.updateStage.bind(this),
};

this.defineValidationSchema(serverless);
}

createSettings() {
Expand Down Expand Up @@ -51,6 +53,78 @@ class ApiGatewayCachingPlugin {

return updateStageCacheSettings(this.settings, this.serverless);
}

defineValidationSchema() {
if (!this.serverless.configSchemaHandler
|| !this.serverless.configSchemaHandler.defineCustomProperties
|| !this.serverless.configSchemaHandler.defineFunctionEventProperties) {
return;
}

const customSchema = this.customCachingSchema();
this.serverless.configSchemaHandler.defineCustomProperties(customSchema);

const httpSchema = this.httpEventCachingSchema();
this.serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', httpSchema);
}

httpEventCachingSchema() {
return {
type: 'object',
properties: {
caching: {
properties: {
enabled: { type: 'boolean' },
ttlInSeconds: { type: 'number' },
dataEncrypted: { type: 'boolean' },
perKeyInvalidation: {
properties: {
requireAuthorization: { type: 'boolean' },
handleUnauthorizedRequests: {
type: 'string',
enum: ['Ignore', 'IgnoreWithWarning', 'Fail']
}
}
},
cacheKeyParameters: {
type: 'array',
items: {
properties: {
name: { type: 'string' },
value: { type: 'string' }
}
}
}
}
}
}
}
}

customCachingSchema() {
return {
type: 'object',
properties: {
apiGatewayCaching: {
properties: {
enabled: { type: 'boolean' },
clusterSize: { type: 'string' },
ttlInSeconds: { type: 'number' },
dataEncrypted: { type: 'boolean' },
perKeyInvalidation: {
properties: {
requireAuthorization: { type: 'boolean' },
handleUnauthorizedRequests: {
type: 'string',
enum: ['Ignore', 'IgnoreWithWarning', 'Fail']
}
}
}
}
}
}
}
}
}

module.exports = ApiGatewayCachingPlugin;

0 comments on commit 21e4916

Please sign in to comment.