This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
70 lines (59 loc) · 2.02 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
61
62
63
64
65
66
67
68
69
require('dotenv').config();
const readline = require("readline-sync");
const fs = require('fs');
const myCOS = require("ibm-cos-sdk");
const config = {
endpoint: "",
apiKeyId: "",
};
const getFlowlogs = require("./backend/getFlowLogs").main;
//const getCollectors = require("./backend/getFlowLogs").getCollectors;
const getCOS = require("./backend/getFileFromCos");
const { getRegion } = require("./backend/getFlowLogs");
const { getCollectors } = require("./backend/getFlowLogs");
const { getTokens } = require("./backend/getFlowLogs");
const { formatCollectors } = require("./backend/getFlowLogs");
const { loadAPI } = require("./backend/getFlowLogs");
const { env } = require('process');
const { ConfigurationOptions } = require('ibm-cos-sdk/lib/config');
const main = async function () {
var option;
while (true) {
if (option != "wait")
option = readline.question(`choose option
1. get flowlogs
q. exit
\n`);
switch (option) {
case "1":
const envPath = '.env';
if (fs.existsSync(envPath)) {
if(process.env.API_KEY == ""){//if env file is empty
var setAPI = await loadAPI();
}
}
else{
var setAPI = await loadAPI();
}
var regionArr = getRegion();
var region = regionArr[0];
config.endpoint = regionArr[1];
//get token to call getColleectors
var access_token = await getTokens(process.env.API_KEY);
//set bucket name to env
var flowLogCollectors = await getCollectors(access_token, region);
var bucket_name = formatCollectors(flowLogCollectors);
// Retrieve all items from the COS bucket using .env
config.apiKeyId = process.env.API_KEY;
var cosClient = new myCOS.S3(config);
await getCOS.getBucketContents(bucket_name, cosClient);
break;
case "q":
console.log("returning...\n\n\n\n\n");
return;
default:
console.log("invalid option\n\n\n\n\n");
}
} while (option != -1);
};
module.exports.main = main;