/
iot_thing.go
executable file
·44 lines (37 loc) · 1.04 KB
/
iot_thing.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
package lister
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iot"
"github.com/trek10inc/awsets/context"
"github.com/trek10inc/awsets/resource"
)
type AWSIoTThing struct {
}
func init() {
i := AWSIoTThing{}
listers = append(listers, i)
}
func (l AWSIoTThing) Types() []resource.ResourceType {
return []resource.ResourceType{resource.IoTThing}
}
func (l AWSIoTThing) List(ctx context.AWSetsCtx) (*resource.Group, error) {
svc := iot.NewFromConfig(ctx.AWSCfg)
rg := resource.NewGroup()
err := Paginator(func(nt *string) (*string, error) {
res, err := svc.ListThings(ctx.Context, &iot.ListThingsInput{
MaxResults: aws.Int32(100),
NextToken: nt,
})
if err != nil {
return nil, fmt.Errorf("failed to list iot thing: %w", err)
}
for _, thing := range res.Things {
r := resource.New(ctx, resource.IoTThing, thing.ThingName, thing.ThingName, thing)
r.AddRelation(resource.IoTThingType, thing.ThingTypeName, "")
rg.AddResource(r)
}
return res.NextToken, nil
})
return rg, err
}