-
Notifications
You must be signed in to change notification settings - Fork 500
/
iot_topic_rules_fetch.go
executable file
·68 lines (58 loc) · 1.51 KB
/
iot_topic_rules_fetch.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package iot
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iot"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/plugin-sdk/schema"
)
func fetchIotTopicRules(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
cl := meta.(*client.Client)
svc := cl.Services().IOT
input := iot.ListTopicRulesInput{
MaxResults: aws.Int32(250),
}
for {
response, err := svc.ListTopicRules(ctx, &input)
if err != nil {
return err
}
for _, s := range response.Rules {
rule, err := svc.GetTopicRule(ctx, &iot.GetTopicRuleInput{
RuleName: s.RuleName,
}, func(options *iot.Options) {
options.Region = cl.Region
})
if err != nil {
return err
}
res <- rule
}
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return nil
}
func ResolveIotTopicRuleTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
i := resource.Item.(*iot.GetTopicRuleOutput)
cl := meta.(*client.Client)
svc := cl.Services().IOT
input := iot.ListTagsForResourceInput{
ResourceArn: i.RuleArn,
}
tags := make(map[string]string)
for {
response, err := svc.ListTagsForResource(ctx, &input)
if err != nil {
return err
}
client.TagsIntoMap(response.Tags, tags)
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return resource.Set(c.Name, tags)
}