Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aws
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
aws
Commits
94caa0b4
Commit
94caa0b4
authored
Aug 18, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
7f606ae8
Pipeline
#208
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
app.js
app.js
+9
-10
No files found.
app.js
View file @
94caa0b4
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment