// import anything you need import readline from "readline" // When we import from the module we created a basic template is: // import {class1, class2, ...} from "./moduleFilename.js" import {QueueInterface, TableInterface} from "./AzureModule.js" import {JiraTools} from "./JiraModule.js" import {addShit} from "./addToDB.js" import {sha256} from "js-sha256" const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); //create class object const tableClient = new TableInterface("NAUTableStorage"); const queueClient = new QueueInterface("versa-test-status"); const jiraClient = new JiraTools("wdcapstonetest", "VG"); const addIssues = new addShit(); const funcs = ["getNextMessage", "addMessage", "checkMessages", "clearMessages", "addIssue", "getAllIssues", "getIssueByID", "removeIssue", "addJiraIssuesToDB", "clearPartition", "getQueryString", "addFW", "removeFW", "getFWByID", "getAllFWs", "addVM", "removeVM", "getVMByID", "getAllVMs", "addFWsToDB", "addVMsToDB", "addSystemsToDB", "getSystemByID", "getAllSystems", "removeSystem", "moveToInProgress", "addReservation", "removeOldReservations", "addExeIssuesToDB", "addUser"]; const issues = [ { "id": "VG-1", "desc": "", "data": { "vm": "cal2", "vmstatus": "in-progress", "owner": "John Deer", "vmlocation": "San Francisco", "vmversion": "Ubuntu 12.3", "product": "WD Blue", "status": "Passing", "fwversion": "3.2.5", "commitid": "322042", "form": "7.5in", "fwlocation": "San Francisco", "serial": "38218AR8D2" } }, { "id": "VG-4", "desc": "Hello World", "data": { "vm": "cal10", "vmstatus": "Completed", "owner": "Lil John", "vmlocation": "San Francisco", "vmversion": "Windows 11", "product": "WD Black", "status": "Failed", "fwversion": "1.0.5", "commitid": "128233", "form": "M.2", "fwlocation": "San Francisco", "serial": "89283YSO2" } }, { "id": "VG-7", "desc": "Everything Broke", "data": { "vm": "wi4", "vmstatus": "in-progress", "owner": "John Cena", "vmlocation": "Madison", "vmversion": "Garuda 3.3", "product": "WD Blue", "status": "Failing", "fwversion": "0.2.5", "commitid": "553992", "form": "7.5in", "fwlocation": "San Francisco", "serial": "UL839V38" } } ]; console.log("Select function to run:"); for(let i = 0; i < funcs.length; i++) { console.log(i + ": " + funcs[i]); } // get input rl.question("", async (func) => { // pass input into arrow function var result = null; // check input and run respective function we want to test switch(func) { // Queue Operations case "0": rl.question("Number to remove: ", (num) => { for(let i = 0; i < num; i++) { queueClient.getNextMessage(); } // rl.close needs to be run in the innermost arrow function for each // branch of the program rl.close(); }); break; case "1": rl.question("Message to add: ", (message) => { queueClient.addMessage(message); rl.close(); }); break; case "2": console.log(queueClient.checkMessages()); rl.close(); break; case "3": queueClient.clearMessages(); rl.close(); break; // Table Operations case "4": rl.question("What role (FW, Dev or Exe): ", (role) => { rl.question("What issue to add (0:2): ", (issueNum) => { let issue = issues[parseInt(issueNum)]; console.log(tableClient.addIssue(role, issue)); rl.close(); }); }); break; case "5": result = await jiraClient.get_all_issues(); console.log(result); rl.close(); break; case "6": rl.question("What role (FW, Dev or Exe): ", async (role) => { let partition = role; rl.question("What is the issue id: ", async (id) => { result = await tableClient.getIssueByID(partition, id); console.log(result); rl.close(); }); }); break; case "7": rl.question("What role (FW, Dev or Exe): ", (role) => { let partition = role; rl.question("What is the issue id: ", async (id) => { result = await tableClient.removeIssue(partition, id); console.log(result); rl.close(); }); }); break; case "8": console.log("Here goes nothing"); addIssues.addJiraIssuesToDB(); rl.close(); break; case "9": rl.question("What partition: ", (partition) => { console.log("Here goes nothing"); console.log("trying to remove from " + partition); addIssues.clearPartition(partition); rl.close(); }); break; case "10": console.log("Bada bing bada boom"); rl.question("Please input arguments to function separated by spaces:\n", (argument) => { tableClient.getQueryString(argument.trim(" ")); rl.close(); }); break; case "11": break; case "12": rl.question("What is the FW id: ", async (id) => { result = await tableClient.removeFW(id); console.log(result); rl.close(); }); break; case "13": rl.question("What is the FW id: ", async (id) => { result = await tableClient.getFWByID(id); console.log(result); rl.close(); }); break; case "14": result = await tableClient.getAllFWs(); console.log(result); rl.close(); break; case "15": break; case "16": rl.question("What is the VM id: ", async (id) => { result = await tableClient.removeVM(id); console.log(result); rl.close(); }); break; case "17": rl.question("What is the VM id: ", async (id) => { result = await tableClient.getVMByID(id); console.log(result); rl.close(); }); break; case "18": result = await tableClient.getAllVMs(); console.log(result); rl.close(); break; case "19": console.log("Here goes nothing"); addIssues.addFWsToDB(); rl.close(); break; case "20": console.log("Here goes nothing"); addIssues.addVMsToDB(); rl.close(); break; case "21": addIssues.addSystemsToDB(); rl.close(); break; case "22": rl.question("What is the system id: ", async (id) => { result = await tableClient.getSystemByID(id); console.log(JSON.parse(result.data)); rl.close(); }); break; case "23": result = await tableClient.getAllSystems(); console.log(result); rl.close(); break; case "24": rl.question("What is the system id: ", async (id) => { result = await tableClient.removeSystem(id); console.log(result); rl.close(); }); break; case "25": result = await jiraClient.get_all_issues(); let i = 0; let completedIssues = []; for(const issue of result) { if(issue.status === "Done") { console.log(i + ": " + issue.id); completedIssues.push(issue.id); i++; } } rl.question("Select a issue: ", async (id) => { jiraClient.set_issue_status(completedIssues[id], 'In Progress'); // change status in DB result = await tableClient.modData(0, completedIssues[id], 1, "FW", {closed: "NA", status: 'In Progress'}); console.log(result); rl.close(); }); break; case "26": rl.question("What is the system id: ", async (id) => { const role = ["FW", "Dev", "Exe", "Manage"]; const vms = ["la", "sf", "wi", "az"]; const serials = [603735, 919120, 411894, 598273, 430917, 299357, 329593]; let day = Math.floor(1 + Math.random() * 28); let hour = Math.floor(1 + Math.random() * 16); let startTime = new Date('March ' + day + ', 2022 ' + hour + ':00:00'); let endTime = new Date('March ' + day + ', 2022 ' + (hour + 6) + ':00:00'); let reservation = { version: 2.0, type: role[Math.floor(Math.random() * role.length)], desc: "Reservation details " + Math.floor(Math.random() * 500), start: startTime, end: endTime, vm: vms[Math.floor(Math.random() * vms.length)] + Math.floor(Math.random() * 10), fw: serials[Math.floor(Math.random() * serials.length)] }; console.log(reservation); result = await tableClient.addReservation(id, reservation); console.log(result); rl.close(); }); break; case "27": rl.question("What is the system id: ", async (id) => { result = await tableClient.removeOldReservations(id); console.log(result); rl.close(); }); break; case "28": addIssues.addExeIssuesToDB(); rl.close(); break; case "29": rl.question("Email: ", async (email) => { rl.question("Password: ", async (pw) => { rl.question("Auth Level: ", async (auth) => { rl.question("Role: ", async (role) => { rl.question("Name: ", async (name) => { let hash = sha256(email); let pass = sha256(pw); let user = { id: hash, pw: pass, auth: auth, role: role, name: name }; result = await tableClient.addUser(user); rl.close(); }); }); }); }); }); break } });