/
crawlers.go
433 lines (424 loc) · 15.6 KB
/
crawlers.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
package glue
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/glue"
"github.com/aws/aws-sdk-go-v2/service/glue/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"
)
//go:generate cq-gen --resource crawlers --config crawlers.hcl --output .
func Crawlers() *schema.Table {
return &schema.Table{
Name: "aws_glue_crawlers",
Description: "Specifies a crawler program that examines a data source and uses classifiers to try to determine its schema",
Resolver: fetchGlueCrawlers,
Multiplex: client.ServiceAccountRegionMultiplexer("glue"),
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
Columns: []schema.Column{
{
Name: "arn",
Description: "ARN of the resource.",
Type: schema.TypeString,
Resolver: resolveGlueCrawlerArn,
},
{
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",
Type: schema.TypeJSON,
Resolver: resolveGlueCrawlerTags,
},
{
Name: "classifiers",
Description: "A list of UTF-8 strings that specify the custom classifiers that are associated with the crawler",
Type: schema.TypeStringArray,
},
{
Name: "configuration",
Description: "Crawler configuration information",
Type: schema.TypeString,
},
{
Name: "crawl_elapsed_time",
Description: "If the crawler is running, contains the total time elapsed since the last crawl began",
Type: schema.TypeBigInt,
},
{
Name: "crawler_security_configuration",
Description: "The name of the SecurityConfiguration structure to be used by this crawler",
Type: schema.TypeString,
},
{
Name: "creation_time",
Description: "The time that the crawler was created",
Type: schema.TypeTimestamp,
},
{
Name: "database_name",
Description: "The name of the database in which the crawler's output is stored",
Type: schema.TypeString,
},
{
Name: "description",
Description: "A description of the crawler",
Type: schema.TypeString,
},
{
Name: "lake_formation_configuration_account_id",
Description: "Required for cross account crawls",
Type: schema.TypeString,
Resolver: schema.PathResolver("LakeFormationConfiguration.AccountId"),
},
{
Name: "lake_formation_configuration_use_lake_formation_credentials",
Description: "Specifies whether to use Lake Formation credentials for the crawler instead of the IAM role credentials",
Type: schema.TypeBool,
Resolver: schema.PathResolver("LakeFormationConfiguration.UseLakeFormationCredentials"),
},
{
Name: "last_crawl_error_message",
Description: "If an error occurred, the error information about the last crawl",
Type: schema.TypeString,
Resolver: schema.PathResolver("LastCrawl.ErrorMessage"),
},
{
Name: "last_crawl_log_group",
Description: "The log group for the last crawl",
Type: schema.TypeString,
Resolver: schema.PathResolver("LastCrawl.LogGroup"),
},
{
Name: "last_crawl_log_stream",
Description: "The log stream for the last crawl",
Type: schema.TypeString,
Resolver: schema.PathResolver("LastCrawl.LogStream"),
},
{
Name: "last_crawl_message_prefix",
Description: "The prefix for a message about this crawl",
Type: schema.TypeString,
Resolver: schema.PathResolver("LastCrawl.MessagePrefix"),
},
{
Name: "last_crawl_start_time",
Description: "The time at which the crawl started",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("LastCrawl.StartTime"),
},
{
Name: "last_crawl_status",
Description: "Status of the last crawl",
Type: schema.TypeString,
Resolver: schema.PathResolver("LastCrawl.Status"),
},
{
Name: "last_updated",
Description: "The time that the crawler was last updated",
Type: schema.TypeTimestamp,
},
{
Name: "lineage_configuration_crawler_lineage_settings",
Description: "Specifies whether data lineage is enabled for the crawler",
Type: schema.TypeString,
Resolver: schema.PathResolver("LineageConfiguration.CrawlerLineageSettings"),
},
{
Name: "name",
Description: "The name of the crawler",
Type: schema.TypeString,
},
{
Name: "recrawl_behavior",
Description: "Specifies whether to crawl the entire dataset again or to crawl only folders that were added since the last crawler run",
Type: schema.TypeString,
Resolver: schema.PathResolver("RecrawlPolicy.RecrawlBehavior"),
},
{
Name: "role",
Description: "The Amazon Resource Name (ARN) of an IAM role that's used to access customer resources, such as Amazon Simple Storage Service (Amazon S3) data",
Type: schema.TypeString,
},
{
Name: "schedule_expression",
Description: "A cron expression used to specify the schedule (see Time-Based Schedules for Jobs and Crawlers (https://docsawsamazoncom/glue/latest/dg/monitor-data-warehouse-schedulehtml) For example, to run something every day at 12:15 UTC, you would specify: cron(15 12 * * ? *)",
Type: schema.TypeString,
Resolver: schema.PathResolver("Schedule.ScheduleExpression"),
},
{
Name: "schedule_state",
Description: "The state of the schedule",
Type: schema.TypeString,
Resolver: schema.PathResolver("Schedule.State"),
},
{
Name: "schema_change_policy_delete_behavior",
Description: "The deletion behavior when the crawler finds a deleted object",
Type: schema.TypeString,
Resolver: schema.PathResolver("SchemaChangePolicy.DeleteBehavior"),
},
{
Name: "schema_change_policy_update_behavior",
Description: "The update behavior when the crawler finds a changed schema",
Type: schema.TypeString,
Resolver: schema.PathResolver("SchemaChangePolicy.UpdateBehavior"),
},
{
Name: "state",
Description: "Indicates whether the crawler is running, or whether a run is pending",
Type: schema.TypeString,
},
{
Name: "table_prefix",
Description: "The prefix added to the names of tables that are created",
Type: schema.TypeString,
},
{
Name: "version",
Description: "The version of the crawler",
Type: schema.TypeBigInt,
},
},
Relations: []*schema.Table{
{
Name: "aws_glue_crawler_targets_catalog_targets",
Description: "Specifies an Glue Data Catalog target",
Resolver: schema.PathTableResolver("Targets.CatalogTargets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "database_name",
Description: "The name of the database to be synchronized",
Type: schema.TypeString,
},
{
Name: "tables",
Description: "A list of the tables to be synchronized",
Type: schema.TypeStringArray,
},
{
Name: "connection_name",
Description: "The name of the connection for an Amazon S3-backed Data Catalog table to be a target of the crawl when using a Catalog connection type paired with a NETWORK Connection type",
Type: schema.TypeString,
},
},
},
{
Name: "aws_glue_crawler_targets_delta_targets",
Description: "Specifies a Delta data store to crawl one or more Delta tables",
Resolver: schema.PathTableResolver("Targets.DeltaTargets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "connection_name",
Description: "The name of the connection to use to connect to the Delta table target",
Type: schema.TypeString,
},
{
Name: "delta_tables",
Description: "A list of the Amazon S3 paths to the Delta tables",
Type: schema.TypeStringArray,
},
{
Name: "write_manifest",
Description: "Specifies whether to write the manifest files to the Delta table path",
Type: schema.TypeBool,
},
},
},
{
Name: "aws_glue_crawler_targets_dynamo_db_targets",
Description: "Specifies an Amazon DynamoDB table to crawl",
Resolver: schema.PathTableResolver("Targets.DynamoDBTargets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "path",
Description: "The name of the DynamoDB table to crawl",
Type: schema.TypeString,
},
{
Name: "scan_all",
Description: "Indicates whether to scan all the records, or to sample rows from the table Scanning all the records can take a long time when the table is not a high throughput table",
Type: schema.TypeBool,
},
{
Name: "scan_rate",
Description: "The percentage of the configured read capacity units to use by the Glue crawler Read capacity units is a term defined by DynamoDB, and is a numeric value that acts as rate limiter for the number of reads that can be performed on that table per second",
Type: schema.TypeFloat,
},
},
},
{
Name: "aws_glue_crawler_targets_jdbc_targets",
Description: "Specifies a JDBC data store to crawl",
Resolver: schema.PathTableResolver("Targets.JdbcTargets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "connection_name",
Description: "The name of the connection to use to connect to the JDBC target",
Type: schema.TypeString,
},
{
Name: "exclusions",
Description: "A list of glob patterns used to exclude from the crawl",
Type: schema.TypeStringArray,
},
{
Name: "path",
Description: "The path of the JDBC target",
Type: schema.TypeString,
},
},
},
{
Name: "aws_glue_crawler_targets_mongo_db_targets",
Description: "Specifies an Amazon DocumentDB or MongoDB data store to crawl",
Resolver: schema.PathTableResolver("Targets.MongoDBTargets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "connection_name",
Description: "The name of the connection to use to connect to the Amazon DocumentDB or MongoDB target",
Type: schema.TypeString,
},
{
Name: "path",
Description: "The path of the Amazon DocumentDB or MongoDB target (database/collection)",
Type: schema.TypeString,
},
{
Name: "scan_all",
Description: "Indicates whether to scan all the records, or to sample rows from the table Scanning all the records can take a long time when the table is not a high throughput table",
Type: schema.TypeBool,
},
},
},
{
Name: "aws_glue_crawler_targets_s3_targets",
Description: "Specifies a data store in Amazon Simple Storage Service (Amazon S3)",
Resolver: schema.PathTableResolver("Targets.S3Targets"),
Columns: []schema.Column{
{
Name: "crawler_cq_id",
Description: "Unique CloudQuery ID of aws_glue_crawlers table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "connection_name",
Description: "The name of a connection which allows a job or crawler to access data in Amazon S3 within an Amazon Virtual Private Cloud environment (Amazon VPC)",
Type: schema.TypeString,
},
{
Name: "dlq_event_queue_arn",
Description: "A valid Amazon dead-letter SQS ARN",
Type: schema.TypeString,
},
{
Name: "event_queue_arn",
Description: "A valid Amazon SQS ARN",
Type: schema.TypeString,
},
{
Name: "exclusions",
Description: "A list of glob patterns used to exclude from the crawl",
Type: schema.TypeStringArray,
},
{
Name: "path",
Description: "The path to the Amazon S3 target",
Type: schema.TypeString,
},
{
Name: "sample_size",
Description: "Sets the number of files in each leaf folder to be crawled when crawling sample files in a dataset",
Type: schema.TypeBigInt,
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchGlueCrawlers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().Glue
input := glue.GetCrawlersInput{}
for {
output, err := svc.GetCrawlers(ctx, &input)
if err != nil {
return diag.WrapError(err)
}
res <- output.Crawlers
if aws.ToString(output.NextToken) == "" {
break
}
input.NextToken = output.NextToken
}
return nil
}
func resolveGlueCrawlerArn(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
cl := meta.(*client.Client)
arn := aws.String(crawlerARN(cl, aws.ToString(resource.Item.(types.Crawler).Name)))
return diag.WrapError(resource.Set(c.Name, arn))
}
func resolveGlueCrawlerTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
cl := meta.(*client.Client)
svc := cl.Services().Glue
input := glue.GetTagsInput{
ResourceArn: aws.String(crawlerARN(cl, aws.ToString(resource.Item.(types.Crawler).Name))),
}
response, err := svc.GetTags(ctx, &input)
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, response.Tags))
}
// ====================================================================================================================
// User Defined Helpers
// ====================================================================================================================
func crawlerARN(cl *client.Client, name string) string {
return cl.ARN(client.GlueService, "crawler", name)
}