forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
119 lines (107 loc) · 4.35 KB
/
Copy pathfunctions.js
File metadata and controls
119 lines (107 loc) · 4.35 KB
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
function getResource(obj) {
// Returns a unique resource name given an object
if (obj.url) {
// Parse URL into resource
return obj.url;
} else {
return null;
}
}
var dataBlacklist = [
'node_id', 'avatar_url', 'gravatar_id', 'followers_url', 'following_url', 'gists_url', 'starred_url',
'subscriptions_url', 'organizations_url', 'repos_url', 'events_url', 'received_events_url', 'forks_url',
'keys_url', 'collaborators_url', 'teams_url', 'hooks_url', 'issue_events_url', 'events_url', 'assignees_url',
'branches_url', 'tags_url', 'blobs_url', 'git_tags_url', 'git_refs_url', 'trees_url', 'statuses_url',
'languages_url', 'stargazers_url', 'contributors_url', 'subscribers_url', 'subscription_url', 'commits_url',
'git_commits_url', 'comments_url', 'issue_comment_url', 'contents_url', 'compare_url', 'merges_url',
'archive_url', 'downloads_url', 'issues_url', 'pulls_url', 'milestones_url', 'notifications_url',
'labels_url', 'releases_url', 'deployments_url', 'git_url', 'ssh_url', 'clone_url', 'svn_url',
'mirror_url'
];
var errBlacklist = [
'access-control-allow-origin', 'access-control-expose-headers', 'connection', 'content-encoding',
'content-security-policy', 'content-type', 'expect-ct', 'referrer-policy', 'retry-after',
'strict-transport-security', 'transfer-encoding', 'x-content-type-options', 'x-frame-options',
'x-github-media-type', 'x-xss-protection', 'user-agent', 'accept'
];
function cleanCollection(collection) {
// Remove unnecessary properties from collection
function processObj(obj, blacklist) {
if (typeof obj == 'string') {
return;
} else if (Array.isArray(obj)) {
for (var i in obj) {
processObj(obj[i], blacklist);
}
} else {
for (var prop in obj) {
if (typeof obj[prop] == 'string') {
if (blacklist.indexOf(prop) > -1) {
delete obj[prop];
}
} else {
processObj(obj[prop], blacklist);
}
}
}
}
for (var service in collection) {
for (var call in collection[service]) {
if (collection[service][call].data) {
processObj(collection[service][call].data, dataBlacklist);
} else if (collection[service][call].err) {
processObj(collection[service][call].err, errBlacklist);
} else {
for (var c in collection[service][call]) {
if (collection[service][call][c].data) {
processObj(collection[service][call][c].data, dataBlacklist);
} else if (collection[service][call][c].err) {
processObj(collection[service][call][c].err, errBlacklist);
}
}
}
}
}
}
function addSource(cache, source, paths){
// paths = array of arrays (props of each element; service, call, region, extra)
var service = paths[0];
var call = paths[1];
var extra = paths[2];
if (!source[service]) source[service] = {};
if (!source[service][call]) source[service][call] = {};
if (!source[service][call]) source[service][call] = {};
var original;
if (extra) {
original = (cache[service] &&
cache[service][call] &&
cache[service][call] &&
cache[service][call][extra]) ?
cache[service][call][extra] : null;
source[service][call][extra] = original;
} else {
original = (cache[service] &&
cache[service][call] &&
cache[service][call]) ?
cache[service][call] : null;
source[service][call] = original;
}
return original;
}
function addError(original){
if (!original || !original.err) {
return 'Unable to obtain data';
} else if (typeof original.err === 'string') {
return original.err;
} else if (original.err.name && original.err.status) {
return original.err.name + ':' + original.err.status;
} else {
return 'Unable to obtain data';
}
}
module.exports = {
getResource: getResource,
cleanCollection: cleanCollection,
addSource: addSource,
addError: addError
};