forked from snyk/driftctl
/
sns_topic_enumerator.go
48 lines (40 loc) · 1.17 KB
/
sns_topic_enumerator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package aws
import (
"github.com/snyk/driftctl/enumeration/remote/aws/repository"
remoteerror "github.com/snyk/driftctl/enumeration/remote/error"
"github.com/snyk/driftctl/enumeration/resource"
"github.com/snyk/driftctl/enumeration/resource/aws"
)
type SNSTopicEnumerator struct {
repository repository.SNSRepository
factory resource.ResourceFactory
}
func NewSNSTopicEnumerator(repo repository.SNSRepository, factory resource.ResourceFactory) *SNSTopicEnumerator {
return &SNSTopicEnumerator{
repository: repo,
factory: factory,
}
}
func (e *SNSTopicEnumerator) SupportedType() resource.ResourceType {
return aws.AwsSnsTopicResourceType
}
func (e *SNSTopicEnumerator) Enumerate() ([]*resource.Resource, error) {
topics, err := e.repository.ListAllTopics()
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
results := make([]*resource.Resource, 0, len(topics))
for _, topic := range topics {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*topic.TopicArn,
map[string]interface{}{
"topic_arn": *topic.TopicArn,
},
),
)
}
return results, err
}