This repository has been archived by the owner on Dec 31, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
60 lines (50 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const _ = {
merge: require('lodash.merge')
}
class DefaultAwsProperties {
constructor(serverless) {
this.provider = serverless.getProvider('aws');
this.serverless = serverless.service;
this.hooks = {
'before:package:finalize': this.addDefaults.bind(this)
};
}
getDefaults() {
return this.serverless.custom.defaultAwsProperties || {};
}
mergeProperties({ original, additional }) {
// Do not override anything in original
return _.merge({}, additional, original);
}
addDefaults() {
const defaults = this.getDefaults()
.reduce(
(acc, d) => {
acc[d.Type] = (acc[d.Type] || []).concat([d]);
return acc;
},
{}
);
const resources = this.serverless.resources.Resources;
for(const [logicalId, resource] of Object.entries(resources)) {
const { Type } = resource;
const defaultsForType = defaults[Type];
if(defaultsForType) {
for(const d of defaultsForType) {
const {
Exclude: exclude,
Properties: defaultPropertiesForType
} = d;
if(!exclude || !exclude.includes(logicalId)) {
resource.Properties = this.mergeProperties({
original: resource.Properties,
additional: defaultPropertiesForType
});
}
}
}
}
}
}
module.exports = DefaultAwsProperties;