Skip to content

Commit 1002c1e

Browse files
authored
feat: add tags to AWS Glue tables (#2402)
1 parent 955abe4 commit 1002c1e

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-6
lines changed

aws/table_aws_glue_catalog_database.go

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ func tableAwsGlueCatalogDatabase(_ context.Context) *plugin.Table {
3939
Description: "The name of the database. For Hive compatibility, this is folded to lowercase when it is stored.",
4040
Type: proto.ColumnType_STRING,
4141
},
42+
{
43+
Name: "arn",
44+
Description: "The Amazon Resource Name (ARN) of the catalog database.",
45+
Type: proto.ColumnType_STRING,
46+
Hydrate: getGlueCatalogDatabaseArn,
47+
Transform: transform.FromValue(),
48+
},
4249
{
4350
Name: "catalog_id",
4451
Description: "The ID of the Data Catalog in which the database resides.",
@@ -87,12 +94,18 @@ func tableAwsGlueCatalogDatabase(_ context.Context) *plugin.Table {
8794
Type: proto.ColumnType_STRING,
8895
Transform: transform.FromField("Name"),
8996
},
97+
{
98+
Name: "tags",
99+
Description: resourceInterfaceDescription("tags"),
100+
Type: proto.ColumnType_JSON,
101+
Hydrate: getTagsForGlueCatalogDatabase,
102+
},
90103
{
91104
Name: "akas",
92105
Description: resourceInterfaceDescription("akas"),
93106
Type: proto.ColumnType_JSON,
94-
Hydrate: getGlueCatalogDatabaseAkas,
95-
Transform: transform.FromValue(),
107+
Hydrate: getGlueCatalogDatabaseArn,
108+
Transform: transform.FromValue().Transform(transform.EnsureStringArray),
96109
},
97110
}),
98111
}
@@ -192,19 +205,52 @@ func getGlueCatalogDatabase(ctx context.Context, d *plugin.QueryData, _ *plugin.
192205
return *data.Database, nil
193206
}
194207

195-
func getGlueCatalogDatabaseAkas(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
208+
func getTagsForGlueResource(ctx context.Context, d *plugin.QueryData, arn string) (interface{}, error) {
209+
// Create session
210+
svc, err := GlueClient(ctx, d)
211+
if err != nil {
212+
plugin.Logger(ctx).Error("aws_glue_catalog_database.getTagsForGlueCatalogDatabase", "connection_error", err)
213+
return nil, err
214+
}
215+
if svc == nil {
216+
// Unsupported region check
217+
return nil, nil
218+
}
219+
220+
// Build param
221+
param := &glue.GetTagsInput{
222+
ResourceArn: aws.String(arn),
223+
}
224+
225+
tags, err := svc.GetTags(ctx, param)
226+
if err != nil {
227+
plugin.Logger(ctx).Error("aws_glue_catalog_database.getTagsForGlueCatalogDatabase", "api_error", err)
228+
return nil, err
229+
}
230+
return tags, nil
231+
}
232+
233+
func getTagsForGlueCatalogDatabase(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
234+
arn, _ := getGlueCatalogDatabaseArn(ctx, d, h)
235+
return getTagsForGlueResource(ctx, d, arn.(string))
236+
}
237+
238+
func getGlueCatalogDatabaseArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
196239
region := d.EqualsQualString(matrixKeyRegion)
197240
data := h.Item.(types.Database)
198241

199242
// Get common columns
200243

201244
c, err := getCommonColumns(ctx, d, h)
202245
if err != nil {
203-
plugin.Logger(ctx).Error("aws_glue_catalog_database.getGlueCatalogDatabaseAkas", "common_data_error", err)
246+
plugin.Logger(ctx).Error("aws_glue_catalog_database.getGlueCatalogDatabaseArn", "common_data_error", err)
204247
return nil, err
205248
}
206249
commonColumnData := c.(*awsCommonColumnData)
207-
aka := "arn:" + commonColumnData.Partition + ":glue:" + region + ":" + commonColumnData.AccountId + ":database/" + *data.Name
208250

209-
return []string{aka}, nil
251+
// arn format - https://docs.aws.amazon.com/glue/latest/dg/glue-specifying-resource-arns.html
252+
// arn:aws:glue:region:account-id:database/database-name
253+
arn := "arn:" + commonColumnData.Partition + ":glue:" + region + ":" + commonColumnData.AccountId + ":database/" + *data.Name
254+
255+
return arn, nil
210256
}

