@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
64 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SnsTopicsSync = void 0;
const client_sns_1 = require("@aws-sdk/client-sns");
const log_js_1 = require("../../utils/log.js");
const typedSync_js_1 = require("../typedSync.js");
exports.SnsTopicsSync = (0, typedSync_js_1.createTypedSyncOperation)('sns', 'topics', (0, typedSync_js_1.createResourceSyncType)({
client: client_sns_1.SNSClient,
command: client_sns_1.ListTopicsCommand,
paginationConfig: {
inputKey: 'NextToken',
outputKey: 'NextToken'
},
key: 'Topics',
arn: (topic) => topic.TopicArn,
resourceTypeParts: (account, region) => ({
service: 'sns',
account,
region
}),
extraFields: {
tags: async (client, topic) => {
const tagResult = await client.send(new client_sns_1.ListTagsForResourceCommand({
ResourceArn: topic.TopicArn
}));
return tagResult.Tags;
},
attributes: async (client, topic) => {
const attributes = await client.send(new client_sns_1.GetTopicAttributesCommand({
TopicArn: topic.TopicArn
}));
return attributes.Attributes;
}
},
tags: (topic) => topic.extraFields.tags,
results: (topic) => ({
metadata: {
name: topic.TopicArn.split(':').pop(),
displayName: topic.extraFields.attributes?.DisplayName,
keyId: topic.extraFields.attributes?.KmsMasterKeyId,
owner: topic.extraFields.attributes?.Owner
},
policy: topicPolicy(topic.TopicArn, topic.extraFields.attributes)
})
}));
/**
* Parse the SNS topic policy from attributes.
*
* @param attributes the attributes of the SNS topic
* @returns the parsed policy or undefined if parsing fails or the policy is not present
*/
function topicPolicy(topicArn, attributes) {
if (attributes?.['Policy']) {
try {
return JSON.parse(attributes['Policy']);
}
catch (e) {
log_js_1.log.error('Failed to parse SNS topic policy', e, { topicArn });
return undefined;
}
}
return undefined;
}
//# sourceMappingURL=topics.js.map