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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+45 −4
Diff settings

Always

Just for now

Copy path View file
@@ -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' }, { {

This comment has been minimized.

@pmuens

pmuens Jan 30, 2019

Member

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...

This comment has been minimized.

@dschep

dschep Jan 30, 2019

Author Member

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 =>
Copy path View file
@@ -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');
@@ -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'));
}); });
@@ -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');
}); });
ProTip! Use n and p to navigate between commits in a pull request.