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

Resolve profile before performing aws-sdk dependent actions #5744

Merged
merged 2 commits into from
Jan 28, 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
4 changes: 4 additions & 0 deletions lib/classes/Variables.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ 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' }, {
value: this.service.provider.profile,
path: 'serverless.service.provider.profile',
}),
]; ];
return this.disableDepedentServices(() => { return this.disableDepedentServices(() => {
const prepopulations = requiredConfigs.map(config => const prepopulations = requiredConfigs.map(config =>
Expand Down
11 changes: 6 additions & 5 deletions lib/classes/Variables.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ describe('Variables', () => {
const prepopulatedProperties = [ const prepopulatedProperties = [
{ 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() },
]; ];
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.options[property.name] = '${self:foobar, "default"}'; 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 @@ -167,15 +168,15 @@ 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.options[property.name] = config.value; 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');
}); });
it(`should reject recursively dependent ${config.name} service dependencies`, () => { it(`should reject recursively dependent ${config.name} service dependencies`, () => {
serverless.variables.service.custom = { serverless.variables.service.custom = {
settings: config.value, settings: config.value,
}; };
awsProvider.options.region = '${self:custom.settings.region}'; awsProvider.serverless.service.provider.region = '${self:custom.settings.region}';
return serverless.variables.populateService() return serverless.variables.populateService()
.should.be.rejectedWith('Variable dependency failure'); .should.be.rejectedWith('Variable dependency failure');
}); });
Expand All @@ -196,8 +197,8 @@ describe('Variables', () => {
{ name: 'getValueFromS3', original: serverless.variables.getValueFromS3 }, { name: 'getValueFromS3', original: serverless.variables.getValueFromS3 },
{ name: 'getValueFromSsm', original: serverless.variables.getValueFromSsm }, { name: 'getValueFromSsm', original: serverless.variables.getValueFromSsm },
]; ];
awsProvider.options.region = combination.region; awsProvider.serverless.service.provider.region = combination.region;
awsProvider.options.state = combination.state; awsProvider.serverless.service.provider.state = combination.state;
return serverless.variables.populateService().should.be.fulfilled return serverless.variables.populateService().should.be.fulfilled
.then(() => { .then(() => {
dependentMethods.forEach((method) => { dependentMethods.forEach((method) => {
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/provider/awsProvider.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class AwsProvider {


getProfileSourceValue() { getProfileSourceValue() {
const values = this.getValues(this, [ const values = this.getValues(this, [
['options', 'aws-profile'],
dschep marked this conversation as resolved.
Show resolved Hide resolved
['options', 'profile'], ['options', 'profile'],
['serverless', 'config', 'profile'], ['serverless', 'config', 'profile'],
['serverless', 'service', 'provider', 'profile'], ['serverless', 'service', 'provider', 'profile'],
Expand Down