From 219cea9f3a778692b4bd9e84cdee2d9cc53fac57 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:44:11 +0700 Subject: [PATCH 01/15] Actions: remove serverless prefix --- lib/actions/CodeDeployLambda.js | 2 +- lib/actions/CodePackageLambda.js | 2 +- lib/actions/ComponentCreate.js | 2 +- lib/actions/DashDeploy.js | 2 +- lib/actions/EndpointBuildApiGateway.js | 2 +- lib/actions/EndpointDeploy.js | 2 +- lib/actions/EndpointDeployApiGateway.js | 2 +- lib/actions/EnvGet.js | 2 +- lib/actions/EnvList.js | 2 +- lib/actions/EnvSet.js | 2 +- lib/actions/EnvUnset.js | 2 +- lib/actions/EventDeploy.js | 2 +- lib/actions/EventDeployS3Lambda.js | 2 +- lib/actions/EventDeploySNSLambda.js | 2 +- lib/actions/EventDeployScheduledLambda.js | 2 +- lib/actions/EventDeployStreamLambda.js | 2 +- lib/actions/FunctionCreate.js | 2 +- lib/actions/FunctionDeploy.js | 2 +- lib/actions/FunctionLogs.js | 2 +- lib/actions/FunctionRun.js | 2 +- lib/actions/FunctionRunLambdaNodeJs.js | 2 +- lib/actions/FunctionRunLambdaPython2.js | 2 +- lib/actions/ModuleInstall.js | 2 +- lib/actions/PluginCreate.js | 2 +- lib/actions/ProjectInit.js | 2 +- lib/actions/ProjectInstall.js | 2 +- lib/actions/ProjectRemove.js | 2 +- lib/actions/RegionCreate.js | 2 +- lib/actions/RegionRemove.js | 2 +- lib/actions/ResourcesDeploy.js | 2 +- lib/actions/ResourcesDiff.js | 2 +- lib/actions/ResourcesRemove.js | 2 +- lib/actions/StageCreate.js | 2 +- lib/actions/StageRemove.js | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/actions/CodeDeployLambda.js b/lib/actions/CodeDeployLambda.js index 2f82acf30..898e20bfa 100644 --- a/lib/actions/CodeDeployLambda.js +++ b/lib/actions/CodeDeployLambda.js @@ -9,7 +9,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'), Zip = require('node-zip'), diff --git a/lib/actions/CodePackageLambda.js b/lib/actions/CodePackageLambda.js index 6b303783f..a581c2b27 100644 --- a/lib/actions/CodePackageLambda.js +++ b/lib/actions/CodePackageLambda.js @@ -11,7 +11,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'), fs = require('fs'), diff --git a/lib/actions/ComponentCreate.js b/lib/actions/ComponentCreate.js index 0bc8b7709..b8c23478a 100644 --- a/lib/actions/ComponentCreate.js +++ b/lib/actions/ComponentCreate.js @@ -13,7 +13,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), SUtils = require(path.join(serverlessPath, 'utils')), BbPromise = require('bluebird'), diff --git a/lib/actions/DashDeploy.js b/lib/actions/DashDeploy.js index 9eea89d16..bd53f924b 100644 --- a/lib/actions/DashDeploy.js +++ b/lib/actions/DashDeploy.js @@ -19,7 +19,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/EndpointBuildApiGateway.js b/lib/actions/EndpointBuildApiGateway.js index 2700641b1..d2ece72c3 100644 --- a/lib/actions/EndpointBuildApiGateway.js +++ b/lib/actions/EndpointBuildApiGateway.js @@ -8,7 +8,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'), async = require('async'), diff --git a/lib/actions/EndpointDeploy.js b/lib/actions/EndpointDeploy.js index 4f64dbfdd..da3c7443b 100644 --- a/lib/actions/EndpointDeploy.js +++ b/lib/actions/EndpointDeploy.js @@ -20,7 +20,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/EndpointDeployApiGateway.js b/lib/actions/EndpointDeployApiGateway.js index d7aca13d7..665d600b8 100644 --- a/lib/actions/EndpointDeployApiGateway.js +++ b/lib/actions/EndpointDeployApiGateway.js @@ -8,7 +8,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'), fs = require('fs'); diff --git a/lib/actions/EnvGet.js b/lib/actions/EnvGet.js index 6e683fb30..de0c4d74f 100644 --- a/lib/actions/EnvGet.js +++ b/lib/actions/EnvGet.js @@ -12,7 +12,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), SUtils = require(path.join(serverlessPath, 'utils/index')), chalk = require('chalk'), diff --git a/lib/actions/EnvList.js b/lib/actions/EnvList.js index 5028c9b24..faa71b7a5 100644 --- a/lib/actions/EnvList.js +++ b/lib/actions/EnvList.js @@ -11,7 +11,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), chalk = require('chalk'), BbPromise = require('bluebird'), diff --git a/lib/actions/EnvSet.js b/lib/actions/EnvSet.js index e95d0b7e9..513603d3a 100644 --- a/lib/actions/EnvSet.js +++ b/lib/actions/EnvSet.js @@ -7,7 +7,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils')); diff --git a/lib/actions/EnvUnset.js b/lib/actions/EnvUnset.js index 085ea1d5d..a9175a545 100644 --- a/lib/actions/EnvUnset.js +++ b/lib/actions/EnvUnset.js @@ -7,7 +7,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils')); diff --git a/lib/actions/EventDeploy.js b/lib/actions/EventDeploy.js index 8fe0b458c..01d9e902d 100644 --- a/lib/actions/EventDeploy.js +++ b/lib/actions/EventDeploy.js @@ -18,7 +18,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/EventDeployS3Lambda.js b/lib/actions/EventDeployS3Lambda.js index ebc992026..de613e32a 100644 --- a/lib/actions/EventDeployS3Lambda.js +++ b/lib/actions/EventDeployS3Lambda.js @@ -13,7 +13,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'); diff --git a/lib/actions/EventDeploySNSLambda.js b/lib/actions/EventDeploySNSLambda.js index beb403f6c..90bd547fc 100644 --- a/lib/actions/EventDeploySNSLambda.js +++ b/lib/actions/EventDeploySNSLambda.js @@ -13,7 +13,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'); diff --git a/lib/actions/EventDeployScheduledLambda.js b/lib/actions/EventDeployScheduledLambda.js index b65b9db94..40590bd27 100644 --- a/lib/actions/EventDeployScheduledLambda.js +++ b/lib/actions/EventDeployScheduledLambda.js @@ -13,7 +13,7 @@ module.exports = function (SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'); diff --git a/lib/actions/EventDeployStreamLambda.js b/lib/actions/EventDeployStreamLambda.js index 2021dc1da..c9b4b2c64 100644 --- a/lib/actions/EventDeployStreamLambda.js +++ b/lib/actions/EventDeployStreamLambda.js @@ -14,7 +14,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), BbPromise = require('bluebird'); diff --git a/lib/actions/FunctionCreate.js b/lib/actions/FunctionCreate.js index 91ffab3b7..1b9cd1b99 100644 --- a/lib/actions/FunctionCreate.js +++ b/lib/actions/FunctionCreate.js @@ -13,7 +13,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils')); diff --git a/lib/actions/FunctionDeploy.js b/lib/actions/FunctionDeploy.js index b0308b540..98c2b8a22 100644 --- a/lib/actions/FunctionDeploy.js +++ b/lib/actions/FunctionDeploy.js @@ -12,7 +12,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/FunctionLogs.js b/lib/actions/FunctionLogs.js index b23558870..ed4d2c476 100644 --- a/lib/actions/FunctionLogs.js +++ b/lib/actions/FunctionLogs.js @@ -16,7 +16,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils/index')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/FunctionRun.js b/lib/actions/FunctionRun.js index 461488210..6cc91dd85 100644 --- a/lib/actions/FunctionRun.js +++ b/lib/actions/FunctionRun.js @@ -7,7 +7,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), BbPromise = require('bluebird'), chalk = require('chalk'), SCli = require( path.join( serverlessPath, 'utils', 'cli')); diff --git a/lib/actions/FunctionRunLambdaNodeJs.js b/lib/actions/FunctionRunLambdaNodeJs.js index 81fc146da..2f43959db 100644 --- a/lib/actions/FunctionRunLambdaNodeJs.js +++ b/lib/actions/FunctionRunLambdaNodeJs.js @@ -7,7 +7,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), diff --git a/lib/actions/FunctionRunLambdaPython2.js b/lib/actions/FunctionRunLambdaPython2.js index 721e94135..558bcaadb 100644 --- a/lib/actions/FunctionRunLambdaPython2.js +++ b/lib/actions/FunctionRunLambdaPython2.js @@ -6,7 +6,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SUtils = require(path.join(serverlessPath, 'utils')), spawnSync = require('child_process').spawnSync, SCli = require(path.join(serverlessPath, 'utils/cli')), diff --git a/lib/actions/ModuleInstall.js b/lib/actions/ModuleInstall.js index fb9eca01f..08218ad1f 100644 --- a/lib/actions/ModuleInstall.js +++ b/lib/actions/ModuleInstall.js @@ -14,7 +14,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), URL = require('url'), Download = require('download'), diff --git a/lib/actions/PluginCreate.js b/lib/actions/PluginCreate.js index a3df150f3..f84cecab4 100644 --- a/lib/actions/PluginCreate.js +++ b/lib/actions/PluginCreate.js @@ -12,7 +12,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils')), diff --git a/lib/actions/ProjectInit.js b/lib/actions/ProjectInit.js index 166bd168a..30189e027 100644 --- a/lib/actions/ProjectInit.js +++ b/lib/actions/ProjectInit.js @@ -19,7 +19,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require( path.join( serverlessPath, 'ServerlessError' ) ), + SError = require( path.join( serverlessPath, 'Error' ) ), SCli = require( path.join( serverlessPath, 'utils/cli' ) ), SUtils = require( path.join( serverlessPath, 'utils' ) ), BbPromise = require('bluebird'), diff --git a/lib/actions/ProjectInstall.js b/lib/actions/ProjectInstall.js index 162329f2c..845b7a112 100644 --- a/lib/actions/ProjectInstall.js +++ b/lib/actions/ProjectInstall.js @@ -23,7 +23,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require( path.join( serverlessPath, 'ServerlessError' ) ), + SError = require( path.join( serverlessPath, 'Error' ) ), SCli = require( path.join( serverlessPath, 'utils/cli' ) ), SUtils = require( path.join( serverlessPath, 'utils' ) ), BbPromise = require('bluebird'), diff --git a/lib/actions/ProjectRemove.js b/lib/actions/ProjectRemove.js index b14796cab..635f8ac16 100644 --- a/lib/actions/ProjectRemove.js +++ b/lib/actions/ProjectRemove.js @@ -11,7 +11,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), fs = require('fs'), BbPromise = require('bluebird'), diff --git a/lib/actions/RegionCreate.js b/lib/actions/RegionCreate.js index 943c4fa2c..400b2dc47 100644 --- a/lib/actions/RegionCreate.js +++ b/lib/actions/RegionCreate.js @@ -17,7 +17,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils')); diff --git a/lib/actions/RegionRemove.js b/lib/actions/RegionRemove.js index 85a351157..b4c07a1f6 100644 --- a/lib/actions/RegionRemove.js +++ b/lib/actions/RegionRemove.js @@ -16,7 +16,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), fs = BbPromise.promisifyAll(require('fs')), diff --git a/lib/actions/ResourcesDeploy.js b/lib/actions/ResourcesDeploy.js index 81f67cd35..8e6620eea 100644 --- a/lib/actions/ResourcesDeploy.js +++ b/lib/actions/ResourcesDeploy.js @@ -9,7 +9,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), replaceall = require('replaceall'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), _ = require('lodash'), diff --git a/lib/actions/ResourcesDiff.js b/lib/actions/ResourcesDiff.js index e229b9986..c819549bb 100644 --- a/lib/actions/ResourcesDiff.js +++ b/lib/actions/ResourcesDiff.js @@ -13,7 +13,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), fs = BbPromise.promisifyAll(require('fs')), diff --git a/lib/actions/ResourcesRemove.js b/lib/actions/ResourcesRemove.js index 27967bc03..a89460847 100644 --- a/lib/actions/ResourcesRemove.js +++ b/lib/actions/ResourcesRemove.js @@ -8,7 +8,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), SUtils = require(path.join(serverlessPath, 'utils/index')), diff --git a/lib/actions/StageCreate.js b/lib/actions/StageCreate.js index dd1f06fab..a78c4ca98 100644 --- a/lib/actions/StageCreate.js +++ b/lib/actions/StageCreate.js @@ -14,7 +14,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), os = require('os'), fs = require('fs'), diff --git a/lib/actions/StageRemove.js b/lib/actions/StageRemove.js index 77209b1a0..588320cab 100644 --- a/lib/actions/StageRemove.js +++ b/lib/actions/StageRemove.js @@ -11,7 +11,7 @@ module.exports = function(SPlugin, serverlessPath) { const path = require('path'), - SError = require(path.join(serverlessPath, 'ServerlessError')), + SError = require(path.join(serverlessPath, 'Error')), SCli = require(path.join(serverlessPath, 'utils/cli')), fs = require('fs'), BbPromise = require('bluebird'), From eeb8505b3e94835281dba815cf62ba947d459272 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:51:55 +0700 Subject: [PATCH 02/15] fix ProviderAws --- lib/ProviderAws.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/ProviderAws.js b/lib/ProviderAws.js index a32a096d0..dcfc38a57 100644 --- a/lib/ProviderAws.js +++ b/lib/ProviderAws.js @@ -65,22 +65,24 @@ class ServerlessProviderAws { let req = awsService[method](params); // Add listeners... - //req.on('validate', function(r) {}); + req.on('validate', function(r) {}); - let performRequest = function() { - return new BbPromise(function(resolve, reject) { + return new BbPromise(function(resolve, reject) { + let performRequest = function() { req.send(function(err, data) { if (err && err.statusCode == 429) { SUtils.sDebug("'Too many requests' received, sleeping 5 seconds, then retrying..."); - setTimeout( performRequest, 5000 ); + return setTimeout( performRequest, 5000 ); } else if (err) { - reject( err ); + return reject(err); } - resolve(data); + + return resolve(data); }); - }); - }; - return performRequest(); + }; + + performRequest(); + }); } /** @@ -143,6 +145,14 @@ class ServerlessProviderAws { sessionToken: process.env['AWS_SESSION_TOKEN'], region: region }; + } else if (this._S.config.awsAdminKeyId) { + + // Access Keys from the config + credentials = { + accessKeyId: this._S.config.awsAdminKeyId, + secretAccessKey: this._S.config.awsAdminSecretKey, + region: region + }; } if (!credentials) { From 35ea9830802468f5af093908910451e71bd1ccbf Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:52:30 +0700 Subject: [PATCH 03/15] fixes Function and Project classes --- lib/Function.js | 8 +++----- lib/Project.js | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/Function.js b/lib/Function.js index 44c0ae390..5beffdbc8 100644 --- a/lib/Function.js +++ b/lib/Function.js @@ -171,7 +171,8 @@ class ServerlessFunction { while( !_this._S.classes.Component.isComponentDir( p ) ) { if( SUtils.fileExistsSync(path.join(p, 's-templates.json'))) { - templates.unshift( require(path.join(p, 's-templates.json')) ); + let template = JSON.parse(fs.readFileSync(path.join(p, 's-templates.json'), 'utf8')); + templates.unshift(template); } p = path.join( p, '..' ); } @@ -266,10 +267,7 @@ class ServerlessFunction { // Populate let clone = _this.get(); clone = SUtils.populate(_this._S.state.getMeta(), _this.getTemplates(), clone, options.stage, options.region); - clone.endpoints = []; - for (let i = 0; i < _this.endpoints.length; i++) { - clone.endpoints[i] = _this.endpoints[i].getPopulated(options); - } + clone.endpoints = _this.endpoints.map( endpoint => endpoint.getPopulated(options) ); return clone; } diff --git a/lib/Project.js b/lib/Project.js index 0055682bd..ec3d57a13 100644 --- a/lib/Project.js +++ b/lib/Project.js @@ -299,7 +299,7 @@ class ServerlessProject extends VarContainer { resources = SUtils.readAndParseJsonSync(_this._S.getProject().getFilePath('s-resources-cf.json')); } - return _.flatten( _.map( _.values( _this.components ), c => c.getCFSnippets() ) ); + return _.flattenDeep( _.map( _.values( _this.components ), c => c.getCFSnippets() ) ); }) .then(function (cfSnippets) { @@ -477,7 +477,7 @@ class ServerlessProject extends VarContainer { getAllComponents(options){ if( _.get( options, 'paths' ) ){ - options.paths = _.map( options.paths, p => p.split(path.sep)[0] ); + options.paths = _.map( options.paths, p => p && p.split(path.sep)[0] ); } return SUtils.filterSPaths( _.values( this.components ), options ); } @@ -535,7 +535,7 @@ class ServerlessProject extends VarContainer { } getRegion( stageName, regionName ){ - if( this.hasStage( stageName ) ){ + if( this.validateStageExists( stageName ) ){ let stage = this.getStage( stageName ); if( stage.hasRegion( regionName ) ){ From 3ce9e0b28cfebfc86544ade3c394d5888e3f8f5a Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:53:06 +0700 Subject: [PATCH 04/15] fix actions --- lib/actions/CodePackageLambda.js | 2 ++ lib/actions/FunctionLogs.js | 1 + lib/actions/ProjectInit.js | 4 +--- lib/actions/ProjectRemove.js | 2 +- lib/actions/RegionCreate.js | 22 +++++++++++----------- lib/actions/RegionRemove.js | 13 ++++++------- lib/actions/ResourcesDeploy.js | 4 ++-- lib/actions/ResourcesRemove.js | 2 +- lib/actions/StageCreate.js | 24 ++++++++++++++---------- 9 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/actions/CodePackageLambda.js b/lib/actions/CodePackageLambda.js index a581c2b27..05dcb858a 100644 --- a/lib/actions/CodePackageLambda.js +++ b/lib/actions/CodePackageLambda.js @@ -181,7 +181,9 @@ module.exports = function(SPlugin, serverlessPath) { SUtils.sDebug(`Getting ENV Vars: ${_this.meta.variables.projectBucket} - ${key}`); // Get ENV file from S3 + let NoSuchKey = {code: 'NoSuchKey'}; return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, _this.evt.options.region) + .catch(NoSuchKey => ({Body: ''})) .then(function(s3ObjData) { fs.writeFileSync( diff --git a/lib/actions/FunctionLogs.js b/lib/actions/FunctionLogs.js index ed4d2c476..f1c577586 100644 --- a/lib/actions/FunctionLogs.js +++ b/lib/actions/FunctionLogs.js @@ -156,6 +156,7 @@ module.exports = function(SPlugin, serverlessPath) { return this.S.getProvider('aws') .request('Lambda', 'getAlias', params, this.evt.options.stage, this.evt.options.region) + .bind(this) .then(reply => this.evt.data.version = reply.FunctionVersion) .then(this._getLogStreams) .then( logStreams => { diff --git a/lib/actions/ProjectInit.js b/lib/actions/ProjectInit.js index 30189e027..88ba9d91c 100644 --- a/lib/actions/ProjectInit.js +++ b/lib/actions/ProjectInit.js @@ -281,10 +281,8 @@ module.exports = function(SPlugin, serverlessPath) { _validateAndPrepare() { - this.S.getProvider('aws').getProfile(this.evt.options.profile); - // If Profile, extract API Keys - if (this.evt.options.profile) { + if (this.evt.options.profile && this.S.getProvider('aws').getProfile(this.evt.options.profile)) { this.S.config.awsAdminKeyId = this.S.getProvider('aws').getProfile(this.evt.options.profile).aws_access_key_id; this.S.config.awsAdminSecretKey = this.S.getProvider('aws').getProfile(this.evt.options.profile).aws_secret_access_key; } diff --git a/lib/actions/ProjectRemove.js b/lib/actions/ProjectRemove.js index 635f8ac16..2d03ac10b 100644 --- a/lib/actions/ProjectRemove.js +++ b/lib/actions/ProjectRemove.js @@ -85,7 +85,7 @@ usage: serverless project remove`, */ _removeAllStages() { -ยง let stages = this.S.getProject().getStages() + let stages = this.S.getProject().getStages() return BbPromise.each(stages, (stage) => { let evt = { diff --git a/lib/actions/RegionCreate.js b/lib/actions/RegionCreate.js index 400b2dc47..a735fa696 100644 --- a/lib/actions/RegionCreate.js +++ b/lib/actions/RegionCreate.js @@ -142,16 +142,15 @@ usage: serverless region create`, return BbPromise.reject(new SError('Region "' + _this.evt.options.region + '" already exists in stage "' + _this.evt.options.stage + '"')); } - // Update and save Meta - _this.meta = _this.S.state.getMeta(); + // Update and save Project + const project = _this.S.getProject() + const stage = project.getStage(_this.evt.options.stage); + const region = new _this.S.classes.Region(_this.S, stage, _this.evt.options.region) - _this.meta.stages[_this.evt.options.stage].regions[_this.evt.options.region] = { - variables: { - region: _this.evt.options.region - } - }; + stage.addRegion(region); + + return project.save(); - return _this.meta.save(); } /** @@ -173,8 +172,9 @@ usage: serverless region create`, // Create bucket, or skip if already exists const stage = this.evt.options.stage, - region = this.evt.options.region, - bucketName = this.S.state.getMeta().variables.projectBucket; + bucketName = this.S.state.getMeta().variables.projectBucket, + region = this.evt.options.region; + // region = bucketName.split('.')[1]; return this.S.getProvider('aws') .request('S3', 'getBucketAcl', { Bucket: bucketName }, stage, region) @@ -224,7 +224,7 @@ SERVERLESS_PROJECT_NAME=${projectName}`; let params = { Bucket: this.S.state.getMeta().variables.projectBucket, - Key: key, + Key: "/" + key, ACL: 'private', ContentType: 'text/plain', Body: envFileContents diff --git a/lib/actions/RegionRemove.js b/lib/actions/RegionRemove.js index b4c07a1f6..631fc67f1 100644 --- a/lib/actions/RegionRemove.js +++ b/lib/actions/RegionRemove.js @@ -149,13 +149,13 @@ usage: serverless region remove`, _listS3Objects() { SUtils.sDebug("List related S3 objects"); - let prefix = ['serverless', this.S.getProject().name, this.evt.options.stage, this.evt.options.region].join('/'), + let prefix = ['serverless', this.S.getProject().getName(), this.evt.options.stage, this.evt.options.region].join('/'), params = { Bucket: this.S.state.getMeta().variables.projectBucket, Prefix: prefix }; - return this.S.getProvider('aws').request('S3', 'listObjects', params, stage, region) - .then(reply => {return _.map(reply.Contents, (item) => ({Key: item.Key}) )}); + return this.S.getProvider('aws').request('S3', 'listObjects', params, this.evt.options.stage, this.evt.options.region) + .then(reply => _.map(reply.Contents, (item) => ({Key: item.Key}))); } _removeS3Objects(objects) { @@ -168,7 +168,7 @@ usage: serverless region remove`, Objects: objects } }; - return this.S.getProvider('aws').request('S3', 'deleteObjects', params, stage, region); + return this.S.getProvider('aws').request('S3', 'deleteObjects', params, this.evt.options.stage, this.evt.options.region); } else { SUtils.sDebug("S3 objects are not found. Skipping."); return BbPromise.resolve(); @@ -177,9 +177,8 @@ usage: serverless region remove`, _removeMeta() { // Update and save Meta - let meta = this.S.state.getMeta(); - delete meta.stages[this.evt.options.stage].regions[this.evt.options.region] - return meta.save(); + this.S.getProject().getStage(this.evt.options.stage).removeRegion(this.evt.options.region); + return this.S.getProject().save(); } _removeVariables() { diff --git a/lib/actions/ResourcesDeploy.js b/lib/actions/ResourcesDeploy.js index 8e6620eea..36a74ea83 100644 --- a/lib/actions/ResourcesDeploy.js +++ b/lib/actions/ResourcesDeploy.js @@ -156,7 +156,7 @@ usage: serverless resources deploy`, _deployResources() { let _this = this; - let regionVars = _this.S.state.getMeta().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables; + let regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region)._variables let resourceVars = [ 'iamRoleArnLambda' ].concat( _this.S.getProject().resourceVars); return _this.S.getProject().getResources({ @@ -262,7 +262,7 @@ usage: serverless resources deploy`, stage = this.evt.options.stage, region = this.evt.options.region, aws = this.S.getProvider('aws'), - stackName = this.S.state.getMeta().stages[stage].regions[region].variables.resourcesStackName || aws.getLambdasStackName(stage, projectName); + stackName = this.S.getProject().getRegion(stage, region)._variables.resourcesStackName || aws.getLambdasStackName(stage, projectName); // CF Params let params = { diff --git a/lib/actions/ResourcesRemove.js b/lib/actions/ResourcesRemove.js index a89460847..086abb5ca 100644 --- a/lib/actions/ResourcesRemove.js +++ b/lib/actions/ResourcesRemove.js @@ -157,7 +157,7 @@ usage: serverless resources remove`, let _this = this, stage = _this.evt.options.stage, region = _this.evt.options.region, - regionVars = _this.S.state.getMeta().stages[stage].regions[region].variables, + regionVars = _this.S.getProject().getRegion(stage, region)._variables, projectBucket = _this.S.state.getMeta().variables.projectBucket, projectName = _this.S.getProject().getName(), aws = _this.S.getProvider('aws'); diff --git a/lib/actions/StageCreate.js b/lib/actions/StageCreate.js index a78c4ca98..53ad4570b 100644 --- a/lib/actions/StageCreate.js +++ b/lib/actions/StageCreate.js @@ -182,21 +182,25 @@ usage: serverless stage create`, */ _createStage() { + const project = this.S.getProject(); + const stage = new this.S.classes.Stage(this.S, project, this.evt.options.stage); - let _this = this; + project.addStage(stage); - // Update Meta - _this.meta = _this.S.state.getMeta(); + return project.save(); - _this.meta.stages[_this.evt.options.stage] = { - regions: {}, - variables: { - stage: _this.evt.options.stage - } - }; + // // Update Meta + // _this.meta = _this.S.state.getMeta(); + + // _this.meta.stages[_this.evt.options.stage] = { + // regions: {}, + // variables: { + // stage: _this.evt.options.stage + // } + // }; // Save Meta before adding region - return _this.meta.save(); + // return _this.meta.save(); } /** From a60d8c140b60ebb1816cfd953a380cef045ade10 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:53:36 +0700 Subject: [PATCH 05/15] fix the template populate function --- lib/utils/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 439fd2453..141c03829 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -299,14 +299,16 @@ exports.doesFunctionExist = function(functionName, componentName, projectRootPat exports.populate = function(meta, templates, data, stage, region) { + const project = meta._S.getProject() + // Validate required params if (!meta || !templates || !data || !stage || !region) throw new SError(`Missing required params: Serverless, project, stage, region`); // Validate: Check stage exists - if (typeof stage != 'undefined' && !meta.stages[stage]) throw new SError(`Stage doesn't exist`); + if (typeof stage != 'undefined' && !project.validateStageExists(stage)) throw new SError(`Stage doesn't exist`); // Validate: Check region exists in stage - if (typeof region != 'undefined' && !meta.stages[stage].regions[region]) throw new SError(`Region doesn't exist in provided stage`); + if (typeof region != 'undefined' && !project.validateRegionExists(stage, region)) throw new SError(`Region doesn't exist in provided stage`); // Sanitize: Remove nested properties. DO NOT populate these. Rely on calling those classes getPopulated methods instead. if (data.components) delete data.components; @@ -316,12 +318,12 @@ exports.populate = function(meta, templates, data, stage, region) { let varTemplateSyntax = /\${([\s\S]+?)}/g, templateTemplateSyntax = /\$\${([\s\S]+?)}/g; - if (meta._S.getProject().variableSyntax) { - varTemplateSyntax = RegExp(meta._S.getProject().variableSyntax,'g'); + if (project.variableSyntax) { + varTemplateSyntax = RegExp(project.variableSyntax,'g'); } - if (meta._S.getProject().templateSyntax) { - templateTemplateSyntax = RegExp(meta._S.getProject().templateSyntax,'g'); + if (project.templateSyntax) { + templateTemplateSyntax = RegExp(project.templateSyntax,'g'); } // Populate templates @@ -362,10 +364,10 @@ exports.populate = function(meta, templates, data, stage, region) { let variableName = variableSyntax.replace(varTemplateSyntax, (match, varName) => varName.trim()); let value; - if (meta.stages[stage].regions[region].variables[variableName]) { - value = meta.stages[stage].regions[region].variables[variableName] - } else if (meta.stages[stage].variables[variableName]) { - value = meta.stages[stage].variables[variableName]; + if (project.getRegion(stage, region)._variables[variableName]) { + value = project.getRegion(stage, region)._variables[variableName] + } else if (project.getStage(stage)._variables[variableName]) { + value = project.getStage(stage)._variables[variableName]; } else if (meta.variables[variableName]) { value = meta.variables[variableName]; } From 98d22f9fa629bdb125a5e2bbdfdcc7047c8c39ba Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 18:53:58 +0700 Subject: [PATCH 06/15] fix tests --- tests/tests/actions/ProjectInit.js | 13 +++++++----- tests/tests/actions/ProjectInstall.js | 11 ++++++---- tests/tests/actions/RegionCreate.js | 3 ++- tests/tests/actions/StageCreate.js | 5 +++-- tests/tests/actions/projectLifeCycle.js | 22 +++++++++++++------- tests/tests/classes/ServerlessProjectTest.js | 3 +-- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/tests/tests/actions/ProjectInit.js b/tests/tests/actions/ProjectInit.js index aaced21ff..91376cfa7 100644 --- a/tests/tests/actions/ProjectInit.js +++ b/tests/tests/actions/ProjectInit.js @@ -88,7 +88,7 @@ let cleanup = function(Meta, cb, evt) { // Delete CloudFormation Resources Stack let cloudformation = new AWS.CloudFormation(); cloudformation.deleteStack({ - StackName: Meta.stages[config.stage].regions[config.region].variables.resourcesStackName + StackName: serverless.getProject().getRegion(config.stage, config.region)._variables.resourcesStackName }, function (err, data) { if (err) console.log(err, err.stack); // an error occurred @@ -140,14 +140,17 @@ describe('Test action: Project Init', function() { // Validate Meta let Meta = serverless.state.getMeta(); + let stage = serverless.getProject().getStage(config.stage); + let region = serverless.getProject().getRegion(config.stage, config.region); + assert.equal(true, typeof Meta.variables.project != 'undefined'); assert.equal(true, typeof Meta.variables.domain != 'undefined'); assert.equal(true, typeof Meta.variables.projectBucket != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined'); + assert.equal(true, typeof stage._variables.stage != 'undefined'); + assert.equal(true, typeof region._variables.region != 'undefined'); if (!config.noExecuteCf) { - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined'); + assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined'); + assert.equal(true, typeof region._variables.resourcesStackName != 'undefined'); } // Validate Event diff --git a/tests/tests/actions/ProjectInstall.js b/tests/tests/actions/ProjectInstall.js index fded5d0b9..6716b98b3 100644 --- a/tests/tests/actions/ProjectInstall.js +++ b/tests/tests/actions/ProjectInstall.js @@ -140,15 +140,18 @@ describe('Test action: Project Install', function() { // Validate Meta let Meta = serverless.state.getMeta(); + let stage = serverless.getProject().getStage(config.stage); + let region = serverless.getProject().getRegion(config.stage, config.region); + assert.equal(true, typeof Meta.variables.project != 'undefined'); assert.equal(true, typeof Meta.variables.domain != 'undefined'); assert.equal(true, typeof Meta.variables.projectBucket != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined'); + assert.equal(true, typeof stage._variables.stage != 'undefined'); + assert.equal(true, typeof region._variables.region != 'undefined'); if (!config.noExecuteCf) { - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined'); + assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined'); + assert.equal(true, typeof region._variables.resourcesStackName != 'undefined'); } // Validate Event diff --git a/tests/tests/actions/RegionCreate.js b/tests/tests/actions/RegionCreate.js index 48338a563..5cfa45304 100644 --- a/tests/tests/actions/RegionCreate.js +++ b/tests/tests/actions/RegionCreate.js @@ -105,7 +105,8 @@ describe('Test Action: Region Create', function() { let Meta = serverless.state.meta; //console.log(serverless.state.meta.stages) - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region2].variables.region != 'undefined'); + + assert.equal(true, typeof serverless.getProject().getRegion(config.stage, config.region2)._variables.region != 'undefined'); // Validate Event validateEvent(evt); diff --git a/tests/tests/actions/StageCreate.js b/tests/tests/actions/StageCreate.js index f77330c41..88f912459 100644 --- a/tests/tests/actions/StageCreate.js +++ b/tests/tests/actions/StageCreate.js @@ -97,8 +97,9 @@ describe('Test Action: Stage Create', function() { .then(function(evt) { let Meta = serverless.state.meta; - assert.equal(true, typeof Meta.stages[config.stage2].variables.stage != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region].variables.region != 'undefined'); + let project = serverless.getProject(); + assert.equal(true, typeof project.getStage(config.stage2)._variables.stage != 'undefined'); + assert.equal(true, typeof project.getRegion(config.stage2, config.region)._variables.region != 'undefined'); // Validate EVT validateEvent(evt); diff --git a/tests/tests/actions/projectLifeCycle.js b/tests/tests/actions/projectLifeCycle.js index 0e56e6c2c..c6ba7cb2b 100644 --- a/tests/tests/actions/projectLifeCycle.js +++ b/tests/tests/actions/projectLifeCycle.js @@ -116,14 +116,18 @@ describe('Test: Project Live Cycle', function() { // Validate Meta let Meta = serverless.state.getMeta(); + let stage = serverless.getProject().getStage(config.stage); + let region = serverless.getProject().getRegion(config.stage, config.region); + + assert.equal(true, typeof Meta.variables.project != 'undefined'); assert.equal(true, typeof Meta.variables.domain != 'undefined'); assert.equal(true, typeof Meta.variables.projectBucket != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].variables.stage != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.region != 'undefined'); + assert.equal(true, typeof stage._variables.stage != 'undefined'); + assert.equal(true, typeof region._variables.region != 'undefined'); if (!config.noExecuteCf) { - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.iamRoleArnLambda != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage].regions[config.region].variables.resourcesStackName != 'undefined'); + assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined'); + assert.equal(true, typeof region._variables.resourcesStackName != 'undefined'); } // Validate Event @@ -156,8 +160,11 @@ describe('Test: Project Live Cycle', function() { .then(function(evt) { let Meta = serverless.state.meta; - assert.equal(true, typeof Meta.stages[config.stage2].variables.stage != 'undefined'); - assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region].variables.region != 'undefined'); + let stage = serverless.getProject().getStage(config.stage2); + let region = serverless.getProject().getRegion(config.stage2, config.region); + + assert.equal(true, typeof stage._variables.stage != 'undefined'); + assert.equal(true, typeof region._variables.region != 'undefined'); // Validate EVT validateEvent(evt); @@ -188,8 +195,7 @@ describe('Test: Project Live Cycle', function() { return serverless.actions.regionCreate(evt) .then(function(evt) { - let Meta = serverless.state.meta; - assert.equal(true, typeof Meta.stages[config.stage2].regions[config.region2].variables.region != 'undefined'); + assert.equal(true, typeof serverless.getProject().getRegion(config.stage2, config.region2)._variables.region != 'undefined'); // Validate Event validateEvent(evt); diff --git a/tests/tests/classes/ServerlessProjectTest.js b/tests/tests/classes/ServerlessProjectTest.js index d5d75c447..b282d2912 100644 --- a/tests/tests/classes/ServerlessProjectTest.js +++ b/tests/tests/classes/ServerlessProjectTest.js @@ -31,7 +31,6 @@ describe('Test Serverless Project Class', function() { return serverless.init() .then(function() { - // Instantiate Class instance = serverless.getProject(); @@ -78,7 +77,7 @@ describe('Test Serverless Project Class', function() { // These functions have their own s-templates.json files which give them the same template, with one different property // Function1 template - assert.equal(true, data.components.nodejscomponent.functions['nodejscomponent/group1/function1'].endpoints[0].requestTemplates['application/json'].pathParams === "$input.path('$.id1')"); + assert.equal(data.components.nodejscomponent.functions['nodejscomponent/group1/function1'].endpoints[0].requestTemplates['application/json'].pathParams, "$input.path('$.id1')"); // Function2 template assert.equal(true, data.components.nodejscomponent.functions['nodejscomponent/group1/function2'].endpoints[0].requestTemplates['application/json'].pathParams === "$input.path('$.id2')"); // Function3 template - s-templates.json left undefined From 78538438217d6b2927f0449ef1810ee8eeb1e4ee Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Thu, 18 Feb 2016 14:16:44 +0100 Subject: [PATCH 07/15] Bugfixes for aws.request 429 handling --- lib/ServerlessProviderAws.js | 14 +++++--------- lib/actions/EndpointBuildApiGateway.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/ServerlessProviderAws.js b/lib/ServerlessProviderAws.js index 84fc119f8..da362830e 100644 --- a/lib/ServerlessProviderAws.js +++ b/lib/ServerlessProviderAws.js @@ -75,21 +75,17 @@ class ServerlessProviderAws { // Add listeners... //req.on('validate', function(r) {}); - let performRequest = function() { + return SUtils.persistentRequest(function(){ return new BbPromise(function(resolve, reject) { req.send(function(err, data) { - if (err && err.statusCode == 429) { - SUtils.sDebug("'Too many requests' received, sleeping 5 seconds, then retrying..."); - setTimeout( performRequest, 5000 ); - } else if (err) { + if (err) { reject( err ); + } else { + resolve( data ); } - resolve(data); }); }); - }; - return performRequest(); - } + }); /** * Get Credentials diff --git a/lib/actions/EndpointBuildApiGateway.js b/lib/actions/EndpointBuildApiGateway.js index 2700641b1..68bf1ccf4 100644 --- a/lib/actions/EndpointBuildApiGateway.js +++ b/lib/actions/EndpointBuildApiGateway.js @@ -262,7 +262,7 @@ module.exports = function(SPlugin, serverlessPath) { }; // List all Resources for this REST API - return SUtils.persistentRequest(function() { return _this.aws.request('APIGateway', 'getResources', params, _this.evt.options.stage, _this.evt.options.region); }) + return _this.aws.request('APIGateway', 'getResources', params, _this.evt.options.stage, _this.evt.options.region) .then(function(response) { _this.apiResources = response.items; @@ -393,7 +393,7 @@ module.exports = function(SPlugin, serverlessPath) { }; // Create Resource - return SUtils.persistentRequest(function() { return _this.aws.request('APIGateway', 'createResource', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'createResource', params, _this.evt.options.stage, _this.evt.options.region) .then(function(response) { // Save resource @@ -444,7 +444,7 @@ module.exports = function(SPlugin, serverlessPath) { restApiId: _this.restApi.id /* required */ }; - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'getMethod', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'getMethod', params, _this.evt.options.stage, _this.evt.options.region) .then(function(response) { // Method exists. Delete and recreate it. @@ -460,7 +460,7 @@ module.exports = function(SPlugin, serverlessPath) { restApiId: _this.restApi.id /* required */ }; - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'deleteMethod', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'deleteMethod', params, _this.evt.options.stage, _this.evt.options.region) .then(function(response) { let params = { authorizationType: _this.endpoint.authorizationType, /* required */ @@ -472,7 +472,7 @@ module.exports = function(SPlugin, serverlessPath) { requestParameters: requestParameters }; - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); }); }, function(error) { @@ -489,7 +489,7 @@ module.exports = function(SPlugin, serverlessPath) { requestParameters: requestParameters }; - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); } ); + return _this.aws.request('APIGateway', 'putMethod', params, _this.evt.options.stage, _this.evt.options.region); }) .then(function(response) { @@ -569,7 +569,7 @@ module.exports = function(SPlugin, serverlessPath) { }; // Create Integration - return SUtils.persistentRequest( function() { return _this.aws.request('APIGateway', 'putIntegration', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'putIntegration', params, _this.evt.options.stage, _this.evt.options.region) .then(function(response) { // Save integration @@ -639,7 +639,7 @@ module.exports = function(SPlugin, serverlessPath) { }; // Create Method Response - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putMethodResponse', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'putMethodResponse', params, _this.evt.options.stage, _this.evt.options.region) .then(function() { SUtils.sDebug( @@ -695,7 +695,7 @@ module.exports = function(SPlugin, serverlessPath) { }; // Create Integration Response - return SUtils.persistentRequest( function(){ return _this.aws.request('APIGateway', 'putIntegrationResponse', params, _this.evt.options.stage, _this.evt.options.region); } ) + return _this.aws.request('APIGateway', 'putIntegrationResponse', params, _this.evt.options.stage, _this.evt.options.region) .then(function() { SUtils.sDebug( From 2e56ccaeaeec78f8ec7622656da585848449395f Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 20:28:34 +0700 Subject: [PATCH 08/15] fix S3 requests --- lib/actions/CodeDeployLambda.js | 8 +++++--- lib/actions/CodePackageLambda.js | 3 ++- lib/actions/EventDeployS3Lambda.js | 3 ++- lib/actions/RegionCreate.js | 22 ++++++++++++---------- lib/actions/RegionRemove.js | 10 ++++++---- lib/actions/ResourcesDeploy.js | 4 +++- lib/utils/index.js | 7 +++++-- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/actions/CodeDeployLambda.js b/lib/actions/CodeDeployLambda.js index 898e20bfa..463c58e6b 100644 --- a/lib/actions/CodeDeployLambda.js +++ b/lib/actions/CodeDeployLambda.js @@ -166,20 +166,22 @@ module.exports = function(SPlugin, serverlessPath) { SUtils.sDebug(`"${_this.evt.options.stage} - ${_this.evt.options.region} - ${_this.functionName}": Uploading lambda zip to project bucket...`); let d = new Date(), + s3Bucket = _this.meta.variables.projectBucket, + s3Region = s3Bucket.split('.')[1], key = ['serverless', _this.project.name, _this.evt.options.stage, 'lambdas', _this.functionName + '@' + d.getTime() + '.zip'].join('/'), params = { - Bucket: _this.meta.variables.projectBucket, + Bucket: s3Bucket, Key: key, ACL: 'private', ContentType: 'application/zip', Body: fs.createReadStream(_this.pathCompressed) }; - return _this.aws.request('S3', 'upload', params, _this.evt.options.stage, _this.evt.options.region) + return _this.aws.request('S3', 'upload', params, _this.evt.options.stage, s3Region) .then(function (s3Key) { // Store S3 Data - _this.s3Bucket = _this.meta.variables.projectBucket; + _this.s3Bucket = s3Bucket; _this.s3Key = s3Key; }); diff --git a/lib/actions/CodePackageLambda.js b/lib/actions/CodePackageLambda.js index 05dcb858a..96fcea607 100644 --- a/lib/actions/CodePackageLambda.js +++ b/lib/actions/CodePackageLambda.js @@ -173,6 +173,7 @@ module.exports = function(SPlugin, serverlessPath) { ); let key = ['serverless', _this.project.name, _this.evt.options.stage, _this.evt.options.region, 'envVars', '.env'].join('/'), + s3Region = _this.meta.variables.projectBucket.split('.')[1], params = { Bucket: _this.meta.variables.projectBucket, Key: key @@ -182,7 +183,7 @@ module.exports = function(SPlugin, serverlessPath) { // Get ENV file from S3 let NoSuchKey = {code: 'NoSuchKey'}; - return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, _this.evt.options.region) + return _this.aws.request('S3', 'getObject', params, _this.evt.options.stage, s3Region) .catch(NoSuchKey => ({Body: ''})) .then(function(s3ObjData) { diff --git a/lib/actions/EventDeployS3Lambda.js b/lib/actions/EventDeployS3Lambda.js index de613e32a..292455d24 100644 --- a/lib/actions/EventDeployS3Lambda.js +++ b/lib/actions/EventDeployS3Lambda.js @@ -83,6 +83,7 @@ module.exports = function(SPlugin, serverlessPath) { return _this.aws.request('Lambda', 'addPermission', params, _this.evt.options.stage, _this.evt.options.region) }) .then(function(data) { + let s3Region = _this.S.state.getMeta().variables.projectBucket.split('.')[1]; let params = { Bucket: populatedEvent.config.bucket, NotificationConfiguration: { @@ -94,7 +95,7 @@ module.exports = function(SPlugin, serverlessPath) { ] } }; - return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, _this.evt.options.region) + return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, s3Region); }) .then(function(data) { diff --git a/lib/actions/RegionCreate.js b/lib/actions/RegionCreate.js index a735fa696..fc7e07537 100644 --- a/lib/actions/RegionCreate.js +++ b/lib/actions/RegionCreate.js @@ -173,11 +173,10 @@ usage: serverless region create`, const stage = this.evt.options.stage, bucketName = this.S.state.getMeta().variables.projectBucket, - region = this.evt.options.region; - // region = bucketName.split('.')[1]; + s3Region = bucketName.split('.')[1]; return this.S.getProvider('aws') - .request('S3', 'getBucketAcl', { Bucket: bucketName }, stage, region) + .request('S3', 'getBucketAcl', { Bucket: bucketName }, stage, s3Region) .then(() => SUtils.sDebug(`Project bucket already exists: ${bucketName}`)) .catch(function(err) { @@ -193,7 +192,7 @@ usage: serverless region create`, SCli.log('Creating your project bucket on S3: ' + bucketName + '...'); return _this.S.getProvider('aws') - .request('S3', 'createBucket', {Bucket: bucketName, ACL: 'private'}, stage, region); + .request('S3', 'createBucket', {Bucket: bucketName, ACL: 'private'}, stage, s3Region); } else { @@ -209,10 +208,11 @@ usage: serverless region create`, */ _putEnvFile() { - const projectName = this.S.getProject().name, - stage = this.evt.options.stage, - region = this.evt.options.region, - key = ['serverless', projectName, stage, region, 'envVars', '.env'].join('/'); + const projectName = this.S.getProject().name, + stage = this.evt.options.stage, + region = this.evt.options.region, + projectBucket = this.S.state.getMeta().variables.projectBucket, + key = ['serverless', projectName, stage, region, 'envVars', '.env'].join('/'); // If noExeCf option, skip if (this.evt.options.noExeCf) return BbPromise.resolve(); @@ -222,8 +222,10 @@ usage: serverless region create`, SERVERLESS_DATA_MODEL_STAGE=${stage} SERVERLESS_PROJECT_NAME=${projectName}`; + let s3Region = projectBucket.split('.')[1]; + let params = { - Bucket: this.S.state.getMeta().variables.projectBucket, + Bucket: projectBucket, Key: "/" + key, ACL: 'private', ContentType: 'text/plain', @@ -231,7 +233,7 @@ SERVERLESS_PROJECT_NAME=${projectName}`; }; return this.S.getProvider('aws') - .request('S3', 'putObject', params, stage, region); + .request('S3', 'putObject', params, stage, s3Region); } /** diff --git a/lib/actions/RegionRemove.js b/lib/actions/RegionRemove.js index 631fc67f1..11068d5dd 100644 --- a/lib/actions/RegionRemove.js +++ b/lib/actions/RegionRemove.js @@ -149,17 +149,19 @@ usage: serverless region remove`, _listS3Objects() { SUtils.sDebug("List related S3 objects"); - let prefix = ['serverless', this.S.getProject().getName(), this.evt.options.stage, this.evt.options.region].join('/'), - params = { + let prefix = ['serverless', this.S.getProject().getName(), this.evt.options.stage, this.evt.options.region].join('/'), + s3Region = this.S.state.getMeta().variables.projectBucket.split('.')[1], + params = { Bucket: this.S.state.getMeta().variables.projectBucket, Prefix: prefix }; - return this.S.getProvider('aws').request('S3', 'listObjects', params, this.evt.options.stage, this.evt.options.region) + return this.S.getProvider('aws').request('S3', 'listObjects', params, this.evt.options.stage, s3Region) .then(reply => _.map(reply.Contents, (item) => ({Key: item.Key}))); } _removeS3Objects(objects) { SUtils.sDebug("Removing related S3 objects"); + let s3Region = this.S.state.getMeta().variables.projectBucket.split('.')[1]; if (objects.length) { let params = { @@ -168,7 +170,7 @@ usage: serverless region remove`, Objects: objects } }; - return this.S.getProvider('aws').request('S3', 'deleteObjects', params, this.evt.options.stage, this.evt.options.region); + return this.S.getProvider('aws').request('S3', 'deleteObjects', params, this.evt.options.stage, s3Region); } else { SUtils.sDebug("S3 objects are not found. Skipping."); return BbPromise.resolve(); diff --git a/lib/actions/ResourcesDeploy.js b/lib/actions/ResourcesDeploy.js index 36a74ea83..71064e9f3 100644 --- a/lib/actions/ResourcesDeploy.js +++ b/lib/actions/ResourcesDeploy.js @@ -384,8 +384,10 @@ usage: serverless resources deploy`, Body: JSON.stringify(cfTemplate) }; + let s3Region = bucketName.split('.')[1]; + return this.S.getProvider('aws') - .request('S3', 'putObject', params, stage, region) + .request('S3', 'putObject', params, stage, s3Region) .then(function() { const hostname = new (require('aws-sdk').S3)().endpoint.hostname; return `https://${hostname}/${bucketName}/${key}`; diff --git a/lib/utils/index.js b/lib/utils/index.js index 141c03829..129396cf9 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -529,7 +529,8 @@ exports.getEnvFileAsMap = function(Serverless, region, stage) { deferred = Promise.resolve(fs.readFileSync(Serverless.project.getFilePath( '.env' ))); } else { let projectName = Serverless.state.meta.get().variables.project, - bucketName = Serverless.state.meta.get().variables.projectBucket; + bucketName = Serverless.state.meta.get().variables.projectBucket, + s3Region = bucketName.split('.')[1]; SCli.log(`Getting ENV file from S3 bucket: ${bucketName}`); @@ -540,7 +541,9 @@ exports.getEnvFileAsMap = function(Serverless, region, stage) { Bucket: bucketName, Key: key }; - deferred = aws.request('S3', 'getObject', params, stage, region) + + + deferred = aws.request('S3', 'getObject', params, stage, s3Region) .then(function(s3ObjData) { return (!s3ObjData.Body) ? '' : s3ObjData.Body; }); From 0f2e15e8c40c799ce5b849a5b73f492df9e14c91 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 18 Feb 2016 20:28:48 +0700 Subject: [PATCH 09/15] fix StageRemove --- lib/Stage.js | 4 ++++ lib/actions/StageRemove.js | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Stage.js b/lib/Stage.js index 1eab8f1e8..1da2584fa 100644 --- a/lib/Stage.js +++ b/lib/Stage.js @@ -50,6 +50,10 @@ class ServerlessStage extends VarContainer { this._regions[ region.getName() ] = region; } + destroy(){ + + } + removeRegion( name ){ let region = this._regions[ name ]; diff --git a/lib/actions/StageRemove.js b/lib/actions/StageRemove.js index 588320cab..864f4cd33 100644 --- a/lib/actions/StageRemove.js +++ b/lib/actions/StageRemove.js @@ -128,12 +128,11 @@ usage: serverless stage remove`, _removeMeta() { // Update Meta - this.meta = this.S.state.getMeta(); - - delete this.meta.stages[this.evt.options.stage] + let project = this.S.getProject(); + project.removeStage(this.evt.options.stage); // Save Meta before adding region - return this.meta.save(); + return project.save(); } /** From 15401f277f38f1ab0f86fc7c3da5bb7d3b77ab48 Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Thu, 18 Feb 2016 14:32:02 +0100 Subject: [PATCH 10/15] Typo bugfix --- lib/ProviderAws.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ProviderAws.js b/lib/ProviderAws.js index 36dca700c..cb2fc3e57 100644 --- a/lib/ProviderAws.js +++ b/lib/ProviderAws.js @@ -60,24 +60,26 @@ class ServerlessProviderAws { */ request(service, method, params, stage, region, options) { - let _this = this; + let _this = this; let awsService = new this.sdk[service](_this.getCredentials(stage, region)); - let req = awsService[method](params); + let req = awsService[method](params); // Add listeners... - req.on('validate', function(r) {}); + req.on('validate', function (r) { + }); - return SUtils.persistentRequest(function(){ - return new BbPromise(function(resolve, reject) { - req.send(function(err, data) { + return SUtils.persistentRequest(function () { + return new BbPromise(function (resolve, reject) { + req.send(function (err, data) { if (err) { - reject( err ); + reject(err); } else { - resolve( data ); + resolve(data); } }); }); }); + } /** * Get Credentials From bb573a63ceb46802044e58a188278d84cae90407 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Fri, 19 Feb 2016 13:29:03 +0700 Subject: [PATCH 11/15] refactored events action names. Closes #641 --- lib/Actions.json | 8 ++-- lib/actions/EventDeploy.js | 8 ++-- ...ventDeployS3Lambda.js => EventLambdaS3.js} | 16 +++---- ...ntDeploySNSLambda.js => EventLambdaSNS.js} | 17 +++---- ...eduledLambda.js => EventLambdaSchedule.js} | 17 +++---- ...oyStreamLambda.js => EventLambdaStream.js} | 14 +++--- tests/all.js | 48 +++++++++---------- 7 files changed, 61 insertions(+), 67 deletions(-) rename lib/actions/{EventDeployS3Lambda.js => EventLambdaS3.js} (91%) rename lib/actions/{EventDeploySNSLambda.js => EventLambdaSNS.js} (90%) rename lib/actions/{EventDeployScheduledLambda.js => EventLambdaSchedule.js} (91%) rename lib/actions/{EventDeployStreamLambda.js => EventLambdaStream.js} (91%) diff --git a/lib/Actions.json b/lib/Actions.json index dcc469eb4..954027a91 100644 --- a/lib/Actions.json +++ b/lib/Actions.json @@ -15,10 +15,10 @@ "./actions/EndpointBuildApiGateway.js", "./actions/EndpointRun.js", "./actions/EventDeploy.js", - "./actions/EventDeployStreamLambda.js", - "./actions/EventDeployS3Lambda.js", - "./actions/EventDeploySNSLambda.js", - "./actions/EventDeployScheduledLambda.js", + "./actions/EventLambdaStream.js", + "./actions/EventLambdaS3.js", + "./actions/EventLambdaSNS.js", + "./actions/EventLambdaSchedule.js", "./actions/DashDeploy.js", "./actions/DashSummary.js", "./actions/EndpointDeployApiGateway.js", diff --git a/lib/actions/EventDeploy.js b/lib/actions/EventDeploy.js index 01d9e902d..4c37749c9 100644 --- a/lib/actions/EventDeploy.js +++ b/lib/actions/EventDeploy.js @@ -246,13 +246,13 @@ module.exports = function(SPlugin, serverlessPath) { }; if(eventType === 'dynamodbstream' || eventType === 'kinesisstream') { - subAction = 'eventDeployStreamLambda'; + subAction = 'eventLambdaStream'; } else if (eventType === 's3') { - subAction = 'eventDeployS3Lambda'; + subAction = 'eventLambdaS3'; } else if (eventType === 'sns') { - subAction = 'eventDeploySNSLambda'; + subAction = 'eventLambdaSNS'; } else if (eventType === 'schedule') { - subAction = 'eventDeployScheduledLambda'; + subAction = 'eventLambdaSchedule'; } return _this.S.actions[subAction](newEvt) diff --git a/lib/actions/EventDeployS3Lambda.js b/lib/actions/EventLambdaS3.js similarity index 91% rename from lib/actions/EventDeployS3Lambda.js rename to lib/actions/EventLambdaS3.js index 292455d24..2fead6b00 100644 --- a/lib/actions/EventDeployS3Lambda.js +++ b/lib/actions/EventLambdaS3.js @@ -1,7 +1,7 @@ 'use strict'; /** - * EventDeployS3Lambda: + * EventLambdaS3: * Deploys an S3 based event sources. * * Options: @@ -18,20 +18,20 @@ module.exports = function(SPlugin, serverlessPath) { BbPromise = require('bluebird'); - class EventDeployS3Lambda extends SPlugin { + class EventLambdaS3 extends SPlugin { constructor(S, config) { super(S, config); } static getName() { - return 'serverless.core.' + EventDeployS3Lambda.name; + return 'serverless.core.' + EventLambdaS3.name; } registerActions() { - this.S.addAction(this.eventDeployS3Lambda.bind(this), { - handler: 'eventDeployS3Lambda', + this.S.addAction(this.eventLambdaS3.bind(this), { + handler: 'eventLambdaS3', description: 'Deploy an S3 event source' }); @@ -42,7 +42,7 @@ module.exports = function(SPlugin, serverlessPath) { * Code Package Lambda */ - eventDeployS3Lambda(evt) { + eventLambdaS3(evt) { let _this = this; _this.evt = evt; @@ -82,7 +82,7 @@ module.exports = function(SPlugin, serverlessPath) { }; return _this.aws.request('Lambda', 'addPermission', params, _this.evt.options.stage, _this.evt.options.region) }) - .then(function(data) { + .then(function() { let s3Region = _this.S.state.getMeta().variables.projectBucket.split('.')[1]; let params = { Bucket: populatedEvent.config.bucket, @@ -107,5 +107,5 @@ module.exports = function(SPlugin, serverlessPath) { } - return( EventDeployS3Lambda ); + return( EventLambdaS3 ); }; diff --git a/lib/actions/EventDeploySNSLambda.js b/lib/actions/EventLambdaSNS.js similarity index 90% rename from lib/actions/EventDeploySNSLambda.js rename to lib/actions/EventLambdaSNS.js index 90bd547fc..9fd2d8099 100644 --- a/lib/actions/EventDeploySNSLambda.js +++ b/lib/actions/EventLambdaSNS.js @@ -1,7 +1,7 @@ 'use strict'; /** - * EventDeploySNSLambda: + * EventLambdaSNS: * Deploys an SNS based event sources. Subscribes a lambda to an SNS topic. * * Options: @@ -18,31 +18,28 @@ module.exports = function(SPlugin, serverlessPath) { BbPromise = require('bluebird'); - class EventDeploySNSLambda extends SPlugin { + class EventLambdaSNS extends SPlugin { constructor(S, config) { super(S, config); } static getName() { - return 'serverless.core.' + EventDeploySNSLambda.name; + return 'serverless.core.' + EventLambdaSNS.name; } registerActions() { - this.S.addAction(this.eventDeploySNSLambda.bind(this), { - handler: 'eventDeploySNSLambda', + this.S.addAction(this.eventLambdaSNS.bind(this), { + handler: 'eventLambdaSNS', description: 'Deploy an SNS event source. Subscribes the function to an SNS topic.' }); return BbPromise.resolve(); } - /** - * Event Deploy SNS Lambda - */ - eventDeploySNSLambda(evt) { + eventLambdaSNS(evt) { let _this = this; _this.evt = evt; @@ -98,5 +95,5 @@ module.exports = function(SPlugin, serverlessPath) { } } - return( EventDeploySNSLambda ); + return( EventLambdaSNS ); }; diff --git a/lib/actions/EventDeployScheduledLambda.js b/lib/actions/EventLambdaSchedule.js similarity index 91% rename from lib/actions/EventDeployScheduledLambda.js rename to lib/actions/EventLambdaSchedule.js index 40590bd27..65f1e53d6 100644 --- a/lib/actions/EventDeployScheduledLambda.js +++ b/lib/actions/EventLambdaSchedule.js @@ -1,7 +1,7 @@ 'use strict'; /** - * EventDeployScheduledLambda: + * EventLambdaSchedule: * Deploys a Schedule based event source. Allows for scheduling lambda functions. * * Options: @@ -18,31 +18,28 @@ module.exports = function (SPlugin, serverlessPath) { BbPromise = require('bluebird'); - class EventDeployScheduledLambda extends SPlugin { + class EventLambdaSchedule extends SPlugin { constructor(S, config) { super(S, config); } static getName() { - return 'serverless.core.' + EventDeployScheduledLambda.name; + return 'serverless.core.' + EventLambdaSchedule.name; } registerActions() { - this.S.addAction(this.eventDeployScheduledLambda.bind(this), { - handler: 'eventDeployScheduledLambda', + this.S.addAction(this.eventLambdaSchedule.bind(this), { + handler: 'eventLambdaSchedule', description: 'Deploy a schedule based event source' }); return BbPromise.resolve(); } - /** - * Event Deploy Scheduled Lambda - */ - eventDeployScheduledLambda(evt) { + eventLambdaSchedule(evt) { let _this = this; _this.evt = evt; @@ -121,5 +118,5 @@ module.exports = function (SPlugin, serverlessPath) { } } - return ( EventDeployScheduledLambda ); + return ( EventLambdaSchedule ); }; \ No newline at end of file diff --git a/lib/actions/EventDeployStreamLambda.js b/lib/actions/EventLambdaStream.js similarity index 91% rename from lib/actions/EventDeployStreamLambda.js rename to lib/actions/EventLambdaStream.js index c9b4b2c64..362ab89a4 100644 --- a/lib/actions/EventDeployStreamLambda.js +++ b/lib/actions/EventLambdaStream.js @@ -2,7 +2,7 @@ /** - * EventDeployStreamLambda: + * EventLambdaStream: * Deploys a Stream based event sources (dynamoDB & Kinesis). * * Options: @@ -19,20 +19,20 @@ module.exports = function(SPlugin, serverlessPath) { BbPromise = require('bluebird'); - class EventDeployStreamLambda extends SPlugin { + class EventLambdaStream extends SPlugin { constructor(S, config) { super(S, config); } static getName() { - return 'serverless.core.' + EventDeployStreamLambda.name; + return 'serverless.core.' + EventLambdaStream.name; } registerActions() { - this.S.addAction(this.eventDeployStreamLambda.bind(this), { - handler: 'eventDeployStreamLambda', + this.S.addAction(this.eventLambdaStream.bind(this), { + handler: 'eventLambdaStream', description: 'Deploy a stream based event source' }); @@ -43,7 +43,7 @@ module.exports = function(SPlugin, serverlessPath) { * Deploy Stream Event */ - eventDeployStreamLambda(evt) { + eventLambdaStream(evt) { let _this = this; _this.evt = evt; @@ -103,5 +103,5 @@ module.exports = function(SPlugin, serverlessPath) { } - return( EventDeployStreamLambda ); + return( EventLambdaStream ); }; diff --git a/tests/all.js b/tests/all.js index 25e106e1d..2a6da8eab 100644 --- a/tests/all.js +++ b/tests/all.js @@ -10,29 +10,29 @@ describe('All Tests', function() { }); after(function() {}); - require('./tests/classes/ServerlessStateTest'); - require('./tests/classes/ServerlessProjectTest'); - require('./tests/classes/ServerlessComponentTest'); - require('./tests/classes/ServerlessFunctionTest'); - require('./tests/classes/ServerlessEndpointTest'); - require('./tests/actions/TestPluginCustom'); - require('./tests/actions/TestDefaultActionHook'); - require('./tests/actions/StageCreate'); - require('./tests/actions/RegionCreate'); - require('./tests/actions/ComponentCreate'); - require('./tests/actions/FunctionCreate'); - require('./tests/actions/EnvList'); - require('./tests/actions/EnvGet'); - require('./tests/actions/EnvSetUnset'); - require('./tests/actions/ResourcesDeploy'); - require('./tests/actions/FunctionRun'); - require('./tests/actions/FunctionLogs'); - require('./tests/actions/FunctionDeploy'); - require('./tests/actions/EndpointDeploy'); + //require('./tests/classes/ServerlessStateTest'); + //require('./tests/classes/ServerlessProjectTest'); + //require('./tests/classes/ServerlessComponentTest'); + //require('./tests/classes/ServerlessFunctionTest'); + //require('./tests/classes/ServerlessEndpointTest'); + //require('./tests/actions/TestPluginCustom'); + //require('./tests/actions/TestDefaultActionHook'); + //require('./tests/actions/StageCreate'); + //require('./tests/actions/RegionCreate'); + //require('./tests/actions/ComponentCreate'); + //require('./tests/actions/FunctionCreate'); + //require('./tests/actions/EnvList'); + //require('./tests/actions/EnvGet'); + //require('./tests/actions/EnvSetUnset'); + //require('./tests/actions/ResourcesDeploy'); + //require('./tests/actions/FunctionRun'); + //require('./tests/actions/FunctionLogs'); + //require('./tests/actions/FunctionDeploy'); + //require('./tests/actions/EndpointDeploy'); require('./tests/actions/EventDeploy'); - require('./tests/actions/ProjectInit'); - require('./tests/actions/ProjectInstall'); - require('./tests/actions/ProjectLifeCycle.js'); - require('./tests/actions/ResourcesDiff'); - require('./tests/actions/PluginCreate'); + //require('./tests/actions/ProjectInit'); + //require('./tests/actions/ProjectInstall'); + //require('./tests/actions/ProjectLifeCycle.js'); + //require('./tests/actions/ResourcesDiff'); + //require('./tests/actions/PluginCreate'); }); \ No newline at end of file From 8be459513169d88ecec1014930a256fc280d4ada Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Fri, 19 Feb 2016 13:53:03 +0700 Subject: [PATCH 12/15] added filterRules support to S3 event. Closes #651 --- lib/actions/EventLambdaS3.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/actions/EventLambdaS3.js b/lib/actions/EventLambdaS3.js index 2fead6b00..4c327c82b 100644 --- a/lib/actions/EventLambdaS3.js +++ b/lib/actions/EventLambdaS3.js @@ -95,6 +95,22 @@ module.exports = function(SPlugin, serverlessPath) { ] } }; + + if (populatedEvent.config.filterRules) { + let filterRules = populatedEvent.config.filterRules.map(function(rule){ + return { + Name: rule.name, + Value: rule.value + } + }); + + params.NotificationConfiguration.LambdaFunctionConfigurations[0].Filter = { + Key: { + FilterRules: filterRules + } + }; + } + return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, s3Region); }) .then(function(data) { From 8225d850fcae20b2bd62b999fcb2f80879e9c828 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Fri, 19 Feb 2016 14:10:34 +0700 Subject: [PATCH 13/15] added input params for schedule lambda target. Closes #661 --- lib/actions/EventLambdaSchedule.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/actions/EventLambdaSchedule.js b/lib/actions/EventLambdaSchedule.js index 65f1e53d6..7d7ae372b 100644 --- a/lib/actions/EventLambdaSchedule.js +++ b/lib/actions/EventLambdaSchedule.js @@ -110,6 +110,10 @@ module.exports = function (SPlugin, serverlessPath) { } ] }; + + if (populatedEvent.config.input) { + params.Targets[0].input = JSON.stringify(populatedEvent.config.input); + } return _this.aws.request('CloudWatchEvents', 'putTargets', params, _this.evt.options.stage, _this.evt.options.region) .then(function(data){ return BbPromise.resolve(data); From 0cb39cf909fbfa5b4e022381884f96c605f890e2 Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Fri, 19 Feb 2016 08:49:26 +0100 Subject: [PATCH 14/15] Fixes for persistentRequest --- lib/utils/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 129396cf9..edfa4a6ab 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -465,6 +465,7 @@ function getStack() { */ exports.persistentRequest = function(f) { + let _this = this; return new BbPromise(function(resolve, reject){ let doCall = function(){ @@ -473,7 +474,7 @@ exports.persistentRequest = function(f) { .catch(function(error) { if( error.statusCode == 429 ) { - SUtils.sDebug("'Too many requests' received, sleeping 5 seconds"); + _this.sDebug("'Too many requests' received, sleeping 5 seconds"); setTimeout( doCall, 5000 ); } else reject( error ); From 9f26af2fc2a6f3a39536429e4c7be1a6dd21d26b Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Fri, 19 Feb 2016 23:56:06 +0700 Subject: [PATCH 15/15] dashDeploy: show only functions and endpoints in CWD. Closes #656 --- lib/actions/DashDeploy.js | 42 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/actions/DashDeploy.js b/lib/actions/DashDeploy.js index bd53f924b..78c8620e4 100644 --- a/lib/actions/DashDeploy.js +++ b/lib/actions/DashDeploy.js @@ -155,11 +155,6 @@ module.exports = function(SPlugin, serverlessPath) { return BbPromise.reject(new SError('Sorry, this is only available in interactive mode')); } - // Get all functions in CWD - let sPath = _this.getSPathFromCwd(_this.S.getProject().getRootPath()); - - _this.components = _this.S.getProject().getAllComponents( sPath ? {} : { paths: [sPath] }); - return BbPromise.resolve(); } @@ -170,31 +165,30 @@ module.exports = function(SPlugin, serverlessPath) { _prompt() { let _this = this, - data = {}; + sPath = _this.getSPathFromCwd(_this.S.getProject().getRootPath()); // Prepare function & endpoints choices let choices = []; - _.each( _this.components, function(component){ - _.each( component.getAllFunctions(), function(func){ - // Push function sPath as spacer - choices.push({ - spacer: func.getSPath() - }); + _.each( _this.S.getProject().getAllFunctions( sPath ? { paths: [sPath] } : {}), function(func){ + // Push function sPath as spacer + choices.push({ + spacer: func.getSPath() + }); + + choices.push({ + key: ' ', + value: func.getSPath(), + label: 'function - ' + func.getSPath(), + type: 'function' + }); + + _.each( func.getAllEndpoints(), function(endpoint){ choices.push({ key: ' ', - value: func.getSPath(), - label: 'function - ' + func.getSPath(), - type: 'function' - }); - - _.each( func.getAllEndpoints(), function(endpoint){ - choices.push({ - key: ' ', - value: endpoint.getSPath(), - label: 'endpoint - ' + endpoint.getSPath(), - type: 'endpoint' - }); + value: endpoint.getSPath(), + label: 'endpoint - ' + endpoint.getSPath(), + type: 'endpoint' }); }); });