@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
105 lines • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AwsConfigSQSClient = void 0;
const client_sqs_1 = require("@aws-sdk/client-sqs");
const AbstractClient_js_1 = require("../../customClients/AbstractClient.js");
const AwsConfigClientContext_js_1 = require("../AwsConfigClientContext.js");
const awsConfigUtils_js_1 = require("../awsConfigUtils.js");
/**
* AWS Config-based SQS client implementation
*/
class AwsConfigSQSClient extends AbstractClient_js_1.AbstractClient {
static clientName = client_sqs_1.SQSClient.name;
constructor(options, customContext) {
super(options, customContext);
}
/**
* Register all SQS command implementations
*/
registerCommands() {
this.registerCommand(AwsConfigGetQueueAttributesCommand);
this.registerCommand(AwsConfigListQueueTagsCommand);
this.registerCommand(AwsConfigListQueuesCommand);
}
}
exports.AwsConfigSQSClient = AwsConfigSQSClient;
/**
* Config-based implementation of SQS ListQueuesCommand
*
* Maps SQS::Queue Config data to SQS ListQueuesCommand output format.
* Returns queue URL listing for IAM analysis and resource discovery.
*/
const AwsConfigListQueuesCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_sqs_1.ListQueuesCommand,
execute: async (input, context) => {
const query = `
SELECT
arn,
resourceId,
resourceName,
configuration.QueueUrl,
configuration.QueueName,
configuration.KmsMasterKeyId,
configuration.Policy,
tags
WHERE
resourceType = 'AWS::SQS::Queue'
AND awsRegion = '${context.region}'
AND accountId = '${context.accountId}'
AND ${awsConfigUtils_js_1.resourceStatusWhereClause}
`;
const results = await (0, awsConfigUtils_js_1.executeConfigQuery)(query, context);
const queueUrls = results.map((result) => {
const { configItem, configuration, tags } = (0, awsConfigUtils_js_1.parseConfigItem)(result);
context.putCache(configItem.resourceId, 'configuration', configuration);
context.putCache(configItem.resourceId, 'tags', tags);
// Use QueueUrl from config if available, otherwise construct from QueueName
return configItem.resourceId;
});
return {
QueueUrls: queueUrls,
NextToken: undefined // Config doesn't provide pagination markers
};
}
});
/**
* Config-based implementation of SQS GetQueueAttributesCommand
*
* Maps SQS::Queue Config data to SQS GetQueueAttributesCommand output format.
* Returns only the attributes used by the sync: KmsMasterKeyId, Policy.
*/
const AwsConfigGetQueueAttributesCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_sqs_1.GetQueueAttributesCommand,
execute: async (input, context) => {
const queueUrl = input.QueueUrl;
const configuration = context.getCache(queueUrl, 'configuration');
// Return only the attributes used by the sync operations
const attributes = {};
if (configuration.KmsMasterKeyId) {
attributes['KmsMasterKeyId'] = configuration.KmsMasterKeyId;
}
if (configuration.Policy) {
attributes['Policy'] = configuration.Policy;
}
return {
Attributes: attributes
};
}
});
/**
* Config-based implementation of SQS ListQueueTagsCommand
*
* Maps SQS::Queue Config tag data to SQS ListQueueTagsCommand output format.
* Returns queue tags for resource identification and compliance analysis.
*/
const AwsConfigListQueueTagsCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({
command: client_sqs_1.ListQueueTagsCommand,
execute: async (input, context) => {
const queueUrl = input.QueueUrl;
const value = context.getCache(queueUrl, 'tags');
return {
Tags: value || {}
};
}
});
//# sourceMappingURL=AwsConfigSQSClient.js.map