This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
ledgers.go
348 lines (339 loc) · 12.6 KB
/
ledgers.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package qldb
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/qldb"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource ledgers --config gen.hcl --output .
func Ledgers() *schema.Table {
return &schema.Table{
Name: "aws_qldb_ledgers",
Resolver: fetchQldbLedgers,
Multiplex: client.ServiceAccountRegionMultiplexer("qldb"),
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
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: "tags",
Description: "The tags associated with the pipeline.",
Type: schema.TypeJSON,
Resolver: ResolveQldbLedgerTags,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) for the ledger.",
Type: schema.TypeString,
},
{
Name: "creation_date_time",
Description: "The date and time, in epoch time format, when the ledger was created",
Type: schema.TypeTimestamp,
},
{
Name: "deletion_protection",
Description: "The flag that prevents a ledger from being deleted by any user",
Type: schema.TypeBool,
},
{
Name: "encryption_status",
Description: "The current state of encryption at rest for the ledger",
Type: schema.TypeString,
Resolver: schema.PathResolver("EncryptionDescription.EncryptionStatus"),
},
{
Name: "kms_key_arn",
Description: "The Amazon Resource Name (ARN) of the customer managed KMS key that the ledger uses for encryption at rest",
Type: schema.TypeString,
IgnoreInTests: true,
Resolver: schema.PathResolver("EncryptionDescription.KmsKeyArn"),
},
{
Name: "inaccessible_kms_key_date_time",
Description: "The date and time, in epoch time format, when the KMS key first became inaccessible, in the case of an error",
Type: schema.TypeTimestamp,
IgnoreInTests: true,
Resolver: schema.PathResolver("EncryptionDescription.InaccessibleKmsKeyDateTime"),
},
{
Name: "name",
Description: "The name of the ledger.",
Type: schema.TypeString,
},
{
Name: "permissions_mode",
Description: "The permissions mode of the ledger.",
Type: schema.TypeString,
},
{
Name: "state",
Description: "The current status of the ledger.",
Type: schema.TypeString,
},
},
Relations: []*schema.Table{
{
Name: "aws_qldb_ledger_journal_kinesis_streams",
Description: "Information about an Amazon QLDB journal stream, including the Amazon Resource Name (ARN), stream name, creation time, current status, and the parameters of the original stream creation request.",
Resolver: fetchQldbLedgerJournalKinesisStreams,
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "ledger_cq_id",
Description: "Unique CloudQuery ID of aws_qldb_ledgers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "stream_arn",
Description: "The Amazon Resource Name (ARN) of the Kinesis Data Streams resource. This member is required.",
Type: schema.TypeString,
Resolver: schema.PathResolver("KinesisConfiguration.StreamArn"),
},
{
Name: "aggregation_enabled",
Description: "Enables QLDB to publish multiple data records in a single Kinesis Data Streams record, increasing the number of records sent per API call",
Type: schema.TypeBool,
Resolver: schema.PathResolver("KinesisConfiguration.AggregationEnabled"),
},
{
Name: "ledger_name",
Description: "The name of the ledger. This member is required.",
Type: schema.TypeString,
},
{
Name: "role_arn",
Description: "The Amazon Resource Name (ARN) of the IAM role that grants QLDB permissions for a journal stream to write data records to a Kinesis Data Streams resource. This member is required.",
Type: schema.TypeString,
},
{
Name: "status",
Description: "The current state of the QLDB journal stream. This member is required.",
Type: schema.TypeString,
},
{
Name: "stream_id",
Description: "The UUID (represented in Base62-encoded text) of the QLDB journal stream. This member is required.",
Type: schema.TypeString,
},
{
Name: "stream_name",
Description: "The user-defined name of the QLDB journal stream. This member is required.",
Type: schema.TypeString,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the QLDB journal stream.",
Type: schema.TypeString,
},
{
Name: "creation_time",
Description: "The date and time, in epoch time format, when the QLDB journal stream was created",
Type: schema.TypeTimestamp,
},
{
Name: "error_cause",
Description: "The error message that describes the reason that a stream has a status of IMPAIRED or FAILED",
Type: schema.TypeString,
},
{
Name: "exclusive_end_time",
Description: "The exclusive date and time that specifies when the stream ends",
Type: schema.TypeTimestamp,
},
{
Name: "inclusive_start_time",
Description: "The inclusive start date and time from which to start streaming journal data.",
Type: schema.TypeTimestamp,
},
},
},
{
Name: "aws_qldb_ledger_journal_s3_exports",
Description: "Information about a journal export job, including the ledger name, export ID, creation time, current status, and the parameters of the original export creation request.",
Resolver: fetchQldbLedgerJournalS3Exports,
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "ledger_cq_id",
Description: "Unique CloudQuery ID of aws_qldb_ledgers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "exclusive_end_time",
Description: "The exclusive end date and time for the range of journal contents that was specified in the original export request. This member is required.",
Type: schema.TypeTimestamp,
},
{
Name: "export_creation_time",
Description: "The date and time, in epoch time format, when the export job was created",
Type: schema.TypeTimestamp,
},
{
Name: "export_id",
Description: "The UUID (represented in Base62-encoded text) of the journal export job. This member is required.",
Type: schema.TypeString,
},
{
Name: "inclusive_start_time",
Description: "The inclusive start date and time for the range of journal contents that was specified in the original export request. This member is required.",
Type: schema.TypeTimestamp,
},
{
Name: "ledger_name",
Description: "The name of the ledger. This member is required.",
Type: schema.TypeString,
},
{
Name: "role_arn",
Description: "The Amazon Resource Name (ARN) of the IAM role that grants QLDB permissions for a journal export job to do the following: * Write objects into your Amazon Simple Storage Service (Amazon S3) bucket. * (Optional) Use your customer managed key in Key Management Service (KMS) for server-side encryption of your exported data. This member is required.",
Type: schema.TypeString,
},
{
Name: "bucket",
Description: "The Amazon S3 bucket name in which a journal export job writes the journal contents",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3ExportConfiguration.Bucket"),
},
{
Name: "object_encryption_type",
Description: "The Amazon S3 object encryption type",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3ExportConfiguration.EncryptionConfiguration.ObjectEncryptionType"),
},
{
Name: "kms_key_arn",
Description: "The Amazon Resource Name (ARN) of a symmetric key in Key Management Service (KMS)",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3ExportConfiguration.EncryptionConfiguration.KmsKeyArn"),
},
{
Name: "prefix",
Description: "The prefix for the Amazon S3 bucket in which a journal export job writes the journal contents",
Type: schema.TypeString,
Resolver: schema.PathResolver("S3ExportConfiguration.Prefix"),
},
{
Name: "status",
Description: "The current state of the journal export job. This member is required.",
Type: schema.TypeString,
},
{
Name: "output_format",
Description: "The output format of the exported journal data.",
Type: schema.TypeString,
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchQldbLedgers(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().QLDB
config := qldb.ListLedgersInput{}
for {
response, err := svc.ListLedgers(ctx, &config, func(options *qldb.Options) {
options.Region = c.Region
})
if err != nil {
return diag.WrapError(err)
}
ledgers := make([]*qldb.DescribeLedgerOutput, 0, len(response.Ledgers))
for _, l := range response.Ledgers {
response, err := svc.DescribeLedger(ctx, &qldb.DescribeLedgerInput{Name: l.Name}, func(o *qldb.Options) {
o.Region = c.Region
})
if err != nil {
if c.IsNotFoundError(err) {
continue
}
return diag.WrapError(err)
}
ledgers = append(ledgers, response)
}
res <- ledgers
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}
func ResolveQldbLedgerTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
ledger := resource.Item.(*qldb.DescribeLedgerOutput)
cl := meta.(*client.Client)
svc := cl.Services().QLDB
response, err := svc.ListTagsForResource(ctx, &qldb.ListTagsForResourceInput{
ResourceArn: ledger.Arn,
}, func(options *qldb.Options) {
options.Region = cl.Region
})
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, response.Tags))
}
func fetchQldbLedgerJournalKinesisStreams(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
ledger := parent.Item.(*qldb.DescribeLedgerOutput)
cl := meta.(*client.Client)
config := &qldb.ListJournalKinesisStreamsForLedgerInput{
LedgerName: ledger.Name,
MaxResults: aws.Int32(100),
}
for {
response, err := cl.Services().QLDB.ListJournalKinesisStreamsForLedger(ctx, config, func(options *qldb.Options) {
options.Region = cl.Region
})
if err != nil {
return diag.WrapError(err)
}
res <- response.Streams
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}
func fetchQldbLedgerJournalS3Exports(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
ledger := parent.Item.(*qldb.DescribeLedgerOutput)
cl := meta.(*client.Client)
config := &qldb.ListJournalS3ExportsForLedgerInput{
Name: ledger.Name,
MaxResults: aws.Int32(100),
}
for {
response, err := cl.Services().QLDB.ListJournalS3ExportsForLedger(ctx, config, func(options *qldb.Options) {
options.Region = cl.Region
})
if err != nil {
return diag.WrapError(err)
}
res <- response.JournalS3Exports
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}