-
Notifications
You must be signed in to change notification settings - Fork 500
/
iot_ca_certificates_fetch.go
executable file
·69 lines (62 loc) · 1.73 KB
/
iot_ca_certificates_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
69
package iot
import (
"context"
"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/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/plugin-sdk/schema"
)
func fetchIotCaCertificates(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
input := iot.ListCACertificatesInput{
PageSize: aws.Int32(250),
}
c := meta.(*client.Client)
svc := c.Services().IOT
for {
response, err := svc.ListCACertificates(ctx, &input)
if err != nil {
return err
}
for _, ca := range response.Certificates {
cert, err := svc.DescribeCACertificate(ctx, &iot.DescribeCACertificateInput{
CertificateId: ca.CertificateId,
}, func(options *iot.Options) {
options.Region = c.Region
})
if err != nil {
return err
}
res <- cert.CertificateDescription
}
if aws.ToString(response.NextMarker) == "" {
break
}
input.Marker = response.NextMarker
}
return nil
}
func ResolveIotCaCertificateCertificates(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
i := resource.Item.(*types.CACertificateDescription)
cl := meta.(*client.Client)
svc := cl.Services().IOT
input := iot.ListCertificatesByCAInput{
CaCertificateId: i.CertificateId,
PageSize: aws.Int32(250),
}
var certs []string
for {
response, err := svc.ListCertificatesByCA(ctx, &input)
if err != nil {
return err
}
for _, ct := range response.Certificates {
certs = append(certs, *ct.CertificateId)
}
if aws.ToString(response.NextMarker) == "" {
break
}
input.Marker = response.NextMarker
}
return resource.Set(c.Name, certs)
}