-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.js
More file actions
57 lines (45 loc) · 1.6 KB
/
services.js
File metadata and controls
57 lines (45 loc) · 1.6 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
const fs = require('fs');
const csv = require('csv-parser');
function createServicesFromCSV(filePath) {
const awsServices = {};
const fileData = fs.readFileSync(filePath, 'utf-8');
const rows = fileData.split('\n').slice(1); // Split data by newline and skip the header
for (const row of rows) {
const columns = row.split(',');
const serviceAction = columns[1]?.trim(); // Assuming 'Action' is in the second column
const serviceName = serviceAction?.split(':')[0];
const action = serviceAction?.split(':')[1]?.trim();
if (serviceName && !awsServices[serviceName]) {
awsServices[serviceName] = createAwsServiceRule(serviceName);
}
// if (action && !awsServices[action]) {
// awsServices[action] = createActionRule(action);
// }
}
return awsServices;
}
function createAwsServiceRule(serviceName) {
serviceName = serviceName.trim().replace(/^\"/, "").replace(/\"$/, "");
serviceName = serviceName.split("").map(char => {
if (char.match(/[a-zA-Z]/)) {
return `[${char.toLowerCase()}${char.toUpperCase()}]`;
} else {
return char;
}
}).join("");
return new RegExp(serviceName);
}
function createActionRule(action) {
action = action.trim().replace(/^\"/, "").replace(/\"$/, "");
action = action.split("").map(char => {
if (char.match(/[a-zA-Z]/)) {
return `[${char.toLowerCase()}${char.toUpperCase()}]`;
} else {
return char;
}
}).join("");
return new RegExp(action);
}
const csvFilePath = './AwsServiceActions.csv';
const services = createServicesFromCSV(csvFilePath);
module.exports = services;