UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

114 lines 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AwsConfigSNSClient = void 0; const client_sns_1 = require("@aws-sdk/client-sns"); 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 SNS client implementation */ class AwsConfigSNSClient extends AbstractClient_js_1.AbstractClient { static clientName = client_sns_1.SNSClient.name; constructor(options, customContext) { super(options, customContext); } /** * Register all SNS command implementations */ registerCommands() { this.registerCommand(AwsConfigGetTopicAttributesCommand); this.registerCommand(AwsConfigListTagsForResourceCommand); this.registerCommand(AwsConfigListTopicsCommand); } } exports.AwsConfigSNSClient = AwsConfigSNSClient; /** * Config-based implementation of SNS GetTopicAttributesCommand * * Maps SNS::Topic Config data to SNS GetTopicAttributesCommand output format. * Returns only the attributes used by the sync: DisplayName, KmsMasterKeyId, Owner, Policy. */ const AwsConfigGetTopicAttributesCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({ command: client_sns_1.GetTopicAttributesCommand, execute: async (input, context) => { const topicArn = input.TopicArn; const configuration = context.getCache(topicArn, 'configuration'); // Return only the attributes used by the sync operations const attributes = {}; if (configuration.DisplayName) { attributes['DisplayName'] = configuration.DisplayName; } if (configuration.KmsMasterKeyId) { attributes['KmsMasterKeyId'] = configuration.KmsMasterKeyId; } if (configuration.Owner) { attributes['Owner'] = configuration.Owner; } if (configuration.Policy) { attributes['Policy'] = configuration.Policy; } return { Attributes: attributes }; } }); /** * Config-based implementation of SNS ListTagsForResourceCommand * * Maps SNS::Topic Config tag data to SNS ListTagsForResourceCommand output format. * Returns topic tags for resource identification and compliance analysis. */ const AwsConfigListTagsForResourceCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({ command: client_sns_1.ListTagsForResourceCommand, execute: async (input, context) => { const resourceArn = input.ResourceArn; const tags = context.getCache(resourceArn, 'tags'); return { Tags: tags || {} }; } }); /** * Config-based implementation of SNS ListTopicsCommand * * Maps SNS::Topic Config data to SNS ListTopicsCommand output format. * Returns topic listing for IAM analysis and resource discovery. */ const AwsConfigListTopicsCommand = (0, AwsConfigClientContext_js_1.awsConfigCommand)({ command: client_sns_1.ListTopicsCommand, execute: async (input, context) => { const query = ` SELECT arn, resourceId, resourceName, configuration.TopicArn, configuration.DisplayName, configuration.KmsMasterKeyId, configuration.Owner, configuration.Policy, tags WHERE resourceType = 'AWS::SNS::Topic' AND awsRegion = '${context.region}' AND accountId = '${context.accountId}' AND ${awsConfigUtils_js_1.resourceStatusWhereClause} `; const results = await (0, awsConfigUtils_js_1.executeConfigQuery)(query, context); const topics = results.map((result) => { const { configItem, configuration, tags } = (0, awsConfigUtils_js_1.parseConfigItem)(result); // Cache data that will be needed by other commands context.putCache(configItem.arn, 'configuration', configuration); context.putCache(configItem.arn, 'tags', tags); return { TopicArn: configItem.arn }; }); return { Topics: topics, NextToken: undefined // Config doesn't provide pagination markers }; } }); //# sourceMappingURL=AwsConfigSNSClient.js.map