From 94fa416059242d43cf75ebe62bc24bd6fafd7f52 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Thu, 21 Jul 2016 19:14:48 +0900 Subject: [PATCH 1/2] provider property can now be an object --- lib/Serverless.js | 2 +- lib/classes/Service.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Serverless.js b/lib/Serverless.js index 0a4a4c44e..a9bb3529d 100644 --- a/lib/Serverless.js +++ b/lib/Serverless.js @@ -54,7 +54,7 @@ class Serverless { .then(() => { // set the provider of the service (so that the PluginManager takes care to // execute the correct provider specific plugins) - this.pluginManager.setProvider(this.service.provider); + this.pluginManager.setProvider(this.service.provider.name); // load all plugins this.pluginManager.loadAllPlugins(this.service.plugins); diff --git a/lib/classes/Service.js b/lib/classes/Service.js index ce6150a6c..e10585222 100644 --- a/lib/classes/Service.js +++ b/lib/classes/Service.js @@ -44,7 +44,8 @@ class Service { return that.serverless.yamlParser .parse(path.join(servicePath, 'serverless.yaml')) - .then((serverlessYaml) => { + .then((serverlessYamlParam) => { + const serverlessYaml = serverlessYamlParam; // basic service level validation if (!serverlessYaml.service) { throw new SError('"service" property is missing in serverless.yaml'); @@ -59,9 +60,16 @@ class Service { throw new SError('"functions" property is missing in serverless.yaml'); } - if (['aws', 'azure', 'google', 'ibm'].indexOf(serverlessYaml.provider)) { + if (typeof serverlessYaml.provider !== 'object') { + const providerName = serverlessYaml.provider; + serverlessYaml.provider = { + name: providerName, + }; + } + + if (['aws', 'azure', 'google', 'ibm'].indexOf(serverlessYaml.provider.name)) { const errorMessage = [ - `Provider "${serverlessYaml.provider}" is not supported.`, + `Provider "${serverlessYaml.provider.name}" is not supported.`, ' Valid values for provider are: aws, azure, google, ibm.', ' Please provide one of those values to the "provider" property in serverless.yaml.', ].join(''); From 252abe597ec76d4276f21e4b393f3bab19d890c6 Mon Sep 17 00:00:00 2001 From: "Eslam A. Hefnawy" Date: Thu, 21 Jul 2016 19:18:35 +0900 Subject: [PATCH 2/2] fixed tests for provider config --- lib/classes/Service.js | 2 +- tests/classes/Service.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/classes/Service.js b/lib/classes/Service.js index e10585222..0a9d33cd7 100644 --- a/lib/classes/Service.js +++ b/lib/classes/Service.js @@ -14,7 +14,7 @@ class Service { // Default properties this.service = null; - this.provider = null; + this.provider = {}; this.runtime = null; this.defaults = { stage: 'dev', diff --git a/tests/classes/Service.js b/tests/classes/Service.js index e10400353..3aa17db46 100644 --- a/tests/classes/Service.js +++ b/tests/classes/Service.js @@ -21,7 +21,7 @@ describe('Service', () => { const serviceInstance = new Service(serverless); expect(serviceInstance.service).to.be.equal(null); - expect(serviceInstance.provider).to.be.equal(null); + expect(serviceInstance.provider).to.deep.equal({}); expect(serviceInstance.runtime).to.be.equal(null); expect(serviceInstance.variableSyntax).to.be.equal(null); expect(serviceInstance.custom).to.deep.equal({}); @@ -151,7 +151,7 @@ describe('Service', () => { }; return serviceInstance.load().then((loadedService) => { expect(loadedService.service).to.be.equal('commonVar'); - expect(loadedService.provider).to.be.equal('aws'); + expect(loadedService.provider).to.deep.equal({ name: 'aws' }); expect(loadedService.runtime).to.be.equal('nodejs4.3'); expect(loadedService.plugins).to.deep.equal(['testPlugin']); expect(loadedService.environment.vars).to.deep.equal(commonVars);