-
Notifications
You must be signed in to change notification settings - Fork 5
/
transform.js
35 lines (32 loc) · 942 Bytes
/
transform.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
var _ = require('lodash');
var transformPromise = function (data) {
var promise = new Promise(function (resolve, rejct) {
var securityGroups = data.SecurityGroups;
// console.dir(securityGroups);
resolve(_(securityGroups)
.map(function (sg) {
var ingress = sg.IpPermissions.map(function (i) {
var name;
if (i.UserIdGroupPairs.length > 0) {
var name = _.find(securityGroups, _.matchesProperty('GroupId', i.UserIdGroupPairs[0].GroupId));
name = name.GroupName;
} else {
name = i.IpRanges[0].CidrIp;
}
return {
name: name,
protocol: i.IpProtocol,
fromPort: i.FromPort
};
});
return {
name: sg.GroupName,
id: sg.GroupId,
ingress: ingress
};
})
.value());
});
return promise;
};
module.exports = transformPromise;