Commit 94caa0b4 authored by Ahmad's avatar Ahmad

inikt

parent 7f606ae8
Pipeline #208 canceled with stages
...@@ -3,13 +3,15 @@ const path = require('path'); ...@@ -3,13 +3,15 @@ const path = require('path');
const csv = require('csv-parser'); const csv = require('csv-parser');
const AWS = require('aws-sdk'); const AWS = require('aws-sdk');
// Define the path to your Downloads directory
const downloadsPath = path.join(process.env.HOME || process.env.USERPROFILE, 'Downloads'); const downloadsPath = path.join(process.env.HOME || process.env.USERPROFILE, 'Downloads');
const rootKeyFilePath = path.join(downloadsPath, 'rootkey.csv');
// Define the path to your rootkey.csv file // Check if the rootkey.csv file exists
const rootKeyFilePath = path.join(process.env.HOME || process.env.USERPROFILE, 'rootkey.csv'); if (!fs.existsSync(rootKeyFilePath)) {
console.error(`File not found: ${rootKeyFilePath}`);
process.exit(1);
}
// Function to get AWS credentials from rootkey.csv
function getAWSCredentials() { function getAWSCredentials() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const credentials = {}; const credentials = {};
...@@ -31,22 +33,20 @@ function getAWSCredentials() { ...@@ -31,22 +33,20 @@ function getAWSCredentials() {
}); });
} }
// Function to get all .pem files and extract regions
function getPemFilesAndRegions() { function getPemFilesAndRegions() {
const pemFiles = fs.readdirSync(downloadsPath).filter(file => file.endsWith('.pem')); const pemFiles = fs.readdirSync(downloadsPath).filter(file => file.endsWith('.pem'));
const regions = new Set(); // Using Set to avoid duplicate regions const regions = new Set();
pemFiles.forEach(file => { pemFiles.forEach(file => {
const match = file.match(/LightsailDefaultKey-(.*)\.pem/); const match = file.match(/LightsailDefaultKey-(.*)\.pem/);
if (match) { if (match) {
regions.add(match[1]); // Extract region and add to Set regions.add(match[1]);
} }
}); });
return Array.from(regions); // Convert Set to Array return Array.from(regions);
} }
// Function to get all Lightsail instances in a given region
async function getLightsailInstances(region, credentials) { async function getLightsailInstances(region, credentials) {
const lightsail = new AWS.Lightsail({ const lightsail = new AWS.Lightsail({
region, region,
...@@ -63,7 +63,6 @@ async function getLightsailInstances(region, credentials) { ...@@ -63,7 +63,6 @@ async function getLightsailInstances(region, credentials) {
} }
} }
// Main function to execute the task
async function main() { async function main() {
try { try {
const credentials = await getAWSCredentials(); const credentials = await getAWSCredentials();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment