From b252846e1da4968465d01ab506f85f4da7bb6116 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 15 Jun 2017 04:21:18 +0900 Subject: [PATCH 01/81] Fix #3792: Resolve tabtab/src/cli.js path when installing locally --- scripts/postinstall.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index a684be441..3339ed1c6 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -5,6 +5,8 @@ const Serverless = require('../lib/Serverless'); const execSync = require('child_process').execSync; +const path = require('path'); +const fileExistsSync = require('../lib/utils/fs/fileExistsSync'); try { const serverless = new Serverless(); @@ -20,13 +22,17 @@ try { function setupAutocomplete() { return new Promise((resolve, reject) => { + let tabtabPath = './node_modules/tabtab'; + if (!fileExistsSync(path.join(__dirname, '..', 'node_modules', 'tabtab', 'src', 'cli.js'))) { + tabtabPath = '../tabtab'; + } try { - execSync('node ./node_modules/tabtab/src/cli.js install --name serverless --auto'); - execSync('node ./node_modules/tabtab/src/cli.js install --name sls --auto'); + execSync(`node ${tabtabPath}/src/cli.js install --name serverless --auto`); + execSync(`node ${tabtabPath}/src/cli.js install --name sls --auto`); return resolve(); } catch (error) { - execSync('node ./node_modules/tabtab/src/cli.js install --name serverless --stdout'); - execSync('node ./node_modules/tabtab/src/cli.js install --name sls --stdout'); + execSync(`node ${tabtabPath}/src/cli.js install --name serverless --stdout`); + execSync(`node ${tabtabPath}/src/cli.js install --name sls --stdout`); console.log('Could not auto-install serverless autocomplete script.'); console.log('Please copy / paste the script above into your shell.'); return reject(error); From 62ab8e09eac797692aa2ba8b4e90edea92a1e14c Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Tue, 20 Jun 2017 15:22:46 +0200 Subject: [PATCH 02/81] add environment variable support --- lib/plugins/platform/platform.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index a05a2e0e9..3761785cc 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -81,6 +81,10 @@ class Platform { } getAuthToken() { + if (process.env.SERVERLESS_PLATFORM_AUTH_TOKEN) { + return process.env.SERVERLESS_PLATFORM_AUTH_TOKEN; + } + const userConfig = configUtils.getConfig(); const currentId = userConfig.userId; const globalConfig = configUtils.getGlobalConfig(); From 569bb6901c83d3c3788884f6d14b31191cec95d3 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 21 Jun 2017 00:11:21 +0530 Subject: [PATCH 03/81] Add generateCommandsByPluginHelp() --- lib/classes/CLI.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 05698c36d..687123003 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -56,7 +56,11 @@ class CLI { if ((commands.length === 0) || (commands.length === 0 && (options.help || options.h)) || (commands.length === 1 && (commands.indexOf('help') > -1))) { - this.generateMainHelp(); + if (options.plugins || options.p) { + this.generateCommandsByPluginHelp(); + } else { + this.generateMainHelp(); + } return true; } @@ -145,6 +149,12 @@ class CLI { } } + generateCommandsByPluginHelp() { + this.consoleLog(''); + + this.consoleLog(chalk.yellow.underline('Commands by plugin')); + } + generateCommandsHelp(commandsArray) { const command = this.serverless.pluginManager.getCommand(commandsArray); const commandName = commandsArray.join(' '); From 084e6669bc7eee995ac33a1080b268bdec45b6da Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 21 Jun 2017 00:32:02 +0530 Subject: [PATCH 04/81] Format commands plugins help output with indents --- lib/classes/CLI.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 687123003..88e22f13f 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -72,18 +72,19 @@ class CLI { return false; } - displayCommandUsage(commandObject, command) { + displayCommandUsage(commandObject, command, indents = 0) { const dotsLength = 30; // check if command has lifecycleEvents (can be executed) if (commandObject.lifecycleEvents) { const usage = commandObject.usage; const dots = _.repeat('.', dotsLength - command.length); - this.consoleLog(`${chalk.yellow(command)} ${chalk.dim(dots)} ${usage}`); + const indent = _.repeat(' ', indents); + this.consoleLog(`${indent}${chalk.yellow(command)} ${chalk.dim(dots)} ${usage}`); } _.forEach(commandObject.commands, (subcommandObject, subcommand) => { - this.displayCommandUsage(subcommandObject, `${command} ${subcommand}`); + this.displayCommandUsage(subcommandObject, `${command} ${subcommand}`, indents); }); } @@ -153,6 +154,14 @@ class CLI { this.consoleLog(''); this.consoleLog(chalk.yellow.underline('Commands by plugin')); + + this.consoleLog(''); + + _.forEach(this.loadedCommands, (details, command) => { + this.consoleLog(details.pluginName); + this.displayCommandUsage(details, command, 1); + this.consoleLog(''); + }); } generateCommandsHelp(commandsArray) { From e68450f5b54e8f3d8d48f4690159efc257ed413f Mon Sep 17 00:00:00 2001 From: k1LoW Date: Wed, 21 Jun 2017 20:30:29 +0900 Subject: [PATCH 05/81] Use require.resolve() --- scripts/postinstall.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 3339ed1c6..0bc960518 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -6,7 +6,6 @@ const Serverless = require('../lib/Serverless'); const execSync = require('child_process').execSync; const path = require('path'); -const fileExistsSync = require('../lib/utils/fs/fileExistsSync'); try { const serverless = new Serverless(); @@ -22,10 +21,7 @@ try { function setupAutocomplete() { return new Promise((resolve, reject) => { - let tabtabPath = './node_modules/tabtab'; - if (!fileExistsSync(path.join(__dirname, '..', 'node_modules', 'tabtab', 'src', 'cli.js'))) { - tabtabPath = '../tabtab'; - } + const tabtabPath = require.resolve('tabtab').replace(/\/index.js$/, ''); try { execSync(`node ${tabtabPath}/src/cli.js install --name serverless --auto`); execSync(`node ${tabtabPath}/src/cli.js install --name sls --auto`); From fa5e5d443d12f57abf89700f8e74a37faf685f03 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Wed, 21 Jun 2017 20:45:14 +0900 Subject: [PATCH 06/81] Remove unneccessary module require --- scripts/postinstall.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 0bc960518..9eb4fba38 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -5,7 +5,6 @@ const Serverless = require('../lib/Serverless'); const execSync = require('child_process').execSync; -const path = require('path'); try { const serverless = new Serverless(); From 1aca36020c14b1522dc436447632c11e4ec53e5d Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 21 Jun 2017 17:58:33 +0530 Subject: [PATCH 07/81] Extract, sort and display plugin commands & test --- lib/classes/CLI.js | 43 ++++++++++++++++++++++++++++++++++++++--- lib/classes/CLI.test.js | 12 ++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 88e22f13f..45565c391 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -157,9 +157,46 @@ class CLI { this.consoleLog(''); - _.forEach(this.loadedCommands, (details, command) => { - this.consoleLog(details.pluginName); - this.displayCommandUsage(details, command, 1); + let pluginCommands = {}; + + // Add commands to pluginCommands based on command's plugin + const addToPluginCommands = (cmd) => { + const pcmd = _.clone(cmd); + + // Remove subcommand from clone + delete pcmd.commands; + + // Check if a plugin entry is alreay present in pluginCommands. Use the + // existing one or create a new plugin entry. + if (_.has(pluginCommands, pcmd.pluginName)) { + pluginCommands[pcmd.pluginName] = pluginCommands[pcmd.pluginName].concat(pcmd); + } else { + pluginCommands[pcmd.pluginName] = [pcmd]; + } + + // Check for subcommands + if ('commands' in cmd) { + _.forEach(cmd.commands, (d) => { + addToPluginCommands(d); + }); + } + }; + + // Fill up pluginCommands with commands in loadedCommands + _.forEach(this.loadedCommands, (details) => { + addToPluginCommands(details); + }); + + // Sort plugins alphabetically + pluginCommands = _(pluginCommands).toPairs().sortBy(0).fromPairs() + .value(); + + _.forEach(pluginCommands, (details, plugin) => { + this.consoleLog(plugin); + _.forEach(details, (cmd) => { + // Display command usage with single(1) indent + this.displayCommandUsage(cmd, cmd.key.split(':').join(' '), 1); + }); this.consoleLog(''); }); } diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 3a1d6b326..42ce2263e 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -352,5 +352,17 @@ describe('CLI', () => { done(); }); }); + + it('should print sorted plugin commands --help --plugins', (done) => { + exec(`${this.serverlessExec} --help --plugins`, (err, stdout) => { + if (err) { + done(err); + return; + } + + expect(stdout).to.contain('Commands by plugin'); + done(); + }); + }); }); }); From 501aa5d5bc1db13a198d201c3f95952d700099d3 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 21 Jun 2017 19:27:15 +0530 Subject: [PATCH 08/81] Avoid default function parameter --- lib/classes/CLI.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 45565c391..f68577d1a 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -72,14 +72,14 @@ class CLI { return false; } - displayCommandUsage(commandObject, command, indents = 0) { + displayCommandUsage(commandObject, command, indents) { const dotsLength = 30; // check if command has lifecycleEvents (can be executed) if (commandObject.lifecycleEvents) { const usage = commandObject.usage; const dots = _.repeat('.', dotsLength - command.length); - const indent = _.repeat(' ', indents); + const indent = _.repeat(' ', indents || 0); this.consoleLog(`${indent}${chalk.yellow(command)} ${chalk.dim(dots)} ${usage}`); } From 83255261b5d42eca297cb96e33f7ca05d4a83235 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 22 Jun 2017 15:00:34 +0200 Subject: [PATCH 09/81] change env variable --- lib/plugins/platform/platform.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index 3761785cc..802258f97 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -81,8 +81,8 @@ class Platform { } getAuthToken() { - if (process.env.SERVERLESS_PLATFORM_AUTH_TOKEN) { - return process.env.SERVERLESS_PLATFORM_AUTH_TOKEN; + if (process.env.SERVERLESS_TOKEN) { + return process.env.SERVERLESS_TOKEN; } const userConfig = configUtils.getConfig(); From f4eac4bfaee72f9e95233e43cb096f61546b522d Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Fri, 23 Jun 2017 11:46:50 +0200 Subject: [PATCH 10/81] Fix AWS API Gateway request parameters docs --- docs/providers/aws/events/apigateway.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index 81a118a32..d299fc7f3 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -354,7 +354,6 @@ functions: url: true headers: foo: false - bar: true paths: bar: false ``` From a6b297aa75af50108c1a40bf63b99a9177073fc7 Mon Sep 17 00:00:00 2001 From: "Christopher \"Chief\" Najewicz" Date: Fri, 23 Jun 2017 08:45:55 -0400 Subject: [PATCH 11/81] Update web-actions.md docs w/ correct URL --- docs/providers/openwhisk/guide/web-actions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/providers/openwhisk/guide/web-actions.md b/docs/providers/openwhisk/guide/web-actions.md index 599c0ce43..86d366e8c 100644 --- a/docs/providers/openwhisk/guide/web-actions.md +++ b/docs/providers/openwhisk/guide/web-actions.md @@ -12,7 +12,7 @@ layout: Doc # OpenWhisk - Web Actions -Functions can be turned into ["*web actions*"](https://github.com/openwhisk/openwhisk/blob/master/docs/actions.md) which return HTTP content without use of an API Gateway. This feature is enabled by setting an annotation (`web-export`) in the configuration file. +Functions can be turned into ["*web actions*"](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md) which return HTTP content without use of an API Gateway. This feature is enabled by setting an annotation (`web-export`) in the configuration file. ``` functions: @@ -73,4 +73,4 @@ Functions can access request parameters using the following environment variable Full details on this new feature are available in this [blog post](https://medium.com/openwhisk/serverless-http-handlers-with-openwhisk-90a986cc7cdd#.2x09176m8). -**\*IMPORTANT: [Web Actions](https://github.com/openwhisk/openwhisk/blob/master/docs/actions.md) is currently experimental and may be subject to breaking changes.*** +**\*IMPORTANT: [Web Actions](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md) is currently experimental and may be subject to breaking changes.*** From d381106b8e176fcb82690c99740ecbede2450668 Mon Sep 17 00:00:00 2001 From: Simon Dittlmann Date: Sat, 24 Jun 2017 01:18:40 +0200 Subject: [PATCH 12/81] fix: correct misspelled eventType value --- docs/providers/google/events/event.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/providers/google/events/event.md b/docs/providers/google/events/event.md index a3e86159d..b96c5ec2e 100644 --- a/docs/providers/google/events/event.md +++ b/docs/providers/google/events/event.md @@ -26,7 +26,7 @@ functions: handler: pubSub events: - event: - eventType: providers/cloud.pubsub/eventTypes/topics.publish + eventType: providers/cloud.pubsub/eventTypes/topic.publish resource: projects/*/topics/my-topic ``` From d2644f92a50fd6c054ae216039e3707e0d8b30ee Mon Sep 17 00:00:00 2001 From: Scott Willeke Date: Fri, 23 Jun 2017 16:20:50 -0700 Subject: [PATCH 13/81] Improves error message to include function name when path isn't indented under the path in yml. --- .../compile/events/apiGateway/lib/validate.js | 2 +- .../events/apiGateway/lib/validate.test.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js index 97f99637f..e0f9ed042 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -150,7 +150,7 @@ module.exports = { }, getHttpPath(http, functionName) { - if (typeof http.path === 'string') { + if (http && typeof http.path === 'string') { return http.path.replace(/^\//, '').replace(/\/$/, ''); } const errorMessage = [ diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js index 7ead5365f..96022354b 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js @@ -61,6 +61,23 @@ describe('#validate()', () => { expect(() => awsCompileApigEvents.validate()).to.throw(Error); }); + it('should throw a helpful error if http event type object doesn\'t have a path property', () => { + /** + * This can happen with surprising subtle syntax error such as when path is not indented under http in the yml + */ + awsCompileApigEvents.serverless.service.functions = { + first: { + events: [ + { + http: null + }, + ], + }, + }; + + expect(() => awsCompileApigEvents.validate()).to.throw(/Missing or invalid "path" property in function "first"/); + }); + it('should validate the http events "path" property', () => { awsCompileApigEvents.serverless.service.functions = { first: { From 18f7521393f0a38a3b66dcce041757d30b386261 Mon Sep 17 00:00:00 2001 From: davidwells Date: Fri, 23 Jun 2017 16:40:26 -0700 Subject: [PATCH 14/81] Update console output on successful publish --- lib/plugins/platform/platform.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index 802258f97..9b4383e90 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -7,6 +7,7 @@ const jwtDecode = require('jwt-decode'); const BbPromise = require('bluebird'); const fsExtra = require('../../utils/fs/fse'); const fetch = require('node-fetch'); +const chalk = require('chalk'); const configUtils = require('../../utils/config'); const functionInfoUtils = require('../../utils/functionInfoUtils'); const createApolloClient = require('../../utils/createApolloClient'); @@ -162,7 +163,8 @@ class Platform { const username = jwtDecode(authToken).nickname; const serviceName = this.serverless.service.service; const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - this.serverless.cli.log(`Your service is available at ${url}`); + console.log('Service sucessfully published! Your service details are available at:'); // eslint-disable-line + console.log(chalk.green(url)); // eslint-disable-line }) .catch(error => { this.serverless.cli.log( From b44d70074b957ca9a5bdf184f049bf4a5553b953 Mon Sep 17 00:00:00 2001 From: davidwells Date: Fri, 23 Jun 2017 16:42:37 -0700 Subject: [PATCH 15/81] speeling is hard --- lib/plugins/platform/platform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index 9b4383e90..43b84e054 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -163,7 +163,7 @@ class Platform { const username = jwtDecode(authToken).nickname; const serviceName = this.serverless.service.service; const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - console.log('Service sucessfully published! Your service details are available at:'); // eslint-disable-line + console.log('Service successfully published! Your service details are available at:'); // eslint-disable-line console.log(chalk.green(url)); // eslint-disable-line }) .catch(error => { From 43201271882ba963862a7bdcf9b5bcaf418c2088 Mon Sep 17 00:00:00 2001 From: Scott Willeke Date: Fri, 23 Jun 2017 16:54:15 -0700 Subject: [PATCH 16/81] fixes linting errors as part of #3845 --- .../compile/events/apiGateway/lib/validate.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js index 96022354b..6206c757b 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js @@ -63,20 +63,22 @@ describe('#validate()', () => { it('should throw a helpful error if http event type object doesn\'t have a path property', () => { /** - * This can happen with surprising subtle syntax error such as when path is not indented under http in the yml + * This can happen with surprising subtle syntax error such as when path is not + * indented under http in yml. */ awsCompileApigEvents.serverless.service.functions = { first: { events: [ { - http: null + http: null, }, ], }, }; - expect(() => awsCompileApigEvents.validate()).to.throw(/Missing or invalid "path" property in function "first"/); - }); + expect(() => awsCompileApigEvents.validate()).to + .throw(/invalid "path" property in function "first"/); + }); it('should validate the http events "path" property', () => { awsCompileApigEvents.serverless.service.functions = { From aab58ad7e80f48f74ffcf27ae62a4fec85b2b096 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Sun, 18 Dec 2016 12:04:51 +0000 Subject: [PATCH 17/81] Add aws-fsharp template --- docs/providers/aws/cli-reference/create.md | 1 + docs/providers/aws/guide/services.md | 1 + lib/plugins/create/create.js | 1 + .../create/templates/aws-fsharp/.gitignore | 246 ++++++++++++++++++ .../create/templates/aws-fsharp/Handler.fs | 17 ++ .../create/templates/aws-fsharp/build.sh | 14 + .../create/templates/aws-fsharp/global.json | 6 + .../create/templates/aws-fsharp/project.json | 43 +++ .../templates/aws-fsharp/serverless.yml | 84 ++++++ 9 files changed, 413 insertions(+) create mode 100644 lib/plugins/create/templates/aws-fsharp/.gitignore create mode 100644 lib/plugins/create/templates/aws-fsharp/Handler.fs create mode 100644 lib/plugins/create/templates/aws-fsharp/build.sh create mode 100644 lib/plugins/create/templates/aws-fsharp/global.json create mode 100644 lib/plugins/create/templates/aws-fsharp/project.json create mode 100644 lib/plugins/create/templates/aws-fsharp/serverless.yml diff --git a/docs/providers/aws/cli-reference/create.md b/docs/providers/aws/cli-reference/create.md index 4cbca6f09..6d2a2296c 100644 --- a/docs/providers/aws/cli-reference/create.md +++ b/docs/providers/aws/cli-reference/create.md @@ -48,6 +48,7 @@ Most commonly used templates: - aws-java-gradle - aws-scala-sbt - aws-csharp +- aws-fsharp - plugin ## Examples diff --git a/docs/providers/aws/guide/services.md b/docs/providers/aws/guide/services.md index ee776f9e2..dd96c4c24 100644 --- a/docs/providers/aws/guide/services.md +++ b/docs/providers/aws/guide/services.md @@ -58,6 +58,7 @@ Here are the available runtimes for AWS Lambda: * aws-java-maven * aws-scala-sbt * aws-csharp +* aws-fsharp Check out the [create command docs](../cli-reference/create) for all the details and options. diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index 7851a43a8..eb62cc843 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -16,6 +16,7 @@ const validTemplates = [ 'aws-java-gradle', 'aws-scala-sbt', 'aws-csharp', + 'aws-fsharp', 'azure-nodejs', 'openwhisk-nodejs', 'openwhisk-python', diff --git a/lib/plugins/create/templates/aws-fsharp/.gitignore b/lib/plugins/create/templates/aws-fsharp/.gitignore new file mode 100644 index 000000000..4dc157e7f --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/.gitignore @@ -0,0 +1,246 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ +*.orig + +# macOS +.DS_Store + +# JetBrains Rider C# IDE +.idea* + +# Serverless directories +.serverless diff --git a/lib/plugins/create/templates/aws-fsharp/Handler.fs b/lib/plugins/create/templates/aws-fsharp/Handler.fs new file mode 100644 index 000000000..b9e1806fe --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/Handler.fs @@ -0,0 +1,17 @@ +namespace AwsDotnetFsharp +open Amazon.Lambda.Core + +[)>] +do () + +type Request = { Key1 : string; Key2 : string; Key3 : string } +type Response = { Message : string; Request : Request } + +module Handler = + open System + open System.IO + open System.Text + + let hello(request:Request) = + { Message="Go Serverless v1.0! Your function executed successfully!" + Request=request } \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh new file mode 100644 index 000000000..c97689e0b --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +#build handlers +dotnet restore +dotnet publish -c release + +#install zip +apt-get -qq update +apt-get -qq -y install zip + +#create deployment package +pushd bin/Release/netcoreapp1.0/publish +zip -r ./deploy-package.zip ./* +popd diff --git a/lib/plugins/create/templates/aws-fsharp/global.json b/lib/plugins/create/templates/aws-fsharp/global.json new file mode 100644 index 000000000..9476c97bb --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/global.json @@ -0,0 +1,6 @@ +{ + "sdk": + { + "version": "1.0.0-preview2-003121" + } +} \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-fsharp/project.json b/lib/plugins/create/templates/aws-fsharp/project.json new file mode 100644 index 000000000..aa4637a19 --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/project.json @@ -0,0 +1,43 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "compilerName": "fsc", + "emitEntryPoint": false, + "compile": "*.fs", + "debugType": "portable", + "outputName": "FsharpHandlers" + }, + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + }, + + "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", + + "Amazon.Lambda.Core": "1.0.0*", + "Amazon.Lambda.Serialization.Json": "1.0.0", + + "Amazon.Lambda.Tools" : { + "type" :"build", + "version":"0.9.0-preview1" + } + }, + + "tools": { + "dotnet-compile-fsc": { + "version": "1.0.0-*", + "imports": [ + "dnxcore50" + ] + }, + "Amazon.Lambda.Tools": "1.0.0-preview1" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +} diff --git a/lib/plugins/create/templates/aws-fsharp/serverless.yml b/lib/plugins/create/templates/aws-fsharp/serverless.yml new file mode 100644 index 000000000..46732efe6 --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/serverless.yml @@ -0,0 +1,84 @@ +# Welcome to Serverless! +# +# This file is the main config file for your service. +# It's very minimal at this point and uses default values. +# You can always add more config options for more control. +# We've included some commented out config examples here. +# Just uncomment any of them to get that config option. +# +# For full config options, check the docs: +# docs.serverless.com +# +# Happy Coding! + +service: aws-fsharp # NOTE: update this with your service name + +# You can pin your service to only deploy with a specific Serverless version +# Check out our docs for more details +# frameworkVersion: "=X.X.X" + +provider: + name: aws + runtime: dotnetcore1.0 + +# you can overwrite defaults here +# stage: dev +# region: us-east-1 + +# you can add statements to the Lambda function's IAM Role here +# iamRoleStatements: +# - Effect: "Allow" +# Action: +# - "s3:ListBucket" +# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } +# - Effect: "Allow" +# Action: +# - "s3:PutObject" +# Resource: +# Fn::Join: +# - "" +# - - "arn:aws:s3:::" +# - "Ref" : "ServerlessDeploymentBucket" + +# you can define service wide environment variables here +# environment: +# variable1: value1 + +# you can add packaging information here +package: + artifact: bin/Release/netcoreapp1.0/publish/deploy-package.zip +# exclude: +# - exclude-me.js +# - exclude-me-dir/** + +functions: + hello: + handler: FsharpHandlers::AwsDotnetFsharp.Handler::Hello + +# The following are a few example events you can configure +# NOTE: Please make sure to change your handler code to work with those events +# Check the event documentation for details +# events: +# - http: +# path: users/create +# method: get +# - s3: ${env:BUCKET} +# - schedule: rate(10 minutes) +# - sns: greeter-topic +# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 + +# Define function environment variables here +# environment: +# variable2: value2 + +# you can add CloudFormation resource templates here +#resources: +# Resources: +# NewResource: +# Type: AWS::S3::Bucket +# Properties: +# BucketName: my-new-bucket +# Outputs: +# NewOutput: +# Description: "Description for the output" +# Value: "Some output value" From 0f334d4baf297a31648d05d2bf58745966735ff5 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Mon, 2 Jan 2017 22:34:33 +0000 Subject: [PATCH 18/81] Add example --- .../examples/hello-world/fsharp/Handler.fs | 17 ++++ .../examples/hello-world/fsharp/project.json | 43 ++++++++++ .../hello-world/fsharp/serverless.yml | 84 +++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 docs/providers/aws/examples/hello-world/fsharp/Handler.fs create mode 100644 docs/providers/aws/examples/hello-world/fsharp/project.json create mode 100644 docs/providers/aws/examples/hello-world/fsharp/serverless.yml diff --git a/docs/providers/aws/examples/hello-world/fsharp/Handler.fs b/docs/providers/aws/examples/hello-world/fsharp/Handler.fs new file mode 100644 index 000000000..b9e1806fe --- /dev/null +++ b/docs/providers/aws/examples/hello-world/fsharp/Handler.fs @@ -0,0 +1,17 @@ +namespace AwsDotnetFsharp +open Amazon.Lambda.Core + +[)>] +do () + +type Request = { Key1 : string; Key2 : string; Key3 : string } +type Response = { Message : string; Request : Request } + +module Handler = + open System + open System.IO + open System.Text + + let hello(request:Request) = + { Message="Go Serverless v1.0! Your function executed successfully!" + Request=request } \ No newline at end of file diff --git a/docs/providers/aws/examples/hello-world/fsharp/project.json b/docs/providers/aws/examples/hello-world/fsharp/project.json new file mode 100644 index 000000000..aa4637a19 --- /dev/null +++ b/docs/providers/aws/examples/hello-world/fsharp/project.json @@ -0,0 +1,43 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "compilerName": "fsc", + "emitEntryPoint": false, + "compile": "*.fs", + "debugType": "portable", + "outputName": "FsharpHandlers" + }, + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + }, + + "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", + + "Amazon.Lambda.Core": "1.0.0*", + "Amazon.Lambda.Serialization.Json": "1.0.0", + + "Amazon.Lambda.Tools" : { + "type" :"build", + "version":"0.9.0-preview1" + } + }, + + "tools": { + "dotnet-compile-fsc": { + "version": "1.0.0-*", + "imports": [ + "dnxcore50" + ] + }, + "Amazon.Lambda.Tools": "1.0.0-preview1" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +} diff --git a/docs/providers/aws/examples/hello-world/fsharp/serverless.yml b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml new file mode 100644 index 000000000..46732efe6 --- /dev/null +++ b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml @@ -0,0 +1,84 @@ +# Welcome to Serverless! +# +# This file is the main config file for your service. +# It's very minimal at this point and uses default values. +# You can always add more config options for more control. +# We've included some commented out config examples here. +# Just uncomment any of them to get that config option. +# +# For full config options, check the docs: +# docs.serverless.com +# +# Happy Coding! + +service: aws-fsharp # NOTE: update this with your service name + +# You can pin your service to only deploy with a specific Serverless version +# Check out our docs for more details +# frameworkVersion: "=X.X.X" + +provider: + name: aws + runtime: dotnetcore1.0 + +# you can overwrite defaults here +# stage: dev +# region: us-east-1 + +# you can add statements to the Lambda function's IAM Role here +# iamRoleStatements: +# - Effect: "Allow" +# Action: +# - "s3:ListBucket" +# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } +# - Effect: "Allow" +# Action: +# - "s3:PutObject" +# Resource: +# Fn::Join: +# - "" +# - - "arn:aws:s3:::" +# - "Ref" : "ServerlessDeploymentBucket" + +# you can define service wide environment variables here +# environment: +# variable1: value1 + +# you can add packaging information here +package: + artifact: bin/Release/netcoreapp1.0/publish/deploy-package.zip +# exclude: +# - exclude-me.js +# - exclude-me-dir/** + +functions: + hello: + handler: FsharpHandlers::AwsDotnetFsharp.Handler::Hello + +# The following are a few example events you can configure +# NOTE: Please make sure to change your handler code to work with those events +# Check the event documentation for details +# events: +# - http: +# path: users/create +# method: get +# - s3: ${env:BUCKET} +# - schedule: rate(10 minutes) +# - sns: greeter-topic +# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 + +# Define function environment variables here +# environment: +# variable2: value2 + +# you can add CloudFormation resource templates here +#resources: +# Resources: +# NewResource: +# Type: AWS::S3::Bucket +# Properties: +# BucketName: my-new-bucket +# Outputs: +# NewOutput: +# Description: "Description for the output" +# Value: "Some output value" From 4b438c4ba1c0014ad63ae77185fa76b0668b76ae Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 3 Jan 2017 00:05:53 +0000 Subject: [PATCH 19/81] Simplify test package step --- lib/plugins/create/templates/aws-fsharp/build.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index c97689e0b..67c7ba660 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -4,11 +4,4 @@ dotnet restore dotnet publish -c release -#install zip -apt-get -qq update -apt-get -qq -y install zip - -#create deployment package -pushd bin/Release/netcoreapp1.0/publish -zip -r ./deploy-package.zip ./* -popd +dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/Release/netcoreapp1.0/deploy-package.zip From 3f0ec7f1aba89395ca8fc719814e6b2412192a97 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 3 Jan 2017 00:10:03 +0000 Subject: [PATCH 20/81] Add build.ps1 --- .../create/templates/aws-fsharp/build.ps1 | 19 +++++++++++++++++++ .../create/templates/aws-fsharp/build.sh | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/plugins/create/templates/aws-fsharp/build.ps1 diff --git a/lib/plugins/create/templates/aws-fsharp/build.ps1 b/lib/plugins/create/templates/aws-fsharp/build.ps1 new file mode 100644 index 000000000..564f8678f --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/build.ps1 @@ -0,0 +1,19 @@ +# from http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell#answer-13302548 +function ZipFiles( $zipfilename, $sourcedir ) +{ + Add-Type -Assembly System.IO.Compression.FileSystem + $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal + [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, + $zipfilename, $compressionLevel, $false) +} + +dotnet restore +dotnet publish -c release +if ($LASTEXITCODE -ne 0) { return } + +$publishDirectory = "bin/release/netcoreapp1.0/publish" +$packageName = "deploy-package.zip" + +rm "$publishDirectory/$packageName" -ErrorAction SilentlyContinue +ZipFiles "$(pwd)/$packageName" "$(pwd)/$publishDirectory" +mv "$packageName" $publishDirectory diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index 67c7ba660..1929db816 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -4,4 +4,4 @@ dotnet restore dotnet publish -c release -dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/Release/netcoreapp1.0/deploy-package.zip +dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip From b8c371c8e5d63d169e5b85a2e0d4103f2dea2c98 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 3 Jan 2017 00:17:56 +0000 Subject: [PATCH 21/81] Remove build.ps1 in favor of build.cmd --- .../create/templates/aws-fsharp/build.cmd | 3 +++ .../create/templates/aws-fsharp/build.ps1 | 19 ------------------- 2 files changed, 3 insertions(+), 19 deletions(-) create mode 100644 lib/plugins/create/templates/aws-fsharp/build.cmd delete mode 100644 lib/plugins/create/templates/aws-fsharp/build.ps1 diff --git a/lib/plugins/create/templates/aws-fsharp/build.cmd b/lib/plugins/create/templates/aws-fsharp/build.cmd new file mode 100644 index 000000000..6c4792a88 --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/build.cmd @@ -0,0 +1,3 @@ +dotnet restore +dotnet build --configuration Release +dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/Release/netcoreapp1.0/deploy-package.zip diff --git a/lib/plugins/create/templates/aws-fsharp/build.ps1 b/lib/plugins/create/templates/aws-fsharp/build.ps1 deleted file mode 100644 index 564f8678f..000000000 --- a/lib/plugins/create/templates/aws-fsharp/build.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -# from http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell#answer-13302548 -function ZipFiles( $zipfilename, $sourcedir ) -{ - Add-Type -Assembly System.IO.Compression.FileSystem - $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal - [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, - $zipfilename, $compressionLevel, $false) -} - -dotnet restore -dotnet publish -c release -if ($LASTEXITCODE -ne 0) { return } - -$publishDirectory = "bin/release/netcoreapp1.0/publish" -$packageName = "deploy-package.zip" - -rm "$publishDirectory/$packageName" -ErrorAction SilentlyContinue -ZipFiles "$(pwd)/$packageName" "$(pwd)/$publishDirectory" -mv "$packageName" $publishDirectory From 79a002434ea36f58090da2b652ea20f94e918dea Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 3 Jan 2017 00:23:57 +0000 Subject: [PATCH 22/81] Added test for aws-fsharp --- lib/plugins/create/create.test.js | 24 +++++++++++++++++++ .../create/templates/aws-fsharp/global.json | 6 ----- 2 files changed, 24 insertions(+), 6 deletions(-) delete mode 100644 lib/plugins/create/templates/aws-fsharp/global.json diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index eabe5a2d6..c0043af7b 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -121,6 +121,30 @@ describe('Create', () => { }); }); + it('should generate scaffolding for "aws-fsharp" template', () => { + const cwd = process.cwd(); + fse.mkdirsSync(tmpDir); + process.chdir(tmpDir); + create.options.template = 'aws-fsharp'; + + return create.create().then(() => { + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'serverless.yml'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'Handler.fs'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, '.gitignore'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'build.sh'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'build.cmd'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'project.json'))) + .to.be.equal(true); + + process.chdir(cwd); + }); + }); + it('should generate scaffolding for "aws-python" template', () => { process.chdir(tmpDir); create.options.template = 'aws-python'; diff --git a/lib/plugins/create/templates/aws-fsharp/global.json b/lib/plugins/create/templates/aws-fsharp/global.json deleted file mode 100644 index 9476c97bb..000000000 --- a/lib/plugins/create/templates/aws-fsharp/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "sdk": - { - "version": "1.0.0-preview2-003121" - } -} \ No newline at end of file From 542c95908040fe755239f1a15023c2bc60014c44 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Tue, 3 Jan 2017 00:26:48 +0000 Subject: [PATCH 23/81] add aws-fsharp integration tests --- docker-compose.yml | 4 ++++ lib/plugins/create/templates/aws-fsharp/build.sh | 1 - tests/templates/test_all_templates | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4649a8550..e39a13771 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,6 +47,10 @@ services: image: microsoft/dotnet:1.0.4-sdk volumes: - ./tmp/serverless-integration-test-aws-csharp:/app + aws-fsharp: + image: microsoft/dotnet:1.0.1-sdk-projectjson + volumes: + - ./tmp/serverless-integration-test-aws-fsharp:/app google-nodejs: image: node:6.9.1 volumes: diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index 1929db816..9b3a00c9d 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -3,5 +3,4 @@ #build handlers dotnet restore dotnet publish -c release - dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index 76a345eee..b60e8900a 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -9,6 +9,7 @@ function integration-test { } integration-test aws-csharp 'apt-get -qq update && apt-get -qq -y install zip && dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' +integration-test aws-fsharp 'dotnet restore && dotnet publish -c release && dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' integration-test aws-groovy-gradle ./gradlew build integration-test aws-java-gradle ./gradlew build integration-test aws-java-maven mvn package From dd3ba770f672b8752ece1d58edb6310c9aca0f2b Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Wed, 4 Jan 2017 00:32:10 +0000 Subject: [PATCH 24/81] Added readme and updated yml conf --- .../aws/examples/hello-world/fsharp/README.md | 37 +++++++++++++++++++ .../hello-world/fsharp/serverless.yml | 7 +++- .../templates/aws-fsharp/serverless.yml | 7 +++- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 docs/providers/aws/examples/hello-world/fsharp/README.md diff --git a/docs/providers/aws/examples/hello-world/fsharp/README.md b/docs/providers/aws/examples/hello-world/fsharp/README.md new file mode 100644 index 000000000..7c7de6acb --- /dev/null +++ b/docs/providers/aws/examples/hello-world/fsharp/README.md @@ -0,0 +1,37 @@ + + +# Hello World F# Example + +## Prerequisites + +* Make sure `serverless` is installed. [See installation guide](../../../guide/installation.md). +* [.Net Core 1.0.1 SDK](https://www.microsoft.com/net/download/core) + * 1.1 isn't currently supported by AWS Lambda +* [NodeJS v4 or higher](https://nodejs.org/en/) +* An AWS Account + +## Build and Package + +From the root of this directory, run `build.cmd`, or `build.sh` if on Linux / Mac. + +This will produce your deployment package at `bin/release/netcoreapp1.0/deploy-package.zip`. + +## Deployment and Invocation + +Once packaged, you can follow [these instructions](https://github.com/serverless/serverless#quick-start) to deploy and remotely invoke the function on AWS Lambda. + +In short the commands you will need to run are (from the root of this directory): + +``` +serverless config credentials --provider aws --key {YourAwsAccessKey} --secret {YourAwsSecret} +serverless deploy -v +serverless invoke -f hello -l +serverless remove +``` + +By default this template deploys to us-east-1, you can change that in "serverless.yml" under the `region: us-east-1` key. \ No newline at end of file diff --git a/docs/providers/aws/examples/hello-world/fsharp/serverless.yml b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml index 46732efe6..774d4d5de 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/serverless.yml +++ b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml @@ -46,14 +46,14 @@ provider: # you can add packaging information here package: - artifact: bin/Release/netcoreapp1.0/publish/deploy-package.zip + artifact: bin/Release/netcoreapp1.0/deploy-package.zip # exclude: # - exclude-me.js # - exclude-me-dir/** functions: hello: - handler: FsharpHandlers::AwsDotnetFsharp.Handler::Hello + handler: FsharpHandlers::AwsDotnetFsharp.Handler::hello # The following are a few example events you can configure # NOTE: Please make sure to change your handler code to work with those events @@ -66,6 +66,9 @@ functions: # - schedule: rate(10 minutes) # - sns: greeter-topic # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 +# - alexaSkill +# - iot: +# sql: "SELECT * FROM 'some_topic'" # Define function environment variables here # environment: diff --git a/lib/plugins/create/templates/aws-fsharp/serverless.yml b/lib/plugins/create/templates/aws-fsharp/serverless.yml index 46732efe6..774d4d5de 100644 --- a/lib/plugins/create/templates/aws-fsharp/serverless.yml +++ b/lib/plugins/create/templates/aws-fsharp/serverless.yml @@ -46,14 +46,14 @@ provider: # you can add packaging information here package: - artifact: bin/Release/netcoreapp1.0/publish/deploy-package.zip + artifact: bin/Release/netcoreapp1.0/deploy-package.zip # exclude: # - exclude-me.js # - exclude-me-dir/** functions: hello: - handler: FsharpHandlers::AwsDotnetFsharp.Handler::Hello + handler: FsharpHandlers::AwsDotnetFsharp.Handler::hello # The following are a few example events you can configure # NOTE: Please make sure to change your handler code to work with those events @@ -66,6 +66,9 @@ functions: # - schedule: rate(10 minutes) # - sns: greeter-topic # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 +# - alexaSkill +# - iot: +# sql: "SELECT * FROM 'some_topic'" # Define function environment variables here # environment: From db69a87b976a91ee1abac2203d8fd543a830f6f3 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Wed, 11 Jan 2017 14:30:41 +0000 Subject: [PATCH 25/81] Update scripts, and updated lambda tools package --- docs/providers/aws/examples/hello-world/fsharp/project.json | 2 +- lib/plugins/create/templates/aws-fsharp/build.cmd | 4 ++-- lib/plugins/create/templates/aws-fsharp/build.sh | 2 +- lib/plugins/create/templates/aws-fsharp/project.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/providers/aws/examples/hello-world/fsharp/project.json b/docs/providers/aws/examples/hello-world/fsharp/project.json index aa4637a19..3e6bff2b9 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/project.json +++ b/docs/providers/aws/examples/hello-world/fsharp/project.json @@ -32,7 +32,7 @@ "dnxcore50" ] }, - "Amazon.Lambda.Tools": "1.0.0-preview1" + "Amazon.Lambda.Tools": "1.0.4-preview1" }, "frameworks": { diff --git a/lib/plugins/create/templates/aws-fsharp/build.cmd b/lib/plugins/create/templates/aws-fsharp/build.cmd index 6c4792a88..2c0a15613 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.cmd +++ b/lib/plugins/create/templates/aws-fsharp/build.cmd @@ -1,3 +1,3 @@ dotnet restore -dotnet build --configuration Release -dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/Release/netcoreapp1.0/deploy-package.zip +dotnet publish -c release +dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index 9b3a00c9d..941f3ace8 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -3,4 +3,4 @@ #build handlers dotnet restore dotnet publish -c release -dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip +dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/lib/plugins/create/templates/aws-fsharp/project.json b/lib/plugins/create/templates/aws-fsharp/project.json index aa4637a19..3e6bff2b9 100644 --- a/lib/plugins/create/templates/aws-fsharp/project.json +++ b/lib/plugins/create/templates/aws-fsharp/project.json @@ -32,7 +32,7 @@ "dnxcore50" ] }, - "Amazon.Lambda.Tools": "1.0.0-preview1" + "Amazon.Lambda.Tools": "1.0.4-preview1" }, "frameworks": { From b319a64216b9cf685b3617771166bfe8353beefb Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Sat, 14 Jan 2017 01:39:36 +0000 Subject: [PATCH 26/81] Updated lambda tools --- docs/providers/aws/examples/hello-world/fsharp/project.json | 2 +- lib/plugins/create/templates/aws-fsharp/project.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/providers/aws/examples/hello-world/fsharp/project.json b/docs/providers/aws/examples/hello-world/fsharp/project.json index 3e6bff2b9..232aef87d 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/project.json +++ b/docs/providers/aws/examples/hello-world/fsharp/project.json @@ -21,7 +21,7 @@ "Amazon.Lambda.Tools" : { "type" :"build", - "version":"0.9.0-preview1" + "version":"1.0.4-preview1" } }, diff --git a/lib/plugins/create/templates/aws-fsharp/project.json b/lib/plugins/create/templates/aws-fsharp/project.json index 3e6bff2b9..232aef87d 100644 --- a/lib/plugins/create/templates/aws-fsharp/project.json +++ b/lib/plugins/create/templates/aws-fsharp/project.json @@ -21,7 +21,7 @@ "Amazon.Lambda.Tools" : { "type" :"build", - "version":"0.9.0-preview1" + "version":"1.0.4-preview1" } }, From 53e61df65c8a7c1194d55a09d5e627acf76424a7 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 23 Jan 2017 12:28:52 +0100 Subject: [PATCH 27/81] Update Lambda Tools version for F# template --- docs/providers/aws/examples/hello-world/fsharp/project.json | 4 ++-- lib/plugins/create/templates/aws-fsharp/project.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/providers/aws/examples/hello-world/fsharp/project.json b/docs/providers/aws/examples/hello-world/fsharp/project.json index 232aef87d..9ba920e18 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/project.json +++ b/docs/providers/aws/examples/hello-world/fsharp/project.json @@ -21,7 +21,7 @@ "Amazon.Lambda.Tools" : { "type" :"build", - "version":"1.0.4-preview1" + "version":"1.1.0-preview1" } }, @@ -32,7 +32,7 @@ "dnxcore50" ] }, - "Amazon.Lambda.Tools": "1.0.4-preview1" + "Amazon.Lambda.Tools": "1.1.0-preview1" }, "frameworks": { diff --git a/lib/plugins/create/templates/aws-fsharp/project.json b/lib/plugins/create/templates/aws-fsharp/project.json index 232aef87d..9ba920e18 100644 --- a/lib/plugins/create/templates/aws-fsharp/project.json +++ b/lib/plugins/create/templates/aws-fsharp/project.json @@ -21,7 +21,7 @@ "Amazon.Lambda.Tools" : { "type" :"build", - "version":"1.0.4-preview1" + "version":"1.1.0-preview1" } }, @@ -32,7 +32,7 @@ "dnxcore50" ] }, - "Amazon.Lambda.Tools": "1.0.4-preview1" + "Amazon.Lambda.Tools": "1.1.0-preview1" }, "frameworks": { From c95061d5db63aa506d6ef173a4d3382c39b20aa8 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 23 Jan 2017 12:29:42 +0100 Subject: [PATCH 28/81] Fix indentation and path in serverless.yml template files --- docs/providers/aws/examples/hello-world/fsharp/serverless.yml | 2 +- lib/plugins/create/templates/aws-fsharp/serverless.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/providers/aws/examples/hello-world/fsharp/serverless.yml b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml index 774d4d5de..c90e1089a 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/serverless.yml +++ b/docs/providers/aws/examples/hello-world/fsharp/serverless.yml @@ -46,7 +46,7 @@ provider: # you can add packaging information here package: - artifact: bin/Release/netcoreapp1.0/deploy-package.zip + artifact: bin/release/netcoreapp1.0/deploy-package.zip # exclude: # - exclude-me.js # - exclude-me-dir/** diff --git a/lib/plugins/create/templates/aws-fsharp/serverless.yml b/lib/plugins/create/templates/aws-fsharp/serverless.yml index 774d4d5de..c90e1089a 100644 --- a/lib/plugins/create/templates/aws-fsharp/serverless.yml +++ b/lib/plugins/create/templates/aws-fsharp/serverless.yml @@ -46,7 +46,7 @@ provider: # you can add packaging information here package: - artifact: bin/Release/netcoreapp1.0/deploy-package.zip + artifact: bin/release/netcoreapp1.0/deploy-package.zip # exclude: # - exclude-me.js # - exclude-me-dir/** From 6a6db5d85633630015911dc325a4255cd328044a Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Sun, 29 Jan 2017 23:54:07 +0000 Subject: [PATCH 29/81] Removed redundant publish command --- lib/plugins/create/templates/aws-fsharp/build.cmd | 5 ++--- lib/plugins/create/templates/aws-fsharp/build.sh | 3 +-- tests/templates/test_all_templates | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/plugins/create/templates/aws-fsharp/build.cmd b/lib/plugins/create/templates/aws-fsharp/build.cmd index 2c0a15613..468f8503a 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.cmd +++ b/lib/plugins/create/templates/aws-fsharp/build.cmd @@ -1,3 +1,2 @@ -dotnet restore -dotnet publish -c release -dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip +dotnet restore +dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index 941f3ace8..79bfb4d1b 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -2,5 +2,4 @@ #build handlers dotnet restore -dotnet publish -c release -dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip +dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index b60e8900a..6a450f0e3 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -9,7 +9,7 @@ function integration-test { } integration-test aws-csharp 'apt-get -qq update && apt-get -qq -y install zip && dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' -integration-test aws-fsharp 'dotnet restore && dotnet publish -c release && dotnet lambda package --configuration Release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' +integration-test aws-fsharp 'dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' integration-test aws-groovy-gradle ./gradlew build integration-test aws-java-gradle ./gradlew build integration-test aws-java-maven mvn package From c18a07191800d8406f28a450940d6819bd14ed51 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Wed, 22 Mar 2017 22:07:51 +0000 Subject: [PATCH 30/81] Update to latest tooling --- .../hello-world/fsharp/aws-fsharp.fsproj | 28 ++++++++++++ .../examples/hello-world/fsharp/project.json | 43 ------------------- lib/plugins/create/create.test.js | 2 +- .../templates/aws-fsharp/aws-fsharp.fsproj | 28 ++++++++++++ .../create/templates/aws-fsharp/project.json | 43 ------------------- 5 files changed, 57 insertions(+), 87 deletions(-) create mode 100644 docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj delete mode 100644 docs/providers/aws/examples/hello-world/fsharp/project.json create mode 100644 lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj delete mode 100644 lib/plugins/create/templates/aws-fsharp/project.json diff --git a/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj b/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj new file mode 100644 index 000000000..9382205fe --- /dev/null +++ b/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj @@ -0,0 +1,28 @@ + + + + netcoreapp1.0 + portable + FsharpHandlers + Library + aws-fsharp + 1.0.4 + $(PackageTargetFallback);dnxcore50 + + + + + + + + + + + + + + + + + + diff --git a/docs/providers/aws/examples/hello-world/fsharp/project.json b/docs/providers/aws/examples/hello-world/fsharp/project.json deleted file mode 100644 index 9ba920e18..000000000 --- a/docs/providers/aws/examples/hello-world/fsharp/project.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "compilerName": "fsc", - "emitEntryPoint": false, - "compile": "*.fs", - "debugType": "portable", - "outputName": "FsharpHandlers" - }, - - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.1" - }, - - "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", - - "Amazon.Lambda.Core": "1.0.0*", - "Amazon.Lambda.Serialization.Json": "1.0.0", - - "Amazon.Lambda.Tools" : { - "type" :"build", - "version":"1.1.0-preview1" - } - }, - - "tools": { - "dotnet-compile-fsc": { - "version": "1.0.0-*", - "imports": [ - "dnxcore50" - ] - }, - "Amazon.Lambda.Tools": "1.1.0-preview1" - }, - - "frameworks": { - "netcoreapp1.0": { - "imports": "dnxcore50" - } - } -} diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index c0043af7b..e79a9e160 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -138,7 +138,7 @@ describe('Create', () => { .to.be.equal(true); expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'build.cmd'))) .to.be.equal(true); - expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'project.json'))) + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'aws-fsharp.fsproj'))) .to.be.equal(true); process.chdir(cwd); diff --git a/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj b/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj new file mode 100644 index 000000000..9382205fe --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj @@ -0,0 +1,28 @@ + + + + netcoreapp1.0 + portable + FsharpHandlers + Library + aws-fsharp + 1.0.4 + $(PackageTargetFallback);dnxcore50 + + + + + + + + + + + + + + + + + + diff --git a/lib/plugins/create/templates/aws-fsharp/project.json b/lib/plugins/create/templates/aws-fsharp/project.json deleted file mode 100644 index 9ba920e18..000000000 --- a/lib/plugins/create/templates/aws-fsharp/project.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "compilerName": "fsc", - "emitEntryPoint": false, - "compile": "*.fs", - "debugType": "portable", - "outputName": "FsharpHandlers" - }, - - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.1" - }, - - "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-*", - - "Amazon.Lambda.Core": "1.0.0*", - "Amazon.Lambda.Serialization.Json": "1.0.0", - - "Amazon.Lambda.Tools" : { - "type" :"build", - "version":"1.1.0-preview1" - } - }, - - "tools": { - "dotnet-compile-fsc": { - "version": "1.0.0-*", - "imports": [ - "dnxcore50" - ] - }, - "Amazon.Lambda.Tools": "1.1.0-preview1" - }, - - "frameworks": { - "netcoreapp1.0": { - "imports": "dnxcore50" - } - } -} From ab002291f7cc4a882778397c9c9c8f18a8a4f1e7 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Wed, 22 Mar 2017 22:41:22 +0000 Subject: [PATCH 31/81] Renamed .gitignore -> gitignore --- lib/plugins/create/templates/aws-fsharp/{.gitignore => gitignore} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/plugins/create/templates/aws-fsharp/{.gitignore => gitignore} (100%) diff --git a/lib/plugins/create/templates/aws-fsharp/.gitignore b/lib/plugins/create/templates/aws-fsharp/gitignore similarity index 100% rename from lib/plugins/create/templates/aws-fsharp/.gitignore rename to lib/plugins/create/templates/aws-fsharp/gitignore From 84a0e4f0cd8210efce10874547e1c18048496b93 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Thu, 23 Mar 2017 17:22:35 +0000 Subject: [PATCH 32/81] Updated dotnet sdk docker image --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e39a13771..227462503 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,7 +48,7 @@ services: volumes: - ./tmp/serverless-integration-test-aws-csharp:/app aws-fsharp: - image: microsoft/dotnet:1.0.1-sdk-projectjson + image: microsoft/dotnet:1.0.4-sdk volumes: - ./tmp/serverless-integration-test-aws-fsharp:/app google-nodejs: From bf80fc928857e0644a29f906d3d84278e5f874e4 Mon Sep 17 00:00:00 2001 From: Stuart Lang Date: Sat, 24 Jun 2017 16:52:09 +0100 Subject: [PATCH 33/81] Update libraries and match csharp changes --- .../examples/hello-world/fsharp/aws-fsharp.fsproj | 12 ++++-------- lib/plugins/create/create.test.js | 6 ++---- lib/plugins/create/templates/aws-fsharp/Handler.fs | 4 ++-- .../create/templates/aws-fsharp/aws-fsharp.fsproj | 12 ++++-------- lib/plugins/create/templates/aws-fsharp/build.sh | 7 ++++++- lib/plugins/create/templates/aws-fsharp/global.json | 5 +++++ tests/templates/test_all_templates | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 lib/plugins/create/templates/aws-fsharp/global.json diff --git a/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj b/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj index 9382205fe..f3a1aafd4 100644 --- a/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj +++ b/docs/providers/aws/examples/hello-world/fsharp/aws-fsharp.fsproj @@ -2,12 +2,8 @@ netcoreapp1.0 - portable FsharpHandlers - Library aws-fsharp - 1.0.4 - $(PackageTargetFallback);dnxcore50 @@ -15,14 +11,14 @@ - - - + + + - + diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index e79a9e160..f77496b3d 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -122,8 +122,6 @@ describe('Create', () => { }); it('should generate scaffolding for "aws-fsharp" template', () => { - const cwd = process.cwd(); - fse.mkdirsSync(tmpDir); process.chdir(tmpDir); create.options.template = 'aws-fsharp'; @@ -140,8 +138,8 @@ describe('Create', () => { .to.be.equal(true); expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'aws-fsharp.fsproj'))) .to.be.equal(true); - - process.chdir(cwd); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'global.json'))) + .to.be.equal(true); }); }); diff --git a/lib/plugins/create/templates/aws-fsharp/Handler.fs b/lib/plugins/create/templates/aws-fsharp/Handler.fs index b9e1806fe..e1eb3a208 100644 --- a/lib/plugins/create/templates/aws-fsharp/Handler.fs +++ b/lib/plugins/create/templates/aws-fsharp/Handler.fs @@ -12,6 +12,6 @@ module Handler = open System.IO open System.Text - let hello(request:Request) = + let hello(request:Request) = { Message="Go Serverless v1.0! Your function executed successfully!" - Request=request } \ No newline at end of file + Request=request } diff --git a/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj b/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj index 9382205fe..f3a1aafd4 100644 --- a/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj +++ b/lib/plugins/create/templates/aws-fsharp/aws-fsharp.fsproj @@ -2,12 +2,8 @@ netcoreapp1.0 - portable FsharpHandlers - Library aws-fsharp - 1.0.4 - $(PackageTargetFallback);dnxcore50 @@ -15,14 +11,14 @@ - - - + + + - + diff --git a/lib/plugins/create/templates/aws-fsharp/build.sh b/lib/plugins/create/templates/aws-fsharp/build.sh index 79bfb4d1b..892b0f289 100644 --- a/lib/plugins/create/templates/aws-fsharp/build.sh +++ b/lib/plugins/create/templates/aws-fsharp/build.sh @@ -1,5 +1,10 @@ #!/bin/bash -#build handlers +#install zip +apt-get -qq update +apt-get -qq -y install zip + dotnet restore + +#create deployment package dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip diff --git a/lib/plugins/create/templates/aws-fsharp/global.json b/lib/plugins/create/templates/aws-fsharp/global.json new file mode 100644 index 000000000..8af244a46 --- /dev/null +++ b/lib/plugins/create/templates/aws-fsharp/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "1.0.4" + } +} diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index 6a450f0e3..b539c35d1 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -9,7 +9,7 @@ function integration-test { } integration-test aws-csharp 'apt-get -qq update && apt-get -qq -y install zip && dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' -integration-test aws-fsharp 'dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' +integration-test aws-fsharp 'apt-get -qq update && apt-get -qq -y install zip && dotnet restore && dotnet lambda package --configuration release --framework netcoreapp1.0 --output-package bin/release/netcoreapp1.0/deploy-package.zip' integration-test aws-groovy-gradle ./gradlew build integration-test aws-java-gradle ./gradlew build integration-test aws-java-maven mvn package From f01ca2dbf7c2b3c9f2ff830c3f9b9cb10f68498d Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Sun, 25 Jun 2017 19:15:21 +1000 Subject: [PATCH 34/81] Update docs to indicate you can use cognito pool authoriser and claims with lambda-proxy --- docs/providers/aws/events/apigateway.md | 9 ++++++--- .../package/compile/events/apiGateway/lib/validate.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index d299fc7f3..0841a2785 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -265,7 +265,12 @@ functions: arn: arn:aws:cognito-idp:us-east-1:xxx:userpool/us-east-1_ZZZ ``` -By default the `sub` claim will be exposed in `events.cognitoPoolClaims`, you can add extra claims like so: +If you are using the default `lambda-proxy` integration, your attributes will be +exposed at `event.requestContext.authorizer.claims`. + +If you want control more control over which attributes are exposed as claims you +can switch to `integration: lambda` and add the following configuration. The +claims will be exposed at `events.cognitoPoolClaims`. ```yml functions: @@ -283,8 +288,6 @@ functions: - nickname ``` -Note: Since claims must be explicitly listed to be exposed, you must use `integration: lambda` integration type to access any claims. - ### Catching Exceptions In Your Lambda Function In case an exception is thrown in your lambda function AWS will send an error message with `Process exited before completing request`. This will be caught by the regular expression for the 500 HTTP status and the 500 status will be returned. diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js index 97f99637f..ad64560b6 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -247,7 +247,7 @@ module.exports = { if (integration === 'AWS_PROXY' && typeof arn === 'string' && arn.match(/^arn:aws:cognito-idp/) && authorizer.claims) { const errorMessage = [ - 'Cognito claims can\'t be retrieved when using lambda-proxy as the integration type', + 'Cognito claims can only be filtered when using the lambda integration type', ]; throw new this.serverless.classes.Error(errorMessage); } From 185af2e5194da3294a9e41ef1a90a01d48ba1359 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 24 Jun 2017 17:09:34 +0530 Subject: [PATCH 35/81] Remove entrypoint subcmds in generateCommandsHelp --- lib/classes/CLI.js | 7 +++++++ lib/classes/CLI.test.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 05698c36d..4a0dc67e9 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -149,6 +149,13 @@ class CLI { const command = this.serverless.pluginManager.getCommand(commandsArray); const commandName = commandsArray.join(' '); + // Remove entrypoint subcommands + _.forEach(command.commands, (details, cmd) => { + if (details.type === 'entrypoint') { + delete command.commands[cmd]; + } + }); + // print the name of the plugin this.consoleLog(chalk.yellow.underline(`Plugin: ${command.pluginName}`)); diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 3a1d6b326..1817a2f8a 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -352,5 +352,17 @@ describe('CLI', () => { done(); }); }); + + it('should not print entrypoint subcommands in help', (done) => { + exec(`${this.serverlessExec} package --help`, (err, stdout) => { + if (err) { + done(err); + return; + } + + expect(stdout).to.not.contain('package function'); + done(); + }); + }); }); }); From ccf5a592245c1b0230cfdbf75785cdaa941143b3 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 25 Jun 2017 19:07:04 +0530 Subject: [PATCH 36/81] Improve entrypoint cmd removal algo Use getCommands() to fetch all the commands with filtered entrypoint commands and reduce to the required command. Throw error when a command is not found. --- lib/classes/CLI.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 4a0dc67e9..a4fe2e1ff 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -146,15 +146,25 @@ class CLI { } generateCommandsHelp(commandsArray) { - const command = this.serverless.pluginManager.getCommand(commandsArray); const commandName = commandsArray.join(' '); - // Remove entrypoint subcommands - _.forEach(command.commands, (details, cmd) => { - if (details.type === 'entrypoint') { - delete command.commands[cmd]; + // Get all the commands using getCommands() with filtered entrypoint + // commands and reduce to the required command. + const allCommands = this.serverless.pluginManager.getCommands(); + const command = _.reduce(commandsArray, (currentCmd, cmd) => { + if (currentCmd.commands && cmd in currentCmd.commands) { + return currentCmd.commands[cmd]; } - }); + return undefined; + }, { commands: allCommands }); + + // Throw error if command not found. + if (!command) { + const errorMessage = `Serverless command "${commandName}" not found + + Run "serverless help" for a list of all available commands.`; + throw new this.serverless.classes.Error(errorMessage); + } // print the name of the plugin this.consoleLog(chalk.yellow.underline(`Plugin: ${command.pluginName}`)); From edaba87927830713c2c41b3f17166a02bf2277bd Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 08:40:40 +0200 Subject: [PATCH 37/81] Update fsharp serverless.yml file --- .../create/templates/aws-fsharp/serverless.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/plugins/create/templates/aws-fsharp/serverless.yml b/lib/plugins/create/templates/aws-fsharp/serverless.yml index c90e1089a..314962e28 100644 --- a/lib/plugins/create/templates/aws-fsharp/serverless.yml +++ b/lib/plugins/create/templates/aws-fsharp/serverless.yml @@ -39,6 +39,7 @@ provider: # - "" # - - "arn:aws:s3:::" # - "Ref" : "ServerlessDeploymentBucket" +# - "/*" # you can define service wide environment variables here # environment: @@ -69,6 +70,19 @@ functions: # - alexaSkill # - iot: # sql: "SELECT * FROM 'some_topic'" +# - cloudwatchEvent: +# event: +# source: +# - "aws.ec2" +# detail-type: +# - "EC2 Instance State-change Notification" +# detail: +# state: +# - pending +# - cloudwatchLog: '/aws/lambda/hello' +# - cognitoUserPool: +# pool: MyUserPool +# trigger: PreSignUp # Define function environment variables here # environment: From 5ff7e72f5fb69fe94466f3c8e8b57430d469e3f6 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 08:40:52 +0200 Subject: [PATCH 38/81] Update csharp serverless.yml file --- lib/plugins/create/templates/aws-csharp/serverless.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/create/templates/aws-csharp/serverless.yml b/lib/plugins/create/templates/aws-csharp/serverless.yml index 5d227388b..1498ed2a5 100644 --- a/lib/plugins/create/templates/aws-csharp/serverless.yml +++ b/lib/plugins/create/templates/aws-csharp/serverless.yml @@ -67,6 +67,7 @@ functions: # - schedule: rate(10 minutes) # - sns: greeter-topic # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 +# - alexaSkill # - iot: # sql: "SELECT * FROM 'some_topic'" # - cloudwatchEvent: From ecb992405466576d573aca7cf1859b76c6ca4ff5 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 09:36:13 +0200 Subject: [PATCH 39/81] Update tests --- lib/classes/CLI.test.js | 86 +++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 1817a2f8a..fd7daceed 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -5,6 +5,7 @@ */ const expect = require('chai').expect; +const sinon = require('sinon'); const CLI = require('../../lib/classes/CLI'); const os = require('os'); const fse = require('fs-extra'); @@ -273,6 +274,79 @@ describe('CLI', () => { }); }); + describe('#generateCommandsHelp()', () => { + let getCommandsStub; + let consoleLogStub; + let displayCommandUsageStub; + let displayCommandOptionsStub; + + const commands = { + package: { + usage: 'Packages a Serverless service', + lifecycleEvents: ['cleanup', 'initialize'], + options: {}, + key: 'package', + pluginName: 'Package', + }, + deploy: { + usage: 'Deploy a Serverless service', + lifecycleEvents: ['cleanup', 'initialize'], + options: {}, + key: 'deploy', + pluginName: 'Deploy', + commands: {}, + }, + }; + + beforeEach(() => { + cli = new CLI(serverless); + getCommandsStub = sinon.stub(cli.serverless.pluginManager, 'getCommands') + .returns(commands); + consoleLogStub = sinon.stub(cli, 'consoleLog').returns(); + displayCommandUsageStub = sinon.stub(cli, 'displayCommandUsage').returns(); + displayCommandOptionsStub = sinon.stub(cli, 'displayCommandOptions').returns(); + }); + + afterEach(() => { + cli.serverless.pluginManager.getCommands.restore(); + cli.consoleLog.restore(); + cli.displayCommandUsage.restore(); + cli.displayCommandOptions.restore(); + }); + + it('should gather and generate the commands help info if the command can be found', () => { + const commandsArray = ['package']; + cli.inputArray = commandsArray; + + cli.generateCommandsHelp(commandsArray); + + expect(getCommandsStub.calledOnce).to.equal(true); + expect(consoleLogStub.called).to.equal(true); + expect(displayCommandUsageStub.calledOnce).to.equal(true); + expect(displayCommandUsageStub.calledWithExactly( + commands.package, + 'package' + )).to.equal(true); + expect(displayCommandOptionsStub.calledOnce).to.equal(true); + expect(displayCommandOptionsStub.calledWithExactly( + commands.package + )).to.equal(true); + }); + + it('should throw an error if the command could not be found', () => { + const commandsArray = ['invalid-command']; + + cli.inputArray = commandsArray; + + expect(() => { cli.generateCommandsHelp(commandsArray); }) + .to.throw(Error, 'not found'); + expect(getCommandsStub.calledOnce).to.equal(true); + expect(consoleLogStub.called).to.equal(false); + expect(displayCommandUsageStub.calledOnce).to.equal(false); + expect(displayCommandOptionsStub.calledOnce).to.equal(false); + }); + }); + describe('#processInput()', () => { it('should only return the commands when only commands are given', () => { cli = new CLI(serverless, ['deploy', 'functions']); @@ -352,17 +426,5 @@ describe('CLI', () => { done(); }); }); - - it('should not print entrypoint subcommands in help', (done) => { - exec(`${this.serverlessExec} package --help`, (err, stdout) => { - if (err) { - done(err); - return; - } - - expect(stdout).to.not.contain('package function'); - done(); - }); - }); }); }); From c3f9c246ca14900e8f975b5b394de04a5096d9b5 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 09:36:59 +0200 Subject: [PATCH 40/81] Update error message to be contained in an array This makes the code more readable. --- lib/classes/CLI.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index a4fe2e1ff..8fb1ec6fa 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -160,9 +160,10 @@ class CLI { // Throw error if command not found. if (!command) { - const errorMessage = `Serverless command "${commandName}" not found - - Run "serverless help" for a list of all available commands.`; + const errorMessage = [ + `Serverless command "${commandName}" not found`, + 'Run "serverless help" for a list of all available commands.', + ].join(''); throw new this.serverless.classes.Error(errorMessage); } From 1d0152535048fa554c3be94a3bb4cabf91a8a5f3 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 09:39:00 +0200 Subject: [PATCH 41/81] Update error message --- lib/classes/CLI.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 8fb1ec6fa..3241d469c 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -161,8 +161,8 @@ class CLI { // Throw error if command not found. if (!command) { const errorMessage = [ - `Serverless command "${commandName}" not found`, - 'Run "serverless help" for a list of all available commands.', + `Serverless command "${commandName}" not found.`, + ' Run "serverless help" for a list of all available commands.', ].join(''); throw new this.serverless.classes.Error(errorMessage); } From 734e12e3d5d9476c21935f6deb46695f407aa4a1 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 09:44:33 +0200 Subject: [PATCH 42/81] Switch from undefined to null --- lib/classes/CLI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 3241d469c..28f61d851 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -155,7 +155,7 @@ class CLI { if (currentCmd.commands && cmd in currentCmd.commands) { return currentCmd.commands[cmd]; } - return undefined; + return null; }, { commands: allCommands }); // Throw error if command not found. From 8595ff0e8bc8e565053c1e1ed52a8373fa11b4c4 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 09:55:22 +0200 Subject: [PATCH 43/81] Switch to serverless log method For consinstency's sake. --- lib/plugins/platform/platform.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index 43b84e054..c806aab05 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -163,8 +163,10 @@ class Platform { const username = jwtDecode(authToken).nickname; const serviceName = this.serverless.service.service; const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - console.log('Service successfully published! Your service details are available at:'); // eslint-disable-line - console.log(chalk.green(url)); // eslint-disable-line + this.serverless + .cli.log('Service successfully published! Your service details are available at:'); + this.serverless + .cli.log(chalk.green(url)); }) .catch(error => { this.serverless.cli.log( From 549afa499f3109cfd72d386ca264f986845da990 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 10:06:07 +0200 Subject: [PATCH 44/81] Update error message --- .../aws/package/compile/events/apiGateway/lib/validate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js index e0f9ed042..fa7f79243 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -158,6 +158,7 @@ module.exports = { ' for http event in serverless.yml.', ' If you define an http event, make sure you pass a valid value for it,', ' either as string syntax, or object syntax.', + ' Please check the indentation of your config values if you use the object syntax.', ' Please check the docs for more options.', ].join(''); throw new this.serverless.classes.Error(errorMessage); From 9130ebb1856c2f19b0878dac371f0bed05b03236 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 10:20:18 +0200 Subject: [PATCH 45/81] Fix tests --- lib/plugins/platform/platform.test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/plugins/platform/platform.test.js b/lib/plugins/platform/platform.test.js index 162733ae7..d26ec41f4 100644 --- a/lib/plugins/platform/platform.test.js +++ b/lib/plugins/platform/platform.test.js @@ -2,6 +2,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); +const chalk = require('chalk'); const Platform = require('./platform'); const Serverless = require('../../Serverless'); const AwsProvider = require('../aws/provider/awsProvider'); @@ -75,9 +76,10 @@ describe('Platform', () => { expect(publishServiceRequestStub.calledOnce).to.be.equal(true); const expected = { name: 'new-service-2', stage: undefined, functions: [] }; expect(publishServiceRequestStub.getCall(0).args[0]).to.deep.equal(expected); - const expectedLog = - 'Your service is available at https://platform.serverless.com/services/johndoe/new-service-2'; - expect(platform.serverless.cli.log.calledWithExactly(expectedLog)).to.be.equal(true); + const url = chalk.green('https://platform.serverless.com/services/johndoe/new-service-2'); + const successLog = 'Service successfully published! Your service details are available at:'; + expect(platform.serverless.cli.log.calledWithExactly(successLog)).to.be.equal(true); + expect(platform.serverless.cli.log.calledWithExactly(url)).to.be.equal(true); }); }); @@ -138,9 +140,10 @@ describe('Platform', () => { license: 'MIT', }; expect(publishServiceRequestStub.getCall(0).args[0]).to.deep.equal(expected); - const expectedLog = - 'Your service is available at https://platform.serverless.com/services/johndoe/new-service-2'; - expect(platform.serverless.cli.log.calledWithExactly(expectedLog)).to.be.equal(true); + const url = chalk.green('https://platform.serverless.com/services/johndoe/new-service-2'); + const successLog = 'Service successfully published! Your service details are available at:'; + expect(platform.serverless.cli.log.calledWithExactly(successLog)).to.be.equal(true); + expect(platform.serverless.cli.log.calledWithExactly(url)).to.be.equal(true); }); }); }); From c98254851430740ca8a9b44a50e053274cb9ff4f Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:02:37 +0200 Subject: [PATCH 46/81] Switch option from --plugin to --verbose --- lib/classes/CLI.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index f68577d1a..64b661b73 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -56,8 +56,8 @@ class CLI { if ((commands.length === 0) || (commands.length === 0 && (options.help || options.h)) || (commands.length === 1 && (commands.indexOf('help') > -1))) { - if (options.plugins || options.p) { - this.generateCommandsByPluginHelp(); + if (options.verbose || options.v) { + this.generateVerboseHelp(); } else { this.generateMainHelp(); } @@ -150,11 +150,9 @@ class CLI { } } - generateCommandsByPluginHelp() { + generateVerboseHelp() { this.consoleLog(''); - this.consoleLog(chalk.yellow.underline('Commands by plugin')); - this.consoleLog(''); let pluginCommands = {}; @@ -189,7 +187,7 @@ class CLI { // Sort plugins alphabetically pluginCommands = _(pluginCommands).toPairs().sortBy(0).fromPairs() - .value(); + .value(); _.forEach(pluginCommands, (details, plugin) => { this.consoleLog(plugin); From 7b64e71dfae536f4c71e0a83948d6daccce0b5ca Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:02:47 +0200 Subject: [PATCH 47/81] Update test --- lib/classes/CLI.test.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/classes/CLI.test.js b/lib/classes/CLI.test.js index 42ce2263e..1e5022bdb 100644 --- a/lib/classes/CLI.test.js +++ b/lib/classes/CLI.test.js @@ -1,9 +1,5 @@ 'use strict'; -/** - * Test: CLI Class - */ - const expect = require('chai').expect; const CLI = require('../../lib/classes/CLI'); const os = require('os'); @@ -353,8 +349,8 @@ describe('CLI', () => { }); }); - it('should print sorted plugin commands --help --plugins', (done) => { - exec(`${this.serverlessExec} --help --plugins`, (err, stdout) => { + it('should print help --verbose to stdout', (done) => { + exec(`${this.serverlessExec} help --verbose`, (err, stdout) => { if (err) { done(err); return; From a709c43274f402538d183d8ca9dd0de2fc85fac2 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:14:58 +0200 Subject: [PATCH 48/81] Add sorting of commands --- lib/classes/CLI.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 64b661b73..0beaaae73 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -129,9 +129,19 @@ class CLI { this.consoleLog(''); - _.forEach(this.loadedCommands, (details, command) => { - this.displayCommandUsage(details, command); - }); + if (this.loadedCommands) { + const commandKeys = Object.keys(this.loadedCommands); + const sortedCommandKeys = _.sortBy(commandKeys); + const sortedCommands = _.fromPairs( + _.map(sortedCommandKeys, key => [key, this.loadedCommands[key]]) + ); + + _.forEach(sortedCommands, (details, command) => { + this.displayCommandUsage(details, command); + }); + } else { + this.consoleLog('No commands found'); + } this.consoleLog(''); @@ -139,11 +149,7 @@ class CLI { this.consoleLog(chalk.yellow.underline('Plugins')); if (this.loadedPlugins.length) { - const sortedPlugins = _.sortBy( - this.loadedPlugins, - (plugin) => plugin.constructor.name - ); - + const sortedPlugins = _.sortBy(this.loadedPlugins, (plugin) => plugin.constructor.name); this.consoleLog(sortedPlugins.map((plugin) => plugin.constructor.name).join(', ')); } else { this.consoleLog('No plugins added yet'); @@ -157,14 +163,14 @@ class CLI { let pluginCommands = {}; - // Add commands to pluginCommands based on command's plugin + // add commands to pluginCommands based on command's plugin const addToPluginCommands = (cmd) => { const pcmd = _.clone(cmd); - // Remove subcommand from clone + // remove subcommand from clone delete pcmd.commands; - // Check if a plugin entry is alreay present in pluginCommands. Use the + // check if a plugin entry is alreay present in pluginCommands. Use the // existing one or create a new plugin entry. if (_.has(pluginCommands, pcmd.pluginName)) { pluginCommands[pcmd.pluginName] = pluginCommands[pcmd.pluginName].concat(pcmd); @@ -180,19 +186,19 @@ class CLI { } }; - // Fill up pluginCommands with commands in loadedCommands + // fill up pluginCommands with commands in loadedCommands _.forEach(this.loadedCommands, (details) => { addToPluginCommands(details); }); - // Sort plugins alphabetically + // sort plugins alphabetically pluginCommands = _(pluginCommands).toPairs().sortBy(0).fromPairs() .value(); _.forEach(pluginCommands, (details, plugin) => { this.consoleLog(plugin); _.forEach(details, (cmd) => { - // Display command usage with single(1) indent + // display command usage with single(1) indent this.displayCommandUsage(cmd, cmd.key.split(':').join(' '), 1); }); this.consoleLog(''); From 909d7d5cc2c9d89f2881cf24ed9a3d929219c271 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:18:40 +0200 Subject: [PATCH 49/81] Add info about new --verbose option --- lib/classes/CLI.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 0beaaae73..9654d3859 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -126,6 +126,7 @@ class CLI { this.consoleLog(chalk.dim('* Serverless documentation: http://docs.serverless.com')); this.consoleLog(chalk.dim('* You can run commands with "serverless" or the shortcut "sls"')); this.consoleLog(chalk.dim('* Pass "--help" after any for contextual help')); + this.consoleLog(chalk.dim('* Pass "--verbose" to this command to get in-depth plugin info')); this.consoleLog(''); From da91ba8e83dea156d39afac669beee654dd2a045 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:20:28 +0200 Subject: [PATCH 50/81] Re-arrange order for help text To reduce ambiguity. --- lib/classes/CLI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 9654d3859..6c13c23e5 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -125,8 +125,8 @@ class CLI { this.consoleLog(chalk.yellow.underline('Commands')); this.consoleLog(chalk.dim('* Serverless documentation: http://docs.serverless.com')); this.consoleLog(chalk.dim('* You can run commands with "serverless" or the shortcut "sls"')); - this.consoleLog(chalk.dim('* Pass "--help" after any for contextual help')); this.consoleLog(chalk.dim('* Pass "--verbose" to this command to get in-depth plugin info')); + this.consoleLog(chalk.dim('* Pass "--help" after any for contextual help')); this.consoleLog(''); From 29f06670adee5cc00889ba950fdbc09be633c20c Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 26 Jun 2017 12:21:24 +0200 Subject: [PATCH 51/81] Lowercase comment --- lib/classes/CLI.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/CLI.js b/lib/classes/CLI.js index 6c13c23e5..b23d15599 100644 --- a/lib/classes/CLI.js +++ b/lib/classes/CLI.js @@ -179,7 +179,7 @@ class CLI { pluginCommands[pcmd.pluginName] = [pcmd]; } - // Check for subcommands + // check for subcommands if ('commands' in cmd) { _.forEach(cmd.commands, (d) => { addToPluginCommands(d); From 8fbcf71da7553488ca6ca3b347da45853ace09cb Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Mon, 26 Jun 2017 15:05:58 +0200 Subject: [PATCH 52/81] make sure to follow the serverless framework conventions for error handling --- lib/plugins/platform/platform.js | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index c806aab05..b2b225aae 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -158,22 +158,25 @@ class Platform { const readmePath = path.join(this.serverless.config.servicePath, 'README.md'); const serviceDataWithReadme = addReadme(serviceData, readmePath); - return this.publishServiceRequest(serviceDataWithReadme, clientWithAuth) - .then(() => { - const username = jwtDecode(authToken).nickname; - const serviceName = this.serverless.service.service; - const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - this.serverless - .cli.log('Service successfully published! Your service details are available at:'); - this.serverless - .cli.log(chalk.green(url)); - }) - .catch(error => { - this.serverless.cli.log( - "Couldn't publish this deploy information to the Serverless Platform due: \n", - error - ); - }); + return new BbPromise((resolve, reject) => { + this.publishServiceRequest(serviceDataWithReadme, clientWithAuth) + .then(() => { + const username = jwtDecode(authToken).nickname; + const serviceName = this.serverless.service.service; + const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; + this.serverless.cli.log( + 'Service successfully published! Your service details are available at:' + ); + this.serverless.cli.log(chalk.green(url)); + resolve(); + }) + .catch(error => { + this.serverless.cli.log( + "Couldn't publish this deploy information to the Serverless Platform." + ); + reject(error); + }); + }); }) ); } From 6e1d22723117b715b30da9f6c7645a3528b837e6 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Mon, 26 Jun 2017 21:41:16 +0800 Subject: [PATCH 53/81] releasing 1.16.1 --- CHANGELOG.md | 7 +++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8186065..995833626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.16.1 (26.06.2017) +- CI/CD fix for the Serverless Platform - #3829 + +## Meta +- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.16.0...v1.16.1) + + # 1.16.0 (21.06.2017) - Added support for usage plans to APIG - #3819 - Optmizied packaging to exclude dev dependencies - #3737 diff --git a/package-lock.json b/package-lock.json index 1804b5917..b81c4dfcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "serverless", - "version": "1.16.0", + "version": "1.16.1", "lockfileVersion": 1, "dependencies": { "@types/async": { diff --git a/package.json b/package.json index 5f7309141..cbe4f0e77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless", - "version": "1.16.0", + "version": "1.16.1", "engines": { "node": ">=4.0" }, From 9327fa8e48e76064c2cef10488b4ea97fccb0cc5 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 08:21:55 -0700 Subject: [PATCH 54/81] shrink token to match header reqs --- lib/plugins/login/login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/login/login.js b/lib/plugins/login/login.js index 902164475..14c183d08 100644 --- a/lib/plugins/login/login.js +++ b/lib/plugins/login/login.js @@ -54,8 +54,9 @@ class Login { const version = this.serverless.version; const state = `id%3D${frameworkId}%26version%3D${version}%26platform%3D${process.platform}`; // refresh token docs https://auth0.com/docs/tokens/preview/refresh-token#get-a-refresh-token + const scope = 'openid%20email%20name%20login_count%20created_at%20original_user_id%20offline_access'; // eslint-disable-line const authorizeUrl = - `${config.AUTH0_URL}/authorize?response_type=code&scope=openid%20profile%20offline_access` + + `${config.AUTH0_URL}/authorize?response_type=code&scope=${scope}` + `&client_id=${config.AUTH0_CLIENT_ID}&redirect_uri=${config.AUTH0_CALLBACK_URL}` + `&code_challenge=${verifierChallenge}&code_challenge_method=S256&state=${state}`; @@ -91,7 +92,6 @@ class Login { .then((platformResponse) => { const decoded = jwtDecode(platformResponse.id_token); this.serverless.cli.log('You are now logged in'); - // because platform only support github const id = decoded.original_user_id || decoded.sub; From db02e800c8456461429979e09ee9ca28a1927cc3 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 08:31:08 -0700 Subject: [PATCH 55/81] expire the token if it is too long --- lib/plugins/platform/platform.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index b2b225aae..8d8325e24 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -101,6 +101,13 @@ class Platform { // NOTE publishService is an opt-in feature and no warning is needed return BbPromise.resolve(); } + + if (authToken && authToken.length > 8000) { + this.serverless.cli.log('Your serverless login has expired'); + this.serverless.cli.log('Please run `serverless login` again'); + return BbPromise.resolve(); + } + this.serverless.cli.log('Publish service to Serverless Platform...'); const clientWithAuth = createApolloClient(config.GRAPHQL_ENDPOINT_URL, authToken); From e40dba4652e006afc9e1959b8506b4376b690be6 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 11:17:10 -0700 Subject: [PATCH 56/81] add nickname --- lib/plugins/login/login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/login/login.js b/lib/plugins/login/login.js index 14c183d08..e35391ec0 100644 --- a/lib/plugins/login/login.js +++ b/lib/plugins/login/login.js @@ -54,7 +54,7 @@ class Login { const version = this.serverless.version; const state = `id%3D${frameworkId}%26version%3D${version}%26platform%3D${process.platform}`; // refresh token docs https://auth0.com/docs/tokens/preview/refresh-token#get-a-refresh-token - const scope = 'openid%20email%20name%20login_count%20created_at%20original_user_id%20offline_access'; // eslint-disable-line + const scope = 'openid%20nickname%20email%20name%20login_count%20created_at%20original_user_id%20offline_access'; // eslint-disable-line const authorizeUrl = `${config.AUTH0_URL}/authorize?response_type=code&scope=${scope}` + `&client_id=${config.AUTH0_CLIENT_ID}&redirect_uri=${config.AUTH0_CALLBACK_URL}` + From d87fa0835e11acbda9287ff86c8f9481c3f70ab6 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 14:58:39 -0700 Subject: [PATCH 57/81] update log for easy copy/paste of url --- lib/plugins/platform/platform.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index b2b225aae..47a3eb2d4 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -164,10 +164,8 @@ class Platform { const username = jwtDecode(authToken).nickname; const serviceName = this.serverless.service.service; const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - this.serverless.cli.log( - 'Service successfully published! Your service details are available at:' - ); - this.serverless.cli.log(chalk.green(url)); + console.log('Service successfully published! Your service details are available at:'); // eslint-disable-line + console.log(chalk.green(url)); // eslint-disable-line resolve(); }) .catch(error => { From 41c3c404431b7f68c81b75d58bd71f3c007a1873 Mon Sep 17 00:00:00 2001 From: David Wells Date: Mon, 26 Jun 2017 16:53:21 -0700 Subject: [PATCH 58/81] Update logs.md --- docs/providers/aws/cli-reference/logs.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/providers/aws/cli-reference/logs.md b/docs/providers/aws/cli-reference/logs.md index d57ecbd0a..f0ab9994f 100644 --- a/docs/providers/aws/cli-reference/logs.md +++ b/docs/providers/aws/cli-reference/logs.md @@ -16,6 +16,9 @@ Lets you watch the logs of a specific function. ```bash serverless logs -f hello + +# Optionally tail the logs with -t +serverless logs -f hello -t ``` ## Options From 041b0356e922e073f571d1d01f1bcb20c11cde48 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:03:36 -0700 Subject: [PATCH 59/81] add remove service placeholder function --- lib/plugins/aws/provider/awsProvider.js | 12 ++++++------ lib/plugins/platform/platform.js | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js index 24c2e3854..8465a8cb7 100644 --- a/lib/plugins/aws/provider/awsProvider.js +++ b/lib/plugins/aws/provider/awsProvider.js @@ -4,8 +4,9 @@ const AWS = require('aws-sdk'); const BbPromise = require('bluebird'); const HttpsProxyAgent = require('https-proxy-agent'); const url = require('url'); +const chalk = require('chalk'); const _ = require('lodash'); - +const userStats = require('../../../utils/userStats'); const naming = require('../lib/naming.js'); const constants = { @@ -168,12 +169,11 @@ class AwsProvider { const err = errParam; if (err) { if (err.message === 'Missing credentials in config') { - const errorMessage = [ - 'AWS provider credentials not found.', - ' You can find more info on how to set up provider', - ' credentials in our docs here: https://git.io/vXsdd', - ].join(''); + const errorMessage = `AWS provider credentials not found. + + Learn how to set up AWS provider credentials in our docs here: ${chalk.green('https://git.io/vXsdd')}`; err.message = errorMessage; + userStats.track('user_awsCredentialsFailed'); } reject(new this.serverless.classes.Error(err.message, err.statusCode)); } else { diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index b2b225aae..a0277d5f3 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -62,10 +62,14 @@ class Platform { if (this.provider) { this.hooks = { 'after:deploy:deploy': this.publishService.bind(this), + 'after:remove:remove': this.removeService.bind(this), }; } } - + removeService() { + // todo implement platform removal here + return BbPromise.resolve(); + } publishServiceRequest(service, client) { return client .mutate({ From 818841b68326a3d46a5af211854019d710c9b270 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:04:04 -0700 Subject: [PATCH 60/81] userStats metrics --- lib/plugins/metrics/metrics.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/plugins/metrics/metrics.js b/lib/plugins/metrics/metrics.js index 393dc8b86..e926d7c58 100644 --- a/lib/plugins/metrics/metrics.js +++ b/lib/plugins/metrics/metrics.js @@ -1,5 +1,8 @@ 'use strict'; +const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); + class Metrics { constructor(serverless, options) { this.serverless = serverless; @@ -33,6 +36,14 @@ class Metrics { }, }, }; + this.hooks = { + 'after:metrics:metrics': () => BbPromise.bind(this).then(this.track), + }; + } + track() { + // todo would like to see time frame via --startTime + userStats.track('service_metricsViewed'); + return BbPromise.resolve(); } } From 025af78403413eb4d2d4477cc8f9023f8f1c08c1 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:04:12 -0700 Subject: [PATCH 61/81] userStats logs --- lib/plugins/logs/logs.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/plugins/logs/logs.js b/lib/plugins/logs/logs.js index 3cb9b4db0..4ba27110b 100644 --- a/lib/plugins/logs/logs.js +++ b/lib/plugins/logs/logs.js @@ -1,4 +1,6 @@ 'use strict'; +const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); class Logs { constructor(serverless) { @@ -41,6 +43,18 @@ class Logs { }, }, }; + this.hooks = { + 'after:logs:logs': () => BbPromise.bind(this).then(this.track), + }; + } + track() { + const sls = this.serverless; + if (sls && sls.processedInput && sls.processedInput.options) { + const opts = sls.processedInput.options; + const type = (opts.tail) ? 'service_logsTailed' : 'service_logsViewed'; + userStats.track(type); + } + return BbPromise.resolve(); } } From 959847f8e26b956dc5f8c5faa5eadf4a9cb4bd2e Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:04:36 -0700 Subject: [PATCH 62/81] userStats install --- lib/plugins/install/install.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/plugins/install/install.js b/lib/plugins/install/install.js index 7fb095067..f845bece0 100644 --- a/lib/plugins/install/install.js +++ b/lib/plugins/install/install.js @@ -6,6 +6,7 @@ const URL = require('url'); const download = require('download'); const fse = require('fs-extra'); const os = require('os'); +const userStats = require('../../utils/userStats'); class Install { constructor(serverless, options) { @@ -151,6 +152,11 @@ class Install { return this.renameService(dirName, servicePath); }).then(() => { let message = `Successfully installed "${serviceName}"`; + userStats.track('service_installed', { + data: { // will be updated with core analtyics lib + url: this.options.url, + }, + }); if (renamed) message = `${message} as "${dirName}"`; that.serverless.cli.log(message); From fb6a505271f64eedaf14c2b22bd60ecf44abdcac Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:04:54 -0700 Subject: [PATCH 63/81] userStats remove --- lib/plugins/remove/remove.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/plugins/remove/remove.js b/lib/plugins/remove/remove.js index e7d85cfc4..dd88d0fb0 100644 --- a/lib/plugins/remove/remove.js +++ b/lib/plugins/remove/remove.js @@ -1,5 +1,8 @@ 'use strict'; +const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); + class Remove { constructor(serverless) { this.serverless = serverless; @@ -26,6 +29,12 @@ class Remove { }, }, }; + this.hooks = { + 'after:remove:remove': () => BbPromise.bind(this).then(this.track), + }; + } + track() { + userStats.track('service_removed'); } } From 57b1421ecca89ea0557f90f5009b68de117337e2 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:05:25 -0700 Subject: [PATCH 64/81] userStats noProviderCredsFound --- lib/plugins/aws/provider/awsProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js index 8465a8cb7..156a73f82 100644 --- a/lib/plugins/aws/provider/awsProvider.js +++ b/lib/plugins/aws/provider/awsProvider.js @@ -173,7 +173,7 @@ class AwsProvider { Learn how to set up AWS provider credentials in our docs here: ${chalk.green('https://git.io/vXsdd')}`; err.message = errorMessage; - userStats.track('user_awsCredentialsFailed'); + userStats.track('user_awsCredentialsNotFound'); } reject(new this.serverless.classes.Error(err.message, err.statusCode)); } else { From c674ae7b3ca77b89666ab388d0fa18d7f78745a2 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:05:48 -0700 Subject: [PATCH 65/81] userStats deploy --- lib/plugins/deploy/deploy.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index 8c26dd55d..84745014f 100644 --- a/lib/plugins/deploy/deploy.js +++ b/lib/plugins/deploy/deploy.js @@ -97,13 +97,22 @@ class Deploy { return BbPromise.resolve(); }), - 'after:deploy:deploy': () => BbPromise.bind(this) - .then(this.track), + 'after:deploy:deploy': () => BbPromise.bind(this).then(this.track), }; } track() { - userStats.track('service_deployed'); + const sls = this.serverless; + let serviceInfo = {}; + if (sls && sls.service && sls.service.provider && sls.service.provider.name) { + serviceInfo = { + provider: sls.service.provider.name, + runtime: sls.service.provider.runtime, + }; + } + userStats.track('service_deployed', { + data: serviceInfo, + }); } } From 5eae2a08ffacf9555fb891711f077334e238551f Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:18:27 -0700 Subject: [PATCH 66/81] userStats rollback --- lib/plugins/rollback/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/plugins/rollback/index.js b/lib/plugins/rollback/index.js index 4adbcccdc..8ff82a3c1 100644 --- a/lib/plugins/rollback/index.js +++ b/lib/plugins/rollback/index.js @@ -1,5 +1,8 @@ 'use strict'; +const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); + class Rollback { constructor(serverless) { this.serverless = serverless; @@ -52,6 +55,13 @@ class Rollback { }, }, }; + this.hooks = { + 'after:rollback:rollback': () => BbPromise.bind(this).then(this.track), + }; + } + track() { + userStats.track('service_rolledBack'); + return BbPromise.resolve(); } } From 332eddc56b7b636b77e299a5360a860713d5b265 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:41:50 -0700 Subject: [PATCH 67/81] userStats config --- lib/plugins/config/config.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/plugins/config/config.js b/lib/plugins/config/config.js index fc82bfa9a..2c0ea983b 100644 --- a/lib/plugins/config/config.js +++ b/lib/plugins/config/config.js @@ -1,6 +1,7 @@ 'use strict'; const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); // class wide constants const validProviders = [ @@ -38,11 +39,10 @@ class Config { }; this.hooks = { - 'before:config:credentials:config': () => BbPromise.bind(this) - .then(this.validate), + 'before:config:credentials:config': () => BbPromise.bind(this).then(this.validate), + 'after:config:credentials:config': () => BbPromise.bind(this).then(this.track), }; } - validate() { const provider = this.options.provider.toLowerCase(); @@ -56,6 +56,17 @@ class Config { return BbPromise.resolve(); } + track() { + const sls = this.serverless; + if (sls && sls.processedInput && sls.processedInput.options) { + const opts = sls.processedInput.options; + if (opts.provider === 'aws') { + userStats.track('user_awsCredentialsConfigured'); + } + // todo: add other providers here when supported + } + return BbPromise.resolve(); + } } module.exports = Config; From 0bcf4b6e8e25dead183f05de7c0e9eaaba158345 Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:42:07 -0700 Subject: [PATCH 68/81] userStats invoke --- lib/plugins/invoke/invoke.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugins/invoke/invoke.js b/lib/plugins/invoke/invoke.js index c5ecdfee5..1946ef83f 100644 --- a/lib/plugins/invoke/invoke.js +++ b/lib/plugins/invoke/invoke.js @@ -2,6 +2,7 @@ const BbPromise = require('bluebird'); const _ = require('lodash'); +const userStats = require('../../utils/userStats'); class Invoke { constructor(serverless) { @@ -72,11 +73,19 @@ class Invoke { }; this.hooks = { - 'invoke:local:loadEnvVars': () => BbPromise.bind(this) - .then(this.loadEnvVarsForLocal), + 'invoke:local:loadEnvVars': () => BbPromise.bind(this).then(this.loadEnvVarsForLocal), + 'after:invoke:invoke': () => BbPromise.bind(this).then(this.trackInvoke), + 'after:invoke:local:invoke': () => BbPromise.bind(this).then(this.trackInvokeLocal), }; } - + trackInvoke() { + userStats.track('service_invoked'); + return BbPromise.resolve(); + } + trackInvokeLocal() { + userStats.track('service_invokedLocally'); + return BbPromise.resolve(); + } /** * Set environment variables for "invoke local" that are provider independent. */ From 583c45a8a1e8c41ff8d2c83eae64a0d2b2922b0b Mon Sep 17 00:00:00 2001 From: davidwells Date: Mon, 26 Jun 2017 17:46:15 -0700 Subject: [PATCH 69/81] userStats info --- lib/plugins/info/info.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/plugins/info/info.js b/lib/plugins/info/info.js index e5889cce7..b4000a73e 100644 --- a/lib/plugins/info/info.js +++ b/lib/plugins/info/info.js @@ -1,5 +1,8 @@ 'use strict'; +const BbPromise = require('bluebird'); +const userStats = require('../../utils/userStats'); + class Info { constructor(serverless) { this.serverless = serverless; @@ -26,6 +29,13 @@ class Info { }, }, }; + this.hooks = { + 'after:info:info': () => BbPromise.bind(this).then(this.track), + }; + } + track() { + userStats.track('service_infoViewed'); + return BbPromise.resolve(); } } From e12962d33a1d94cd145342a730141d8eeb6e3f43 Mon Sep 17 00:00:00 2001 From: gorankl Date: Tue, 27 Jun 2017 15:50:00 +1000 Subject: [PATCH 70/81] Update apigateway.md 1.16.0 resolved these issues --- docs/providers/aws/events/apigateway.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index 0841a2785..79f7a7c0f 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -294,8 +294,6 @@ In case an exception is thrown in your lambda function AWS will send an error me ### Setting API keys for your Rest API -**Note:** Due to a CloudFormation restriction you need to wire up API Keys and usage plans manually in the AWS console. - You can specify a list of API keys to be used by your service Rest API by adding an `apiKeys` array property to the `provider` object in `serverless.yml`. You'll also need to explicitly specify which endpoints are `private` and require one of the api keys to be included in the request by adding a `private` boolean property to the `http` event object you From e7297cca4b445563d326cafa913bb126c6b2c91c Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Tue, 27 Jun 2017 09:03:44 +0200 Subject: [PATCH 71/81] Disable console globally for platform.js file --- lib/plugins/platform/platform.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index 47a3eb2d4..bf73d68c8 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -1,5 +1,7 @@ 'use strict'; +/* eslint-disable no-console */ + const path = require('path'); const fs = require('fs'); const gql = require('graphql-tag'); @@ -164,8 +166,8 @@ class Platform { const username = jwtDecode(authToken).nickname; const serviceName = this.serverless.service.service; const url = `${config.PLATFORM_FRONTEND_BASE_URL}services/${username}/${serviceName}`; - console.log('Service successfully published! Your service details are available at:'); // eslint-disable-line - console.log(chalk.green(url)); // eslint-disable-line + console.log('Service successfully published! Your service details are available at:'); + console.log(chalk.green(url)); resolve(); }) .catch(error => { From 74fb662617ab67831e905bc7b607cd41d470cd3d Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Tue, 27 Jun 2017 09:03:59 +0200 Subject: [PATCH 72/81] Fix tests --- lib/plugins/platform/platform.test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/plugins/platform/platform.test.js b/lib/plugins/platform/platform.test.js index d26ec41f4..2f9c4a2fc 100644 --- a/lib/plugins/platform/platform.test.js +++ b/lib/plugins/platform/platform.test.js @@ -1,5 +1,7 @@ 'use strict'; +/* eslint-disable no-console */ + const expect = require('chai').expect; const sinon = require('sinon'); const chalk = require('chalk'); @@ -52,6 +54,7 @@ describe('Platform', () => { ], }); publishServiceRequestStub = sinon.stub(platform, 'publishServiceRequest').resolves(); + sinon.spy(console, 'log'); }); afterEach(() => { @@ -59,6 +62,7 @@ describe('Platform', () => { getAccountIdStub.restore(); endpointsRequestStub.restore(); publishServiceRequestStub.restore(); + console.log.restore(); }); it('should send a minimal service request to the platform', () => { @@ -67,7 +71,6 @@ describe('Platform', () => { name: 'new-service-2', }; platform.serverless.config.servicePath = '/path/to/service'; - sinon.spy(platform.serverless.cli, 'log'); return platform.publishService().then(() => { expect(getAuthTokenStub.calledOnce).to.be.equal(true); @@ -78,8 +81,8 @@ describe('Platform', () => { expect(publishServiceRequestStub.getCall(0).args[0]).to.deep.equal(expected); const url = chalk.green('https://platform.serverless.com/services/johndoe/new-service-2'); const successLog = 'Service successfully published! Your service details are available at:'; - expect(platform.serverless.cli.log.calledWithExactly(successLog)).to.be.equal(true); - expect(platform.serverless.cli.log.calledWithExactly(url)).to.be.equal(true); + expect(console.log.calledWithExactly(successLog)).to.be.equal(true); + expect(console.log.calledWithExactly(url)).to.be.equal(true); }); }); @@ -106,8 +109,6 @@ describe('Platform', () => { }, }; - sinon.spy(platform.serverless.cli, 'log'); - return platform.publishService().then(() => { expect(getAuthTokenStub.calledOnce).to.be.equal(true); expect(getAccountIdStub.calledOnce).to.be.equal(true); @@ -142,8 +143,8 @@ describe('Platform', () => { expect(publishServiceRequestStub.getCall(0).args[0]).to.deep.equal(expected); const url = chalk.green('https://platform.serverless.com/services/johndoe/new-service-2'); const successLog = 'Service successfully published! Your service details are available at:'; - expect(platform.serverless.cli.log.calledWithExactly(successLog)).to.be.equal(true); - expect(platform.serverless.cli.log.calledWithExactly(url)).to.be.equal(true); + expect(console.log.calledWithExactly(successLog)).to.be.equal(true); + expect(console.log.calledWithExactly(url)).to.be.equal(true); }); }); }); From 72bb1d74d9df56494ee794df365bab7541160bbd Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Fri, 23 Jun 2017 16:18:53 +0200 Subject: [PATCH 73/81] Add infinite stack trace limit for Errors --- bin/serverless | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/serverless b/bin/serverless index 5adf6bfd4..fb63b7383 100755 --- a/bin/serverless +++ b/bin/serverless @@ -6,6 +6,8 @@ const autocomplete = require('../lib/utils/autocomplete'); const BbPromise = require('bluebird'); const logError = require('../lib/classes/Error').logError; +Error.stackTraceLimit = Infinity; + BbPromise.config({ longStackTraces: true, }); From fe6a71a78c4f79a67c1da925cab6be1be6e19940 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 28 Jun 2017 08:44:12 +0200 Subject: [PATCH 74/81] Fix tabtab paths in postinstall script --- scripts/postinstall.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 9eb4fba38..a32f64078 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -1,5 +1,7 @@ 'use strict'; +const path = require('path'); + /* eslint-disable no-console */ /* eslint-disable no-use-before-define */ @@ -20,14 +22,17 @@ try { function setupAutocomplete() { return new Promise((resolve, reject) => { - const tabtabPath = require.resolve('tabtab').replace(/\/index.js$/, ''); + const indexRegex = new RegExp(path.join(path.sep, 'index.js')); + const tabtabPath = require.resolve('tabtab').replace(indexRegex, ''); + const tabtabCliPath = path.join(tabtabPath, 'src', 'cli.js'); + try { - execSync(`node ${tabtabPath}/src/cli.js install --name serverless --auto`); - execSync(`node ${tabtabPath}/src/cli.js install --name sls --auto`); + execSync(`node ${tabtabCliPath} install --name serverless --auto`); + execSync(`node ${tabtabCliPath} install --name sls --auto`); return resolve(); } catch (error) { - execSync(`node ${tabtabPath}/src/cli.js install --name serverless --stdout`); - execSync(`node ${tabtabPath}/src/cli.js install --name sls --stdout`); + execSync(`node ${tabtabCliPath} install --name serverless --stdout`); + execSync(`node ${tabtabCliPath} install --name sls --stdout`); console.log('Could not auto-install serverless autocomplete script.'); console.log('Please copy / paste the script above into your shell.'); return reject(error); From 0e580bfd26fa09d88d7a60567e3eebe60c2717a9 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 28 Jun 2017 09:29:35 +0200 Subject: [PATCH 75/81] Update formatting of error message --- lib/plugins/aws/provider/awsProvider.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js index 156a73f82..c7354fb43 100644 --- a/lib/plugins/aws/provider/awsProvider.js +++ b/lib/plugins/aws/provider/awsProvider.js @@ -169,9 +169,11 @@ class AwsProvider { const err = errParam; if (err) { if (err.message === 'Missing credentials in config') { - const errorMessage = `AWS provider credentials not found. - - Learn how to set up AWS provider credentials in our docs here: ${chalk.green('https://git.io/vXsdd')}`; + const errorMessage = [ + 'AWS provider credentials not found.', + ' Learn how to set up AWS provider credentials', + ` in our docs here: ${chalk.green('https://git.io/vXsdd')}.`, + ].join(''); err.message = errorMessage; userStats.track('user_awsCredentialsNotFound'); } From 80970a4b2d4161ce0df51b62799e0413e395ea42 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 28 Jun 2017 09:43:31 +0200 Subject: [PATCH 76/81] Minor fixes / add whitespaces for better readability --- lib/plugins/config/config.js | 4 +++- lib/plugins/info/info.js | 2 ++ lib/plugins/invoke/invoke.js | 3 +++ lib/plugins/logs/logs.js | 3 +++ lib/plugins/metrics/metrics.js | 2 ++ lib/plugins/platform/platform.js | 4 +++- lib/plugins/remove/remove.js | 3 +++ lib/plugins/rollback/index.js | 2 ++ 8 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/plugins/config/config.js b/lib/plugins/config/config.js index 2c0ea983b..600c92e2b 100644 --- a/lib/plugins/config/config.js +++ b/lib/plugins/config/config.js @@ -43,6 +43,7 @@ class Config { 'after:config:credentials:config': () => BbPromise.bind(this).then(this.track), }; } + validate() { const provider = this.options.provider.toLowerCase(); @@ -56,6 +57,7 @@ class Config { return BbPromise.resolve(); } + track() { const sls = this.serverless; if (sls && sls.processedInput && sls.processedInput.options) { @@ -63,7 +65,7 @@ class Config { if (opts.provider === 'aws') { userStats.track('user_awsCredentialsConfigured'); } - // todo: add other providers here when supported + // TODO add other providers here when supported } return BbPromise.resolve(); } diff --git a/lib/plugins/info/info.js b/lib/plugins/info/info.js index b4000a73e..5d4499397 100644 --- a/lib/plugins/info/info.js +++ b/lib/plugins/info/info.js @@ -29,10 +29,12 @@ class Info { }, }, }; + this.hooks = { 'after:info:info': () => BbPromise.bind(this).then(this.track), }; } + track() { userStats.track('service_infoViewed'); return BbPromise.resolve(); diff --git a/lib/plugins/invoke/invoke.js b/lib/plugins/invoke/invoke.js index 1946ef83f..f513fef23 100644 --- a/lib/plugins/invoke/invoke.js +++ b/lib/plugins/invoke/invoke.js @@ -78,14 +78,17 @@ class Invoke { 'after:invoke:local:invoke': () => BbPromise.bind(this).then(this.trackInvokeLocal), }; } + trackInvoke() { userStats.track('service_invoked'); return BbPromise.resolve(); } + trackInvokeLocal() { userStats.track('service_invokedLocally'); return BbPromise.resolve(); } + /** * Set environment variables for "invoke local" that are provider independent. */ diff --git a/lib/plugins/logs/logs.js b/lib/plugins/logs/logs.js index 4ba27110b..1888f7227 100644 --- a/lib/plugins/logs/logs.js +++ b/lib/plugins/logs/logs.js @@ -1,4 +1,5 @@ 'use strict'; + const BbPromise = require('bluebird'); const userStats = require('../../utils/userStats'); @@ -43,10 +44,12 @@ class Logs { }, }, }; + this.hooks = { 'after:logs:logs': () => BbPromise.bind(this).then(this.track), }; } + track() { const sls = this.serverless; if (sls && sls.processedInput && sls.processedInput.options) { diff --git a/lib/plugins/metrics/metrics.js b/lib/plugins/metrics/metrics.js index e926d7c58..24adab56b 100644 --- a/lib/plugins/metrics/metrics.js +++ b/lib/plugins/metrics/metrics.js @@ -36,10 +36,12 @@ class Metrics { }, }, }; + this.hooks = { 'after:metrics:metrics': () => BbPromise.bind(this).then(this.track), }; } + track() { // todo would like to see time frame via --startTime userStats.track('service_metricsViewed'); diff --git a/lib/plugins/platform/platform.js b/lib/plugins/platform/platform.js index a0277d5f3..a83ba0c89 100644 --- a/lib/plugins/platform/platform.js +++ b/lib/plugins/platform/platform.js @@ -66,10 +66,12 @@ class Platform { }; } } + removeService() { - // todo implement platform removal here + // TODO implement platform removal here return BbPromise.resolve(); } + publishServiceRequest(service, client) { return client .mutate({ diff --git a/lib/plugins/remove/remove.js b/lib/plugins/remove/remove.js index dd88d0fb0..1f098b38a 100644 --- a/lib/plugins/remove/remove.js +++ b/lib/plugins/remove/remove.js @@ -29,12 +29,15 @@ class Remove { }, }, }; + this.hooks = { 'after:remove:remove': () => BbPromise.bind(this).then(this.track), }; } + track() { userStats.track('service_removed'); + return BbPromise.resolve(); } } diff --git a/lib/plugins/rollback/index.js b/lib/plugins/rollback/index.js index 8ff82a3c1..d7e4a52ad 100644 --- a/lib/plugins/rollback/index.js +++ b/lib/plugins/rollback/index.js @@ -55,10 +55,12 @@ class Rollback { }, }, }; + this.hooks = { 'after:rollback:rollback': () => BbPromise.bind(this).then(this.track), }; } + track() { userStats.track('service_rolledBack'); return BbPromise.resolve(); From 0f912c8486b81c5717cc8e8bf7f302bfbf2a4211 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 28 Jun 2017 09:50:30 +0200 Subject: [PATCH 77/81] Add missing Promise resolving --- lib/plugins/deploy/deploy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index 84745014f..bdb917acd 100644 --- a/lib/plugins/deploy/deploy.js +++ b/lib/plugins/deploy/deploy.js @@ -113,6 +113,7 @@ class Deploy { userStats.track('service_deployed', { data: serviceInfo, }); + return BbPromise.resolve(); } } From ce7a7cd8686d682c0564e071319ca44bd09b6cc3 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Wed, 28 Jun 2017 09:51:15 +0200 Subject: [PATCH 78/81] Fix linting error --- lib/plugins/metrics/metrics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/metrics/metrics.js b/lib/plugins/metrics/metrics.js index 24adab56b..c089724c2 100644 --- a/lib/plugins/metrics/metrics.js +++ b/lib/plugins/metrics/metrics.js @@ -41,7 +41,7 @@ class Metrics { 'after:metrics:metrics': () => BbPromise.bind(this).then(this.track), }; } - + track() { // todo would like to see time frame via --startTime userStats.track('service_metricsViewed'); From 6c02461a8d8ff3527d9ab15b9d758bc4a61aade3 Mon Sep 17 00:00:00 2001 From: Mike Hostetler Date: Wed, 28 Jun 2017 13:06:22 -0500 Subject: [PATCH 79/81] Update README.md Adding Langa to list of Serverless Consultants --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 94a9c1fca..535802fe5 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,7 @@ These consultants use the Serverless Framework and can help you build your serve * [Craftship](https://craftship.io) * [EPX Labs](http://www.epxlabs.com/) - runs [Serverless NYC Meetup](https://www.meetup.com/Serverless-NYC/) * [Red Badger](https://red-badger.com) +* [Langa](http://langa.io/?utm_source=gh-serverless&utm_medium=github) - They built [Trails.js](http://github.com/trailsjs/trails) ---- From 6def2d5f1e2aef5bc2e61104c89b412ba18bfb37 Mon Sep 17 00:00:00 2001 From: davidwells Date: Wed, 28 Jun 2017 16:41:09 -0700 Subject: [PATCH 80/81] include additional meta --- lib/plugins/login/login.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/plugins/login/login.js b/lib/plugins/login/login.js index e35391ec0..abed6c752 100644 --- a/lib/plugins/login/login.js +++ b/lib/plugins/login/login.js @@ -7,7 +7,7 @@ const fetch = require('node-fetch'); const jwtDecode = require('jwt-decode'); const chalk = require('chalk'); const openBrowser = require('../../utils/openBrowser'); -const getFrameworkId = require('../../utils/getFrameworkId'); +const configUtils = require('../../utils/config'); const clearConsole = require('../../utils/clearConsole'); const userStats = require('../../utils/userStats'); const setConfig = require('../../utils/config').set; @@ -49,7 +49,8 @@ class Login { // Generate the verifier, and the corresponding challenge const verifier = base64url(crypto.randomBytes(32)); const verifierChallenge = base64url(crypto.createHash('sha256').update(verifier).digest()); - const frameworkId = getFrameworkId(); + const configuration = configUtils.getConfig(); + const frameworkId = configuration.frameworkId; // eslint-disable-next-line prefer-template const version = this.serverless.version; const state = `id%3D${frameworkId}%26version%3D${version}%26platform%3D${process.platform}`; @@ -134,6 +135,7 @@ class Login { email: decoded.email, // unix timestamp created_at: Math.round(+new Date(createdAt) / 1000), + trackingDisabled: configuration.trackingDisabled, force: true, }).then(() => { userStats.track('user_loggedIn', { From 8baf8eebfcfb0857914c1882e478cbf265b7044a Mon Sep 17 00:00:00 2001 From: davidwells Date: Wed, 28 Jun 2017 17:13:32 -0700 Subject: [PATCH 81/81] use original tracking id --- lib/plugins/login/login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/login/login.js b/lib/plugins/login/login.js index abed6c752..56476c955 100644 --- a/lib/plugins/login/login.js +++ b/lib/plugins/login/login.js @@ -55,7 +55,7 @@ class Login { const version = this.serverless.version; const state = `id%3D${frameworkId}%26version%3D${version}%26platform%3D${process.platform}`; // refresh token docs https://auth0.com/docs/tokens/preview/refresh-token#get-a-refresh-token - const scope = 'openid%20nickname%20email%20name%20login_count%20created_at%20original_user_id%20offline_access'; // eslint-disable-line + const scope = 'openid%20nickname%20email%20name%20login_count%20created_at%20tracking_id%20offline_access'; // eslint-disable-line const authorizeUrl = `${config.AUTH0_URL}/authorize?response_type=code&scope=${scope}` + `&client_id=${config.AUTH0_CLIENT_ID}&redirect_uri=${config.AUTH0_CALLBACK_URL}` + @@ -94,7 +94,7 @@ class Login { const decoded = jwtDecode(platformResponse.id_token); this.serverless.cli.log('You are now logged in'); // because platform only support github - const id = decoded.original_user_id || decoded.sub; + const id = decoded.tracking_id || decoded.sub; /* For future use segment.identify({