From 2eab58575b7863a4748e444aec6b4224afa4ce48 Mon Sep 17 00:00:00 2001 From: Cameron Hartmann Date: Thu, 12 Jan 2017 10:58:42 -0800 Subject: [PATCH 1/4] completed support for stage variables --- README.md | 6 +++--- src/index.js | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 55f2f6b..71a52e2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # serverless-enable-api-logs Enables Coudwatch logging for API Gateway events -# Resources -- [Github](https://github.com/paulSambolin/serverless-enable-api-logs) -- [NPM](https://www.npmjs.com/package/serverless-enable-api-logs) # Usage ```yaml @@ -13,6 +10,9 @@ plugins: - serverless-enable-api-logs ... +custom: + stageVariables: + thirdPartyEndpoint: http://supercool.endpoint.com/openapi/something functions: get: diff --git a/src/index.js b/src/index.js index 656f055..8675018 100644 --- a/src/index.js +++ b/src/index.js @@ -18,12 +18,13 @@ module.exports = Class.extend({ const template = this._serverless.service.provider.compiledCloudFormationTemplate; // setup variables, if any are defined - /* + var variables = {}; + if (this._serverless.service.custom.stageVariables) { variables = this._serverless.service.custom.stageVariables; } -*/ + // find the correct stage name var stage = this._serverless.service.defaults.stage; @@ -51,10 +52,13 @@ module.exports = Class.extend({ LoggingLevel: "INFO", ResourcePath: "/*", MetricsEnabled: true - }] + }], + Variables: variables } } + console.log(JSON.stringify(variables)); + // find the deployment resource, and add the stage resource Object.keys(template.Resources).forEach(function(key){ if (template.Resources[key]['Type'] == 'AWS::ApiGateway::Deployment') { From 1cec08cc246a4dd5c4b4cea00332e9604d67a971 Mon Sep 17 00:00:00 2001 From: Cameron Hartmann Date: Thu, 12 Jan 2017 11:06:20 -0800 Subject: [PATCH 2/4] fixing readme, removing console.log --- README.md | 11 ++++++++--- src/index.js | 2 -- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 71a52e2..f39965b 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ # serverless-enable-api-logs Enables Coudwatch logging for API Gateway events +-# Resources +-- [Github](https://github.com/paulSambolin/serverless-enable-api-logs) +-- [NPM](https://www.npmjs.com/package/serverless-enable-api-logs) # Usage ```yaml ... +custom: + stageVariables: + thirdPartyEndpoint: http://supercool.endpoint.com/openapi/something + + plugins: - serverless-enable-api-logs ... -custom: - stageVariables: - thirdPartyEndpoint: http://supercool.endpoint.com/openapi/something functions: get: diff --git a/src/index.js b/src/index.js index 8675018..80b6e8d 100644 --- a/src/index.js +++ b/src/index.js @@ -57,8 +57,6 @@ module.exports = Class.extend({ } } - console.log(JSON.stringify(variables)); - // find the deployment resource, and add the stage resource Object.keys(template.Resources).forEach(function(key){ if (template.Resources[key]['Type'] == 'AWS::ApiGateway::Deployment') { From 70d93957e0e9acbc030c90dacdc39f26c16b4901 Mon Sep 17 00:00:00 2001 From: Cameron Hartmann Date: Thu, 12 Jan 2017 11:07:32 -0800 Subject: [PATCH 3/4] removing dashes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f39965b..23776c8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # serverless-enable-api-logs Enables Coudwatch logging for API Gateway events --# Resources --- [Github](https://github.com/paulSambolin/serverless-enable-api-logs) --- [NPM](https://www.npmjs.com/package/serverless-enable-api-logs) +# Resources +- [Github](https://github.com/paulSambolin/serverless-enable-api-logs) +- [NPM](https://www.npmjs.com/package/serverless-enable-api-logs) # Usage ```yaml From 52cf89efbd69a96cc2fea71a8f1a0e79e4dc3027 Mon Sep 17 00:00:00 2001 From: Cameron Hartmann Date: Thu, 12 Jan 2017 11:12:28 -0800 Subject: [PATCH 4/4] fixing check for stage variable existance --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 80b6e8d..8ed2712 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ module.exports = Class.extend({ var variables = {}; - if (this._serverless.service.custom.stageVariables) { + if (this._serverless.service.custom && this._serverless.service.custom.stageVariables) { variables = this._serverless.service.custom.stageVariables; }