/
iot_things_fetch.go
57 lines (50 loc) · 1.34 KB
/
iot_things_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
package iot
import (
"context"
"github.com/OpsHelmInc/cloudquery/client"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iot"
"github.com/aws/aws-sdk-go-v2/service/iot/types"
"github.com/cloudquery/plugin-sdk/schema"
)
func fetchIotThings(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
input := iot.ListThingsInput{
MaxResults: aws.Int32(250),
}
c := meta.(*client.Client)
svc := c.Services().Iot
for {
response, err := svc.ListThings(ctx, &input)
if err != nil {
return err
}
res <- response.Things
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return nil
}
func ResolveIotThingPrincipals(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
i := resource.Item.(types.ThingAttribute)
cl := meta.(*client.Client)
svc := cl.Services().Iot
input := iot.ListThingPrincipalsInput{
ThingName: i.ThingName,
MaxResults: aws.Int32(250),
}
var principals []string
for {
response, err := svc.ListThingPrincipals(ctx, &input)
if err != nil {
return err
}
principals = append(principals, response.Principals...)
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return resource.Set(c.Name, principals)
}