Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require provider.credentials vars to be resolved before s3/ssm/cf vars #5763

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/classes/Variables.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -102,10 +102,31 @@ class Variables {
const requiredConfigs = [ const requiredConfigs = [
_.assign({ name: 'region' }, provider.getRegionSourceValue()), _.assign({ name: 'region' }, provider.getRegionSourceValue()),
_.assign({ name: 'stage' }, provider.getStageSourceValue()), _.assign({ name: 'stage' }, provider.getStageSourceValue()),
_.assign({ name: 'profile' }, { {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this requiredConfigs above mean that those are required to be present (e.g. users need to put in region, stage, porfile, etc.)? At least it reads like that. Pretty sure that's not the case. Just want to make sure that this is not a breaking change...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the name is a little misleading. It works just fine when they're not set. They'r required to be prepopulated if they're set.

name: 'profile',
value: this.service.provider.profile, value: this.service.provider.profile,
path: 'serverless.service.provider.profile', path: 'serverless.service.provider.profile',
}), },
{
name: 'credentials',
value: this.service.provider.credentials,
path: 'serverless.service.provider.credentials',
},
{
name: 'credentials.accessKeyId',
value: _.get(this, 'service.provider.credentials.accessKeyId'),
path: 'serverless.service.provider.credentials.accessKeyId',
},
{
name: 'credentials.secretAccessKey',
value: _.get(this, 'service.provider.credentials.secretAccessKey'),
path: 'serverless.service.provider.credentials.secretAccessKey',
},
{
name: 'credentials.sessionToken',
value: _.get(this, 'service.provider.credentials.sessionToken'),
path: 'serverless.service.provider.credentials.sessionToken',
},
]; ];
return this.disableDepedentServices(() => { return this.disableDepedentServices(() => {
const prepopulations = requiredConfigs.map(config => const prepopulations = requiredConfigs.map(config =>
Expand Down
24 changes: 22 additions & 2 deletions lib/classes/Variables.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const path = require('path');
const proxyquire = require('proxyquire'); const proxyquire = require('proxyquire');
const sinon = require('sinon'); const sinon = require('sinon');
const YAML = require('js-yaml'); const YAML = require('js-yaml');
const _ = require('lodash');


const AwsProvider = require('../plugins/aws/provider/awsProvider'); const AwsProvider = require('../plugins/aws/provider/awsProvider');
const fse = require('../utils/fs/fse'); const fse = require('../utils/fs/fse');
Expand Down Expand Up @@ -148,11 +149,30 @@ describe('Variables', () => {
{ name: 'region', getter: (provider) => provider.getRegion() }, { name: 'region', getter: (provider) => provider.getRegion() },
{ name: 'stage', getter: (provider) => provider.getStage() }, { name: 'stage', getter: (provider) => provider.getStage() },
{ name: 'profile', getter: (provider) => provider.getProfile() }, { name: 'profile', getter: (provider) => provider.getProfile() },
{
name: 'credentials',
getter: (provider) => provider.serverless.service.provider.credentials,
},
{
name: 'credentials.accessKeyId',
getter: (provider) => provider.serverless.service.provider.credentials.accessKeyId,
},
{
name: 'credentials.secretAccessKey',
getter: (provider) => provider.serverless.service.provider.credentials.secretAccessKey,
},
{
name: 'credentials.sessionToken',
getter: (provider) => provider.serverless.service.provider.credentials.sessionToken,
},
]; ];
describe('basic population tests', () => { describe('basic population tests', () => {
prepopulatedProperties.forEach((property) => { prepopulatedProperties.forEach((property) => {
it(`should populate variables in ${property.name} values`, () => { it(`should populate variables in ${property.name} values`, () => {
awsProvider.serverless.service.provider[property.name] = '${self:foobar, "default"}'; _.set(
awsProvider.serverless.service.provider,
property.name,
'${self:foobar, "default"}');
return serverless.variables.populateService().should.be.fulfilled return serverless.variables.populateService().should.be.fulfilled
.then(() => expect(property.getter(awsProvider)).to.be.eql('default')); .then(() => expect(property.getter(awsProvider)).to.be.eql('default'));
}); });
Expand All @@ -168,7 +188,7 @@ describe('Variables', () => {
prepopulatedProperties.forEach(property => { prepopulatedProperties.forEach(property => {
dependentConfigs.forEach(config => { dependentConfigs.forEach(config => {
it(`should reject ${config.name} variables in ${property.name} values`, () => { it(`should reject ${config.name} variables in ${property.name} values`, () => {
awsProvider.serverless.service.provider[property.name] = config.value; _.set(awsProvider.serverless.service.provider, property.name, config.value);
return serverless.variables.populateService() return serverless.variables.populateService()
.should.be.rejectedWith('Variable dependency failure'); .should.be.rejectedWith('Variable dependency failure');
}); });
Expand Down