Merge pull request #5744 from serverless/fix-sls-4311

Resolve profile before performing aws-sdk dependent actions
This commit is contained in:
Daniel Schep 2019-01-28 10:10:07 -05:00 committed by GitHub
commit 03d8cebee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -102,6 +102,10 @@ class Variables {
const requiredConfigs = [
_.assign({ name: 'region' }, provider.getRegionSourceValue()),
_.assign({ name: 'stage' }, provider.getStageSourceValue()),
_.assign({ name: 'profile' }, {
value: this.service.provider.profile,
path: 'serverless.service.provider.profile',
}),
];
return this.disableDepedentServices(() => {
const prepopulations = requiredConfigs.map(config =>

View File

@ -147,11 +147,12 @@ describe('Variables', () => {
const prepopulatedProperties = [
{ name: 'region', getter: (provider) => provider.getRegion() },
{ name: 'stage', getter: (provider) => provider.getStage() },
{ name: 'profile', getter: (provider) => provider.getProfile() },
];
describe('basic population tests', () => {
prepopulatedProperties.forEach((property) => {
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
.then(() => expect(property.getter(awsProvider)).to.be.eql('default'));
});
@ -167,7 +168,7 @@ describe('Variables', () => {
prepopulatedProperties.forEach(property => {
dependentConfigs.forEach(config => {
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()
.should.be.rejectedWith('Variable dependency failure');
});
@ -175,7 +176,7 @@ describe('Variables', () => {
serverless.variables.service.custom = {
settings: config.value,
};
awsProvider.options.region = '${self:custom.settings.region}';
awsProvider.serverless.service.provider.region = '${self:custom.settings.region}';
return serverless.variables.populateService()
.should.be.rejectedWith('Variable dependency failure');
});
@ -196,8 +197,8 @@ describe('Variables', () => {
{ name: 'getValueFromS3', original: serverless.variables.getValueFromS3 },
{ name: 'getValueFromSsm', original: serverless.variables.getValueFromSsm },
];
awsProvider.options.region = combination.region;
awsProvider.options.state = combination.state;
awsProvider.serverless.service.provider.region = combination.region;
awsProvider.serverless.service.provider.state = combination.state;
return serverless.variables.populateService().should.be.fulfilled
.then(() => {
dependentMethods.forEach((method) => {

View File

@ -410,6 +410,7 @@ class AwsProvider {
getProfileSourceValue() {
const values = this.getValues(this, [
['options', 'aws-profile'],
['options', 'profile'],
['serverless', 'config', 'profile'],
['serverless', 'service', 'provider', 'profile'],