Skip to content

Commit 721f8b6

Browse files
authored
Merge pull request serverless#4859 from erikerikson/self-service-rewrite
Re-write `self:service.[...]` to `self:serviceObject.[...]`
2 parents 1e72743 + 71c6db9 commit 721f8b6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/classes/Variables.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ class Variables {
525525
}
526526

527527
getValueFromSelf(variableString) {
528+
const selfServiceRex = /self:service\./;
528529
let variable = variableString;
529530
// ###################################################################
530531
// ## KEEP SYNCHRONIZED WITH EQUIVALENT IN ~/lib/classes/Service.js ##
@@ -534,8 +535,9 @@ class Variables {
534535
// Account for these so that user's reference to their file populate properly
535536
if (variable === 'self:service.name') {
536537
variable = 'self:service';
537-
}
538-
if (variable === 'self:provider') {
538+
} else if (variable.match(selfServiceRex)) {
539+
variable = variable.replace(selfServiceRex, 'self:serviceObject.');
540+
} else if (variable === 'self:provider') {
539541
variable = 'self:provider.name';
540542
}
541543
const valueToPopulate = this.service;

lib/classes/Variables.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,18 @@ module.exports = {
11561156
};
11571157
return serverless.variables.getValueFromSelf('self:provider').should.become('aws');
11581158
});
1159+
it('should redirect ${self:service.awsKmsKeyArn} to ${self:serviceObject.awsKmsKeyArn}', () => {
1160+
const keyArn = 'arn:aws:kms:us-east-1:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
1161+
serverless.variables.service = {
1162+
service: 'testService',
1163+
serviceObject: {
1164+
name: 'testService',
1165+
awsKmsKeyArn: keyArn,
1166+
},
1167+
};
1168+
return serverless.variables.getValueFromSelf('self:service.awsKmsKeyArn')
1169+
.should.become(keyArn);
1170+
});
11591171
it('should handle self-references to the root of the serverless.yml file', () => {
11601172
serverless.variables.service = {
11611173
service: 'testService',

0 commit comments

Comments
 (0)