/
iot_streams.go
152 lines (146 loc) · 4.48 KB
/
iot_streams.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
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/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func IotStreams() *schema.Table {
return &schema.Table{
Name: "aws_iot_streams",
Description: "Information about a stream.",
Resolver: fetchIotStreams,
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: "created_at",
Description: "The date when the stream was created.",
Type: schema.TypeTimestamp,
},
{
Name: "description",
Description: "The description of the stream.",
Type: schema.TypeString,
},
{
Name: "last_updated_at",
Description: "The date when the stream was last updated.",
Type: schema.TypeTimestamp,
},
{
Name: "role_arn",
Description: "An IAM role IoT assumes to access your S3 files.",
Type: schema.TypeString,
},
{
Name: "arn",
Description: "The stream ARN.",
Type: schema.TypeString,
Resolver: schema.PathResolver("StreamArn"),
},
{
Name: "id",
Description: "The stream ID.",
Type: schema.TypeString,
Resolver: schema.PathResolver("StreamId"),
},
{
Name: "version",
Description: "The stream version.",
Type: schema.TypeInt,
Resolver: schema.PathResolver("StreamVersion"),
},
},
Relations: []*schema.Table{
{
Name: "aws_iot_stream_files",
Description: "Represents a file to stream.",
Resolver: schema.PathTableResolver("Files"),
Columns: []schema.Column{
{
Name: "stream_cq_id",
Description: "Unique CloudQuery ID of aws_iot_streams table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "file_id",
Description: "The file ID.",
Type: schema.TypeInt,
},
{
Name: "s3_location_bucket",
Description: "The S3 bucket.",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3Location.Bucket"),
},
{
Name: "s3_location_key",
Description: "The S3 key.",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3Location.Key"),
},
{
Name: "s3_location_version",
Description: "The S3 bucket version.",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3Location.Version"),
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchIotStreams(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var diags diag.Diagnostics
input := iot.ListStreamsInput{
MaxResults: aws.Int32(250),
}
c := meta.(*client.Client)
svc := c.Services().IOT
for {
response, err := svc.ListStreams(ctx, &input)
if err != nil {
return diags.Add(diag.FromError(diag.WrapError(err), diag.RESOLVING, diag.WithSeverity(diag.ERROR)))
}
for _, s := range response.Streams {
stream, err := svc.DescribeStream(ctx, &iot.DescribeStreamInput{
StreamId: s.StreamId,
}, func(options *iot.Options) {
options.Region = c.Region
})
if err != nil {
// A single `Describe` call error should not end resolving of table
diags = diags.Add(diag.FromError(err, diag.RESOLVING, diag.WithSeverity(diag.WARNING)))
continue
}
res <- stream.StreamInfo
}
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return diags
}