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
50a738dd
Commit
50a738dd
authored
Aug 18, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
d3891be3
Pipeline
#211
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
28 deletions
+14
-28
app.js
app.js
+14
-28
No files found.
app.js
View file @
50a738dd
const
fs
=
require
(
'
fs
'
);
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
path
=
require
(
'
path
'
);
const
csv
=
require
(
'
csv-parser
'
);
const
AWS
=
require
(
'
aws-sdk
'
);
const
AWS
=
require
(
'
aws-sdk
'
);
const
downloadsPath
=
path
.
join
(
process
.
env
.
HOME
||
process
.
env
.
USERPROFILE
,
'
Downloads
'
);
const
downloadsPath
=
path
.
join
(
process
.
env
.
HOME
||
process
.
env
.
USERPROFILE
,
'
Downloads
'
);
...
@@ -12,33 +11,20 @@ if (!fs.existsSync(rootKeyFilePath)) {
...
@@ -12,33 +11,20 @@ if (!fs.existsSync(rootKeyFilePath)) {
process
.
exit
(
1
);
process
.
exit
(
1
);
}
}
function
getAWSCredentials
()
{
// Function to extract AWS credentials using regex
return
new
Promise
((
resolve
,
reject
)
=>
{
function
extractAWSCredentials
(
filePath
)
{
let
credentials
=
null
;
const
fileContent
=
fs
.
readFileSync
(
filePath
,
'
utf8
'
);
const
accessKeyIdMatch
=
fileContent
.
match
(
/Access key ID
\s
*,
\s
*
([^
,
\s]
+
)
/i
);
const
secretAccessKeyMatch
=
fileContent
.
match
(
/Secret access key
\s
*,
\s
*
([^
,
\s]
+
)
/i
);
fs
.
createReadStream
(
rootKeyFilePath
)
if
(
accessKeyIdMatch
&&
secretAccessKeyMatch
)
{
.
pipe
(
csv
())
return
{
.
on
(
'
data
'
,
(
row
)
=>
{
accessKeyId
:
accessKeyIdMatch
[
1
],
console
.
log
(
'
Parsed row:
'
,
row
);
// Log the parsed row for debugging
secretAccessKey
:
secretAccessKeyMatch
[
1
],
};
// Adjust for BOM in the header
}
else
{
const
accessKeyIdHeader
=
Object
.
keys
(
row
)[
0
].
replace
(
/^
\u
FEFF/
,
''
);
// Removes BOM if present
throw
new
Error
(
'
Failed to extract AWS credentials from rootkey.csv
'
);
if
(
accessKeyIdHeader
===
'
Access key ID
'
&&
row
[
'
Secret access key
'
])
{
}
credentials
=
{
accessKeyId
:
row
[
accessKeyIdHeader
].
trim
(),
secretAccessKey
:
row
[
'
Secret access key
'
].
trim
(),
};
}
})
.
on
(
'
end
'
,
()
=>
{
if
(
credentials
)
{
resolve
(
credentials
);
}
else
{
reject
(
new
Error
(
'
Failed to load AWS credentials from rootkey.csv
'
));
}
})
.
on
(
'
error
'
,
(
error
)
=>
reject
(
error
));
});
}
}
function
getPemFilesAndRegions
()
{
function
getPemFilesAndRegions
()
{
...
@@ -73,7 +59,7 @@ async function getLightsailInstances(region, credentials) {
...
@@ -73,7 +59,7 @@ async function getLightsailInstances(region, credentials) {
async
function
main
()
{
async
function
main
()
{
try
{
try
{
const
credentials
=
await
getAWSCredentials
(
);
const
credentials
=
extractAWSCredentials
(
rootKeyFilePath
);
console
.
log
(
'
AWS Credentials Loaded:
'
,
credentials
);
// Log loaded credentials for debugging
console
.
log
(
'
AWS Credentials Loaded:
'
,
credentials
);
// Log loaded credentials for debugging
const
regions
=
getPemFilesAndRegions
();
const
regions
=
getPemFilesAndRegions
();
...
...
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