-
Notifications
You must be signed in to change notification settings - Fork 500
/
iot_ca_certificates.go
172 lines (163 loc) · 5.12 KB
/
iot_ca_certificates.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func IotCaCertificates() *schema.Table {
return &schema.Table{
Name: "aws_iot_ca_certificates",
Description: "Describes a CA certificate.",
Resolver: fetchIotCaCertificates,
Multiplex: client.ServiceAccountRegionMultiplexer("iot"),
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "certificates",
Description: "Certificates of the ca certificate",
Type: schema.TypeStringArray,
Resolver: ResolveIotCaCertificateCertificates,
},
{
Name: "auto_registration_status",
Description: "Whether the CA certificate configured for auto registration of device certificates",
Type: schema.TypeString,
},
{
Name: "arn",
Description: "The CA certificate ARN.",
Type: schema.TypeString,
Resolver: schema.PathResolver("CertificateArn"),
},
{
Name: "id",
Description: "The CA certificate ID.",
Type: schema.TypeString,
Resolver: schema.PathResolver("CertificateId"),
},
{
Name: "pem",
Description: "The CA certificate data, in PEM format.",
Type: schema.TypeString,
Resolver: schema.PathResolver("CertificatePem"),
},
{
Name: "creation_date",
Description: "The date the CA certificate was created.",
Type: schema.TypeTimestamp,
},
{
Name: "customer_version",
Description: "The customer version of the CA certificate.",
Type: schema.TypeInt,
},
{
Name: "generation_id",
Description: "The generation ID of the CA certificate.",
Type: schema.TypeString,
},
{
Name: "last_modified_date",
Description: "The date the CA certificate was last modified.",
Type: schema.TypeTimestamp,
},
{
Name: "owned_by",
Description: "The owner of the CA certificate.",
Type: schema.TypeString,
},
{
Name: "status",
Description: "The status of a CA certificate.",
Type: schema.TypeString,
},
{
Name: "validity_not_after",
Description: "The certificate is not valid after this date.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Validity.NotAfter"),
},
{
Name: "validity_not_before",
Description: "The certificate is not valid before this date.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Validity.NotBefore"),
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
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 diag.WrapError(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 diag.WrapError(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 diag.WrapError(err)
}
for _, ct := range response.Certificates {
certs = append(certs, *ct.CertificateId)
}
if aws.ToString(response.NextMarker) == "" {
break
}
input.Marker = response.NextMarker
}
return diag.WrapError(resource.Set(c.Name, certs))
}