Skip to content

Commit

Permalink
Add tag mapping for SNS provider (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblausten authored Dec 26, 2024
1 parent fd71b83 commit 969c924
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import { SNS, ListTopicsCommand, Topic } from '@aws-sdk/client-sns';
import {
SNS,
ListTopicsCommand,
Topic,
ListTagsForResourceCommand,
} from '@aws-sdk/client-sns';
import { STS, GetCallerIdentityCommand } from '@aws-sdk/client-sts';

import { mockClient } from 'aws-sdk-client-mock';
Expand Down Expand Up @@ -47,6 +52,9 @@ describe('AWSSNSTopicProvider', () => {
sns.on(ListTopicsCommand).resolves({
Topics: [],
});
sns.on(ListTagsForResourceCommand).resolves({
Tags: [],
});
});

it('creates no SNS topics', async () => {
Expand All @@ -73,6 +81,9 @@ describe('AWSSNSTopicProvider', () => {
} as Partial<Topic> as any,
],
});
sns.on(ListTagsForResourceCommand).resolves({
Tags: [],
});
});

it('creates SNS topic entities', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export class AWSSNSTopicProvider extends AWSEntityProvider {
for await (const topicPage of topicPages) {
for (const topic of topicPage.Topics || []) {
if (topic.TopicArn) {
const tagsResponse = await sns.listTagsForResource({
ResourceArn: topic.TopicArn,
});
const tags = tagsResponse.Tags ?? [];
const topicName = topic.TopicArn.split(':').pop() || 'unknown-topic';
const consoleLink = new ARN(topic.TopicArn).consoleLink;
const topicEntity: ResourceEntity = {
Expand All @@ -110,12 +114,12 @@ export class AWSSNSTopicProvider extends AWSEntityProvider {
},
name: topicName,
title: topicName,
labels: {}, // Add any labels if necessary
labels: this.labelsFromTags(tags),
},
spec: {
type: 'aws-sns-topic',
owner: ownerFromTags([], this.getOwnerTag(), groups),
...relationshipsFromTags([]),
owner: ownerFromTags(tags, this.getOwnerTag(), groups),
...relationshipsFromTags(tags),
},
};

Expand Down

0 comments on commit 969c924

Please sign in to comment.