aws/table_aws_glue_connection.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ func tableAwsGlueConnection(_ context.Context) *plugin.Table {
9999
Type: proto.ColumnType_STRING,
100100
Transform: transform.FromField("Name"),
101101
},
102+
{
103+
Name: "tags",
104+
Description: resourceInterfaceDescription("tags"),
105+
Type: proto.ColumnType_JSON,
106+
Hydrate: getTagsForGlueConnection,
107+
},
102108
{
103109
Name: "akas",
104110
Description: resourceInterfaceDescription("akas"),
@@ -215,6 +221,11 @@ func getGlueConnection(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydra
215221
return *data.Connection, nil
216222
}
217223

224+
func getTagsForGlueConnection(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
225+
arn, _ := getGlueConnectionArn(ctx, d, h)
226+
return getTagsForGlueResource(ctx, d, arn.(string))
227+
}
228+
218229
func getGlueConnectionArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
219230
region := d.EqualsQualString(matrixKeyRegion)
220231
data := h.Item.(types.Connection)

aws/table_aws_glue_crawler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func tableAwsGlueCrawler(_ context.Context) *plugin.Table {
157157
Type: proto.ColumnType_STRING,
158158
Transform: transform.FromField("Name"),
159159
},
160+
{
161+
Name: "tags",
162+
Description: resourceInterfaceDescription("tags"),
163+
Type: proto.ColumnType_JSON,
164+
Hydrate: getTagsForGlueCrawler,
165+
},
160166
{
161167
Name: "akas",
162168
Description: resourceInterfaceDescription("akas"),
@@ -262,6 +268,11 @@ func getGlueCrawler(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateD
262268
return *data.Crawler, nil
263269
}
264270

271+
func getTagsForGlueCrawler(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
272+
arn, _ := getGlueCrawlerArn(ctx, d, h)
273+
return getTagsForGlueResource(ctx, d, arn.(string))
274+
}
275+
265276
func getGlueCrawlerArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
266277
region := d.EqualsQualString(matrixKeyRegion)
267278
data := h.Item.(types.Crawler)

aws/table_aws_glue_dev_endpoint.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ func tableAwsGlueDevEndpoint(_ context.Context) *plugin.Table {
169169
Type: proto.ColumnType_STRING,
170170
Transform: transform.FromField("EndpointName"),
171171
},
172+
{
173+
Name: "tags",
174+
Description: resourceInterfaceDescription("tags"),
175+
Type: proto.ColumnType_JSON,
176+
Hydrate: getTagsForGlueDevEndpoint,
177+
},
172178
{
173179
Name: "akas",
174180
Description: resourceInterfaceDescription("akas"),
@@ -276,6 +282,11 @@ func getGlueDevEndpoint(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydr
276282
return *data.DevEndpoint, nil
277283
}
278284

285+
func getTagsForGlueDevEndpoint(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
286+
arn, _ := getGlueDevEndpointArn(ctx, d, h)
287+
return getTagsForGlueResource(ctx, d, arn.(string))
288+
}
289+
279290
func getGlueDevEndpointArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
280291
region := d.EqualsQualString(matrixKeyRegion)
281292
data := h.Item.(types.DevEndpoint)

aws/table_aws_glue_job.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ func tableAwsGlueJob(_ context.Context) *plugin.Table {
175175
Type: proto.ColumnType_STRING,
176176
Transform: transform.FromField("Name"),
177177
},
178+
{
179+
Name: "tags",
180+
Description: resourceInterfaceDescription("tags"),
181+
Type: proto.ColumnType_JSON,
182+
Hydrate: getTagsForGlueJob,
183+
},
178184
{
179185
Name: "akas",
180186
Description: resourceInterfaceDescription("akas"),
@@ -309,6 +315,11 @@ func getGlueJobBookmark(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr
309315
return data.JobBookmarkEntry, nil
310316
}
311317

318+
func getTagsForGlueJob(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
319+
arn, _ := getGlueJobArn(ctx, d, h)
320+
return getTagsForGlueResource(ctx, d, arn.(string))
321+
}
322+
312323
func getGlueJobArn(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
313324
region := d.EqualsQualString(matrixKeyRegion)
314325
data := h.Item.(types.Job)

0 commit comments

Comments
 (0)