@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
60 lines • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AwsConfigAccountClient = void 0;
const client_account_1 = require("@aws-sdk/client-account");
const AbstractClient_js_1 = require("../../customClients/AbstractClient.js");
const AwsConfigClientContext_js_1 = require("../AwsConfigClientContext.js");
const awsConfigUtils_js_1 = require("../awsConfigUtils.js");
/**
* Account client implementation using AWS Config as data source
*/
class AwsConfigAccountClient extends AbstractClient_js_1.AbstractClient {
static clientName = client_account_1.AccountClient.name;
constructor(options, customContext) {
super(options, customContext);
}
/**
* Register all Account command implementations
*/
registerCommands() {
this.registerCommand((0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_account_1.ListRegionsCommand,
execute: async (input, context) => {
const globalRegion = 'us-east-1';
const partition = context.partition;
if (partition !== 'aws') {
throw new Error(`Unknown global region for partition ${partition}. Please file an issue with the default region for your partition.`);
}
const accountId = context.accountId;
const query = `
SELECT
awsRegion
WHERE
accountId = '${accountId}'
AND ${awsConfigUtils_js_1.resourceStatusWhereClause}
GROUP BY
awsRegion
`;
const results = await (0, awsConfigUtils_js_1.executeConfigQuery)(query, context);
// Convert the results to the expected format
const uniqueRegions = new Set();
results.forEach((resultString) => {
const result = JSON.parse(resultString);
if (result.awsRegion === 'global') {
uniqueRegions.add(globalRegion);
}
else if (result.awsRegion) {
uniqueRegions.add(result.awsRegion);
}
});
return {
Regions: Array.from(uniqueRegions).map((regionName) => ({
RegionName: regionName
}))
};
}
}));
}
}
exports.AwsConfigAccountClient = AwsConfigAccountClient;
//# sourceMappingURL=AwsConfigAccountClient.js.map