From 4fc7583ebe825728fca9168228f27c9d4aa5660a Mon Sep 17 00:00:00 2001 From: singh_m Date: Fri, 30 Aug 2019 11:58:22 +0800 Subject: [PATCH 1/2] refs #30 add support for X-Ray and full MethodSettings --- README.md | 28 ++++++++++++++++++++++++---- src/index.js | 15 +++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 58ab562..a3d363d 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,34 @@ custom: stageSettings: CacheClusterEnabled: true CacheClusterSize: '0.5' + TracingEnabled: Boolean Variables: foo: bar baz: xyzzy + # The MethodSettingsGlobal property type configures settings for all methods in a stage. + # Required + MethodSettingsGlobal: + CacheDataEncrypted: Boolean + CacheTtlInSeconds: Integer + CachingEnabled: Boolean + DataTraceEnabled: Boolean + HttpMethod: String + LoggingLevel: String + MetricsEnabled: Boolean + ResourcePath: String + ThrottlingBurstLimit: Integer + ThrottlingRateLimit: Double + # MethodSettings:Optional, Use this to overwrite above global settings at each method level. + # Type: List of MethodSetting MethodSettings: - LoggingLevel: INFO - CachingEnabled: true - CacheTtlInSeconds: 3600 - # see below... + - CacheDataEncrypted: Boolean + CacheTtlInSeconds: Integer + CachingEnabled: Boolean + ... + - CacheDataEncrypted: Boolean + CacheTtlInSeconds: Integer + CachingEnabled: Boolean + ... #... ``` diff --git a/src/index.js b/src/index.js index ecd66bd..e1ccc92 100644 --- a/src/index.js +++ b/src/index.js @@ -116,16 +116,23 @@ module.exports = function (serverless) { AccessLogSetting: stageSettings.AccessLogSetting || {}, CacheClusterEnabled: stageSettings.CacheClusterEnabled || false, CacheClusterSize: stageSettings.CacheClusterSize || '0.5', + TracingEnabled: stageSettings.TracingEnabled || false, ClientCertificateId: stageSettings.ClientCertificateId || undefined, DocumentationVersion: stageSettings.DocumentationVersion || undefined, MethodSettings: methodSettings.map((item) => ( _.defaults( item || {}, { - DataTraceEnabled: true, - HttpMethod: '*', - ResourcePath: '/*', - MetricsEnabled: false + HttpMethod: stageSettings.MethodSettingsGlobal.HttpMethod || '*', + ResourcePath: stageSettings.MethodSettingsGlobal.ResourcePath || '/*', + CachingEnabled: stageSettings.MethodSettingsGlobal.CachingEnabled || false, + CacheDataEncrypted: stageSettings.MethodSettingsGlobal.CacheDataEncrypted || false, + CacheTtlInSeconds: stageSettings.MethodSettingsGlobal.CacheTtlInSeconds || undefined, + DataTraceEnabled: stageSettings.MethodSettingsGlobal.DataTraceEnabled || false, + LoggingLevel: stageSettings.MethodSettingsGlobal.LoggingLevel || 'OFF', + MetricsEnabled: stageSettings.MethodSettingsGlobal.MetricsEnabled || false, + ThrottlingBurstLimit: stageSettings.MethodSettingsGlobal.ThrottlingBurstLimit || undefined, + ThrottlingRateLimit: stageSettings.MethodSettingsGlobal.ThrottlingRateLimit || undefined } ) )) From 308ed07ae050bd7e2ce54f529848a5a8739fda96 Mon Sep 17 00:00:00 2001 From: singh_m Date: Fri, 30 Aug 2019 12:53:58 +0800 Subject: [PATCH 2/2] refs #30 update tests --- README.md | 14 ++++---------- src/index.js | 20 +++++++++---------- test/spec/index.spec.js | 43 +++++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a3d363d..8e8ed54 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ custom: Variables: foo: bar baz: xyzzy - # The MethodSettingsGlobal property type configures settings for all methods in a stage. - # Required - MethodSettingsGlobal: - CacheDataEncrypted: Boolean + # MethodSettings:Use this to overwrite above global settings at each method level. + # Type: List of MethodSetting + MethodSettings: + - CacheDataEncrypted: Boolean CacheTtlInSeconds: Integer CachingEnabled: Boolean DataTraceEnabled: Boolean @@ -55,12 +55,6 @@ custom: ResourcePath: String ThrottlingBurstLimit: Integer ThrottlingRateLimit: Double - # MethodSettings:Optional, Use this to overwrite above global settings at each method level. - # Type: List of MethodSetting - MethodSettings: - - CacheDataEncrypted: Boolean - CacheTtlInSeconds: Integer - CachingEnabled: Boolean ... - CacheDataEncrypted: Boolean CacheTtlInSeconds: Integer diff --git a/src/index.js b/src/index.js index e1ccc92..9f118d1 100644 --- a/src/index.js +++ b/src/index.js @@ -123,16 +123,16 @@ module.exports = function (serverless) { _.defaults( item || {}, { - HttpMethod: stageSettings.MethodSettingsGlobal.HttpMethod || '*', - ResourcePath: stageSettings.MethodSettingsGlobal.ResourcePath || '/*', - CachingEnabled: stageSettings.MethodSettingsGlobal.CachingEnabled || false, - CacheDataEncrypted: stageSettings.MethodSettingsGlobal.CacheDataEncrypted || false, - CacheTtlInSeconds: stageSettings.MethodSettingsGlobal.CacheTtlInSeconds || undefined, - DataTraceEnabled: stageSettings.MethodSettingsGlobal.DataTraceEnabled || false, - LoggingLevel: stageSettings.MethodSettingsGlobal.LoggingLevel || 'OFF', - MetricsEnabled: stageSettings.MethodSettingsGlobal.MetricsEnabled || false, - ThrottlingBurstLimit: stageSettings.MethodSettingsGlobal.ThrottlingBurstLimit || undefined, - ThrottlingRateLimit: stageSettings.MethodSettingsGlobal.ThrottlingRateLimit || undefined + HttpMethod: stageSettings.HttpMethod || '*', + ResourcePath: stageSettings.ResourcePath || '/*', + CachingEnabled: stageSettings.CachingEnabled || false, + CacheDataEncrypted: stageSettings.CacheDataEncrypted || false, + CacheTtlInSeconds: stageSettings.CacheTtlInSeconds || undefined, + DataTraceEnabled: stageSettings.DataTraceEnabled || false, + LoggingLevel: stageSettings.LoggingLevel || 'OFF', + MetricsEnabled: stageSettings.MetricsEnabled || false, + ThrottlingBurstLimit: stageSettings.ThrottlingBurstLimit || undefined, + ThrottlingRateLimit: stageSettings.ThrottlingRateLimit || undefined } ) )) diff --git a/test/spec/index.spec.js b/test/spec/index.spec.js index 9754a67..9b893fb 100644 --- a/test/spec/index.spec.js +++ b/test/spec/index.spec.js @@ -42,6 +42,7 @@ describe('The `serverless-api-stage` plugin', function () { AccessLogSetting: {}, CacheClusterEnabled: false, CacheClusterSize: '0.5', + TracingEnabled: false, ClientCertificateId: undefined, DocumentationVersion: undefined, DeploymentId: { @@ -50,10 +51,16 @@ describe('The `serverless-api-stage` plugin', function () { Variables: {}, MethodSettings: [ { - DataTraceEnabled: true, HttpMethod: '*', ResourcePath: '/*', - MetricsEnabled: false + CachingEnabled: false, + CacheDataEncrypted: false, + CacheTtlInSeconds: undefined, + DataTraceEnabled: false, + LoggingLevel: 'OFF', + MetricsEnabled: false, + ThrottlingBurstLimit: undefined, + ThrottlingRateLimit: undefined } ] } @@ -77,6 +84,7 @@ describe('The `serverless-api-stage` plugin', function () { }, CacheClusterEnabled: true, CacheClusterSize: '1.0', + TracingEnabled: true, ClientCertificateId: undefined, DocumentationVersion: undefined, Variables: { @@ -87,7 +95,8 @@ describe('The `serverless-api-stage` plugin', function () { MetricsEnabled: true, HttpMethod: 'GET', CacheTtlInSeconds: 3600, - CachingEnabled: true + CachingEnabled: true, + DataTraceEnabled: true } }); pluginInstance = new ApiStagePlugin(serverless); @@ -194,6 +203,7 @@ describe('The `serverless-api-stage` plugin', function () { }, CacheClusterEnabled: true, CacheClusterSize: '1.0', + TracingEnabled: true, ClientCertificateId: undefined, DocumentationVersion: undefined, DeploymentId: { @@ -207,10 +217,13 @@ describe('The `serverless-api-stage` plugin', function () { LoggingLevel: 'INFO', CacheTtlInSeconds: 3600, CachingEnabled: true, + CacheDataEncrypted: false, DataTraceEnabled: true, HttpMethod: 'GET', ResourcePath: '/*', - MetricsEnabled: true + MetricsEnabled: true, + ThrottlingBurstLimit: undefined, + ThrottlingRateLimit: undefined } ] } @@ -331,6 +344,7 @@ describe('The `serverless-api-stage` plugin', function () { AccessLogSetting: {}, CacheClusterEnabled: false, CacheClusterSize: '0.5', + TracingEnabled: false, DeploymentId: { Ref: 'Deployment' }, @@ -339,10 +353,16 @@ describe('The `serverless-api-stage` plugin', function () { Variables: {}, MethodSettings: [ { - DataTraceEnabled: true, HttpMethod: '*', ResourcePath: '/*', - MetricsEnabled: false + CachingEnabled: false, + CacheDataEncrypted: false, + CacheTtlInSeconds: undefined, + DataTraceEnabled: false, + LoggingLevel: 'OFF', + MetricsEnabled: false, + ThrottlingBurstLimit: undefined, + ThrottlingRateLimit: undefined } ] } @@ -463,6 +483,7 @@ describe('The `serverless-api-stage` plugin', function () { AccessLogSetting: {}, CacheClusterEnabled: false, CacheClusterSize: '0.5', + TracingEnabled: false, DeploymentId: { Ref: 'Deployment' }, @@ -471,10 +492,16 @@ describe('The `serverless-api-stage` plugin', function () { Variables: {}, MethodSettings: [ { - DataTraceEnabled: true, HttpMethod: '*', ResourcePath: '/*', - MetricsEnabled: false + CachingEnabled: false, + CacheDataEncrypted: false, + CacheTtlInSeconds: undefined, + DataTraceEnabled: false, + LoggingLevel: 'OFF', + MetricsEnabled: false, + ThrottlingBurstLimit: undefined, + ThrottlingRateLimit: undefined } ] }