/
config.js
135 lines (132 loc) · 4.67 KB
/
config.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const _ = require('lodash')
const rules = _.sortBy(${rules}, 'priority')
function getDestinationsFromMatchingRules({bucket, key, tags, eventType}) {
const tagObject = _.reduce(tags, (acc, v, k) => {
acc[v.Key] = v.Value
return acc
}, {})
const applicableRules = _.filter(rules, (rule) => {
return (
(_.startsWith(eventType, "ObjectCreated") || (_.startsWith(eventType, "ObjectRemoved") && rule.replicate_delete)) &&
_.startsWith(key, rule.filter.prefix || "") &&
_.endsWith(key, rule.filter.suffix || "") &&
_.reduce(rule.filter.tags, (acc, v, k) => {
return acc && tagObject[k] === v
}, true)
)
})
if (applicableRules.length) {
if (_.startsWith(eventType, "ObjectCreated")) {
const completionTags = _.uniqBy(_.flatten(_.map(applicableRules, (rule) => _.get(rule, 'completion_tags'))), 'Key')
return {
copy: _.map(applicableRules, () => true),
storageClass: _.map(applicableRules, (rule) => _.get(rule, 'destination.storage_class') || 'STANDARD'),
completionTags: completionTags.length ? {TagSet: completionTags} : null,
bucket: _.map(applicableRules, (rule) => rule.destination.bucket === "" ? "${default_destination_bucket}" : rule.destination.bucket),
copySource: _.map(applicableRules, () => '/' + bucket + '/' + key),
key: _.map(applicableRules, (rule) => (rule.destination.prefix || "") + _.replace(key, rule.filter.prefix, "")),
}
} else if (_.startsWith(eventType, "ObjectRemoved")) {
return {
delete: _.map(applicableRules, () => true),
bucket: _.map(applicableRules, (rule) => rule.destination.bucket === "" ? "${default_destination_bucket}" : rule.destination.bucket),
key: _.map(applicableRules, (rule) => (rule.destination.prefix || "") + _.replace(key, rule.filter.prefix, "")),
}
}
}
}
module.exports = {
stages: {
tags: {
index: 0,
transformers: {
key: {ref: 'event.Records[0].s3.object.decodedKey'},
bucket: {ref: 'event.Records[0].s3.bucket.name'},
},
dependencies: {
getTags: {
action: 'exploranda',
condition: {
helper: ({eventType}) => _.startsWith(eventType, 'ObjectCreated'),
params: {
eventType: {ref: 'event.Records[0].eventName'},
},
},
params: {
accessSchema: {value: 'dataSources.AWS.s3.getObjectTagging'},
params: {
explorandaParams: {
Bucket: { ref: 'stage.bucket'},
Key: { ref: 'stage.key'},
}
}
},
}
},
},
process: {
index: 1,
transformers: {
actionConfig: {
helper: getDestinationsFromMatchingRules,
params: {
tags: {ref: 'tags.results.getTags.TagSet'},
key: {ref: 'tags.vars.key'},
bucket: {ref: 'event.Records[0].s3.bucket.name'},
eventType: {ref: 'event.Records[0].eventName'},
},
},
},
dependencies: {
copy: {
condition: {ref: 'stage.actionConfig.copy'},
action: 'exploranda',
params: {
accessSchema: {value: 'dataSources.AWS.s3.copyObject'},
params: {
explorandaParams: {
CopySource: { ref: 'stage.actionConfig.copySource'},
StorageClass: { ref: 'stage.actionConfig.storageClass'},
Bucket: { ref: 'stage.actionConfig.bucket' },
Key: { ref: 'stage.actionConfig.key' },
}
}
},
},
delete: {
condition: {ref: 'stage.actionConfig.delete'},
action: 'exploranda',
params: {
accessSchema: {value: 'dataSources.AWS.s3.deleteObject'},
params: {
explorandaParams: {
Bucket: {ref: 'stage.actionConfig.bucket' },
Key: { ref: 'stage.actionConfig.key' },
}
}
},
},
},
},
tagReplicationComplete: {
condition: {ref: 'process.vars.actionConfig.completionTags'},
index: 2,
dependencies: {
tag: {
condition: {ref: 'process.vars.actionConfig.copy'},
action: 'exploranda',
params: {
accessSchema: {value: 'dataSources.AWS.s3.putObjectTagging'},
params: {
explorandaParams: {
Key: {ref: 'tags.vars.key'},
Bucket: {ref: 'event.Records[0].s3.bucket.name'},
Tagging: {ref: 'process.vars.actionConfig.completionTags'}
}
}
},
},
},
},
},
}