From 6f2efc0e0ddc9960309d75d0888fc6c6a826952e Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Mon, 16 Jan 2023 14:11:04 +0000 Subject: [PATCH 1/7] fix(aws): Add region to aws_backup_global_settings --- .../source/aws/docs/tables/aws_backup_global_settings.md | 3 ++- .../aws/resources/services/backup/global_settings.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/source/aws/docs/tables/aws_backup_global_settings.md b/plugins/source/aws/docs/tables/aws_backup_global_settings.md index 99a655d1702a80..7c75c740e0ea67 100644 --- a/plugins/source/aws/docs/tables/aws_backup_global_settings.md +++ b/plugins/source/aws/docs/tables/aws_backup_global_settings.md @@ -2,7 +2,7 @@ https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html -The primary key for this table is **account_id**. +The composite primary key for this table is (**account_id**, **region**). ## Columns @@ -13,6 +13,7 @@ The primary key for this table is **account_id**. |_cq_id|UUID| |_cq_parent_id|UUID| |account_id (PK)|String| +|region (PK)|String| |global_settings|JSON| |last_update_time|Timestamp| |result_metadata|JSON| \ No newline at end of file diff --git a/plugins/source/aws/resources/services/backup/global_settings.go b/plugins/source/aws/resources/services/backup/global_settings.go index d95561b6fca1b0..c51a26840e87ef 100644 --- a/plugins/source/aws/resources/services/backup/global_settings.go +++ b/plugins/source/aws/resources/services/backup/global_settings.go @@ -23,6 +23,14 @@ func GlobalSettings() *schema.Table { PrimaryKey: true, }, }, + { + Name: "region", + Type: schema.TypeString, + Resolver: client.ResolveAWSRegion, + CreationOptions: schema.ColumnCreationOptions{ + PrimaryKey: true, + }, + }, }, } } From ce9882ffacfa33725c11d2507e91dc7af8def226 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Tue, 17 Jan 2023 13:32:46 +0000 Subject: [PATCH 2/7] use accountmultiplex --- .../aws/resources/services/backup/global_settings.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/plugins/source/aws/resources/services/backup/global_settings.go b/plugins/source/aws/resources/services/backup/global_settings.go index c51a26840e87ef..b06f358fe71846 100644 --- a/plugins/source/aws/resources/services/backup/global_settings.go +++ b/plugins/source/aws/resources/services/backup/global_settings.go @@ -12,7 +12,7 @@ func GlobalSettings() *schema.Table { Name: "aws_backup_global_settings", Description: `https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html`, Resolver: fetchBackupGlobalSettings, - Multiplex: client.ServiceAccountRegionMultiplexer("backup"), + Multiplex: client.AccountMultiplex, Transform: transformers.TransformWithStruct(&backup.DescribeGlobalSettingsOutput{}), Columns: []schema.Column{ { @@ -23,14 +23,6 @@ func GlobalSettings() *schema.Table { PrimaryKey: true, }, }, - { - Name: "region", - Type: schema.TypeString, - Resolver: client.ResolveAWSRegion, - CreationOptions: schema.ColumnCreationOptions{ - PrimaryKey: true, - }, - }, }, } } From 5b62154939d405f6aaabdb2b20d170d6c03e7ef3 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Tue, 17 Jan 2023 14:29:12 +0000 Subject: [PATCH 3/7] Use a single region from the service list --- plugins/source/aws/client/multiplexers.go | 20 +++++++++++++++++++ .../services/backup/global_settings.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/source/aws/client/multiplexers.go b/plugins/source/aws/client/multiplexers.go index 5e301618882079..6d58c0e4148bbe 100644 --- a/plugins/source/aws/client/multiplexers.go +++ b/plugins/source/aws/client/multiplexers.go @@ -41,6 +41,26 @@ func AccountMultiplex(meta schema.ClientMeta) []schema.ClientMeta { return l } +func ServiceAccountSingleRegionMultiplexer(service string) func(meta schema.ClientMeta) []schema.ClientMeta { + return func(meta schema.ClientMeta) []schema.ClientMeta { + var l = make([]schema.ClientMeta, 0) + client := meta.(*Client) + for partition := range client.ServicesManager.services { + for accountID := range client.ServicesManager.services[partition] { + for region := range client.ServicesManager.services[partition][accountID] { + if !isSupportedServiceForRegion(service, region) { + meta.(*Client).Logger().Trace().Str("service", service).Str("region", region).Str("partition", partition).Msg("region is not supported for service") + continue + } + l = append(l, client.withPartitionAccountIDAndRegion(partition, accountID, region)) + break + } + } + } + return l + } +} + func ServiceAccountRegionMultiplexer(service string) func(meta schema.ClientMeta) []schema.ClientMeta { return func(meta schema.ClientMeta) []schema.ClientMeta { var l = make([]schema.ClientMeta, 0) diff --git a/plugins/source/aws/resources/services/backup/global_settings.go b/plugins/source/aws/resources/services/backup/global_settings.go index b06f358fe71846..621b83122ee39e 100644 --- a/plugins/source/aws/resources/services/backup/global_settings.go +++ b/plugins/source/aws/resources/services/backup/global_settings.go @@ -12,7 +12,7 @@ func GlobalSettings() *schema.Table { Name: "aws_backup_global_settings", Description: `https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html`, Resolver: fetchBackupGlobalSettings, - Multiplex: client.AccountMultiplex, + Multiplex: client.ServiceAccountSingleRegionMultiplexer("backup"), Transform: transformers.TransformWithStruct(&backup.DescribeGlobalSettingsOutput{}), Columns: []schema.Column{ { From 249225e34789a16a60a1b0cf4951a7ccec30a04a Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Tue, 17 Jan 2023 14:33:18 +0000 Subject: [PATCH 4/7] gen-docs --- plugins/source/aws/docs/tables/aws_backup_global_settings.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/source/aws/docs/tables/aws_backup_global_settings.md b/plugins/source/aws/docs/tables/aws_backup_global_settings.md index 7c75c740e0ea67..99a655d1702a80 100644 --- a/plugins/source/aws/docs/tables/aws_backup_global_settings.md +++ b/plugins/source/aws/docs/tables/aws_backup_global_settings.md @@ -2,7 +2,7 @@ https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html -The composite primary key for this table is (**account_id**, **region**). +The primary key for this table is **account_id**. ## Columns @@ -13,7 +13,6 @@ The composite primary key for this table is (**account_id**, **region**). |_cq_id|UUID| |_cq_parent_id|UUID| |account_id (PK)|String| -|region (PK)|String| |global_settings|JSON| |last_update_time|Timestamp| |result_metadata|JSON| \ No newline at end of file From bbc5b42db3f7f4ddb10b72c9c0da74fd0502dd3d Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 18 Jan 2023 08:55:59 +0000 Subject: [PATCH 5/7] Revert "gen-docs" This reverts commit 249225e34789a16a60a1b0cf4951a7ccec30a04a. --- plugins/source/aws/docs/tables/aws_backup_global_settings.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/source/aws/docs/tables/aws_backup_global_settings.md b/plugins/source/aws/docs/tables/aws_backup_global_settings.md index 99a655d1702a80..7c75c740e0ea67 100644 --- a/plugins/source/aws/docs/tables/aws_backup_global_settings.md +++ b/plugins/source/aws/docs/tables/aws_backup_global_settings.md @@ -2,7 +2,7 @@ https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html -The primary key for this table is **account_id**. +The composite primary key for this table is (**account_id**, **region**). ## Columns @@ -13,6 +13,7 @@ The primary key for this table is **account_id**. |_cq_id|UUID| |_cq_parent_id|UUID| |account_id (PK)|String| +|region (PK)|String| |global_settings|JSON| |last_update_time|Timestamp| |result_metadata|JSON| \ No newline at end of file From 865603485b344d1b9d253e1e9e450bb70c5354f0 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 18 Jan 2023 08:56:03 +0000 Subject: [PATCH 6/7] Revert "Use a single region from the service list" This reverts commit 5b62154939d405f6aaabdb2b20d170d6c03e7ef3. --- plugins/source/aws/client/multiplexers.go | 20 ------------------- .../services/backup/global_settings.go | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/plugins/source/aws/client/multiplexers.go b/plugins/source/aws/client/multiplexers.go index 6d58c0e4148bbe..5e301618882079 100644 --- a/plugins/source/aws/client/multiplexers.go +++ b/plugins/source/aws/client/multiplexers.go @@ -41,26 +41,6 @@ func AccountMultiplex(meta schema.ClientMeta) []schema.ClientMeta { return l } -func ServiceAccountSingleRegionMultiplexer(service string) func(meta schema.ClientMeta) []schema.ClientMeta { - return func(meta schema.ClientMeta) []schema.ClientMeta { - var l = make([]schema.ClientMeta, 0) - client := meta.(*Client) - for partition := range client.ServicesManager.services { - for accountID := range client.ServicesManager.services[partition] { - for region := range client.ServicesManager.services[partition][accountID] { - if !isSupportedServiceForRegion(service, region) { - meta.(*Client).Logger().Trace().Str("service", service).Str("region", region).Str("partition", partition).Msg("region is not supported for service") - continue - } - l = append(l, client.withPartitionAccountIDAndRegion(partition, accountID, region)) - break - } - } - } - return l - } -} - func ServiceAccountRegionMultiplexer(service string) func(meta schema.ClientMeta) []schema.ClientMeta { return func(meta schema.ClientMeta) []schema.ClientMeta { var l = make([]schema.ClientMeta, 0) diff --git a/plugins/source/aws/resources/services/backup/global_settings.go b/plugins/source/aws/resources/services/backup/global_settings.go index 621b83122ee39e..b06f358fe71846 100644 --- a/plugins/source/aws/resources/services/backup/global_settings.go +++ b/plugins/source/aws/resources/services/backup/global_settings.go @@ -12,7 +12,7 @@ func GlobalSettings() *schema.Table { Name: "aws_backup_global_settings", Description: `https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html`, Resolver: fetchBackupGlobalSettings, - Multiplex: client.ServiceAccountSingleRegionMultiplexer("backup"), + Multiplex: client.AccountMultiplex, Transform: transformers.TransformWithStruct(&backup.DescribeGlobalSettingsOutput{}), Columns: []schema.Column{ { From 0c2a90a4fb217e60c159e516e2d3b102f39b7bce Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Wed, 18 Jan 2023 08:56:05 +0000 Subject: [PATCH 7/7] Revert "use accountmultiplex" This reverts commit ce9882ffacfa33725c11d2507e91dc7af8def226. --- .../aws/resources/services/backup/global_settings.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/source/aws/resources/services/backup/global_settings.go b/plugins/source/aws/resources/services/backup/global_settings.go index b06f358fe71846..c51a26840e87ef 100644 --- a/plugins/source/aws/resources/services/backup/global_settings.go +++ b/plugins/source/aws/resources/services/backup/global_settings.go @@ -12,7 +12,7 @@ func GlobalSettings() *schema.Table { Name: "aws_backup_global_settings", Description: `https://docs.aws.amazon.com/aws-backup/latest/devguide/API_DescribeGlobalSettings.html`, Resolver: fetchBackupGlobalSettings, - Multiplex: client.AccountMultiplex, + Multiplex: client.ServiceAccountRegionMultiplexer("backup"), Transform: transformers.TransformWithStruct(&backup.DescribeGlobalSettingsOutput{}), Columns: []schema.Column{ { @@ -23,6 +23,14 @@ func GlobalSettings() *schema.Table { PrimaryKey: true, }, }, + { + Name: "region", + Type: schema.TypeString, + Resolver: client.ResolveAWSRegion, + CreationOptions: schema.ColumnCreationOptions{ + PrimaryKey: true, + }, + }, }, } }