From c277df71dcff5c8819c815c2fe342bb1c180ce45 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 10 Feb 2023 11:17:12 -0600 Subject: [PATCH 1/7] initial --- .../services/directconnect/locations.go | 30 +++++++++++++++++ .../services/directconnect/locations_fetch.go | 21 ++++++++++++ .../directconnect/locations_mock_test.go | 32 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 plugins/source/aws/resources/services/directconnect/locations.go create mode 100644 plugins/source/aws/resources/services/directconnect/locations_fetch.go create mode 100644 plugins/source/aws/resources/services/directconnect/locations_mock_test.go diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go new file mode 100644 index 00000000000000..cb495c2af17a5c --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -0,0 +1,30 @@ +package directconnect + +import ( + "github.com/aws/aws-sdk-go-v2/service/directconnect/types" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/plugin-sdk/schema" + "github.com/cloudquery/plugin-sdk/transformers" +) + +func Locations() *schema.Table { + return &schema.Table{ + Name: "aws_directconnect_locations", + Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html`, + Resolver: fetchDirectConnectLocations, + Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), + Transform: transformers.TransformWithStruct(&types.Location{}), + Columns: []schema.Column{ + { + Name: "account_id", + Type: schema.TypeString, + Resolver: client.ResolveAWSAccount, + }, + { + Name: "region", + Type: schema.TypeString, + Resolver: client.ResolveAWSRegion, + }, + }, + } +} diff --git a/plugins/source/aws/resources/services/directconnect/locations_fetch.go b/plugins/source/aws/resources/services/directconnect/locations_fetch.go new file mode 100644 index 00000000000000..7dcf2ef8cabb51 --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations_fetch.go @@ -0,0 +1,21 @@ +package directconnect + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/directconnect" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/plugin-sdk/schema" +) + +func fetchDirectConnectLocations(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error { + var config directconnect.DescribeLocationsInput + c := meta.(*client.Client) + svc := c.Services().Directconnect + output, err := svc.DescribeLocations(ctx, &config) + if err != nil { + return err + } + res <- output.Locations + return nil +} diff --git a/plugins/source/aws/resources/services/directconnect/locations_mock_test.go b/plugins/source/aws/resources/services/directconnect/locations_mock_test.go new file mode 100644 index 00000000000000..c3c0f283c33a7a --- /dev/null +++ b/plugins/source/aws/resources/services/directconnect/locations_mock_test.go @@ -0,0 +1,32 @@ +package directconnect + +import ( + "testing" + + "github.com/aws/aws-sdk-go-v2/service/directconnect" + "github.com/aws/aws-sdk-go-v2/service/directconnect/types" + "github.com/cloudquery/cloudquery/plugins/source/aws/client" + "github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks" + "github.com/cloudquery/plugin-sdk/faker" + "github.com/golang/mock/gomock" +) + +func buildDirectconnectLocations(t *testing.T, ctrl *gomock.Controller) client.Services { + m := mocks.NewMockDirectconnectClient(ctrl) + loc := types.Location{} + err := faker.FakeObject(&loc) + if err != nil { + t.Fatal(err) + } + m.EXPECT().DescribeLocations(gomock.Any(), gomock.Any(), gomock.Any()).Return( + &directconnect.DescribeLocationsOutput{ + Locations: []types.Location{loc}, + }, nil) + return client.Services{ + Directconnect: m, + } +} + +func TestDirectconnectLocation(t *testing.T) { + client.AwsMockTestHelper(t, Locations(), buildDirectconnectLocations, client.TestOptions{}) +} From 5066d18fc351589aa601c2d8ee91a9daa0fa8d57 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 10 Feb 2023 11:18:10 -0600 Subject: [PATCH 2/7] docs --- plugins/source/aws/docs/tables/README.md | 1 + .../tables/aws_directconnect_locations.md | 21 +++++++++++++++++++ plugins/source/aws/resources/plugin/tables.go | 1 + .../pages/docs/plugins/sources/aws/tables.md | 1 + 4 files changed, 24 insertions(+) create mode 100644 plugins/source/aws/docs/tables/aws_directconnect_locations.md diff --git a/plugins/source/aws/docs/tables/README.md b/plugins/source/aws/docs/tables/README.md index fd5705ae1ed284..a19ff70531b5a0 100644 --- a/plugins/source/aws/docs/tables/README.md +++ b/plugins/source/aws/docs/tables/README.md @@ -110,6 +110,7 @@ - [aws_directconnect_gateway_associations](aws_directconnect_gateway_associations.md) - [aws_directconnect_gateway_attachments](aws_directconnect_gateway_attachments.md) - [aws_directconnect_lags](aws_directconnect_lags.md) +- [aws_directconnect_locations](aws_directconnect_locations.md) - [aws_directconnect_virtual_gateways](aws_directconnect_virtual_gateways.md) - [aws_directconnect_virtual_interfaces](aws_directconnect_virtual_interfaces.md) - [aws_dms_replication_instances](aws_dms_replication_instances.md) diff --git a/plugins/source/aws/docs/tables/aws_directconnect_locations.md b/plugins/source/aws/docs/tables/aws_directconnect_locations.md new file mode 100644 index 00000000000000..845b933625b908 --- /dev/null +++ b/plugins/source/aws/docs/tables/aws_directconnect_locations.md @@ -0,0 +1,21 @@ +# Table: aws_directconnect_locations + +https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html + +The primary key for this table is **_cq_id**. + +## Columns + +| Name | Type | +| ------------- | ------------- | +|_cq_source_name|String| +|_cq_sync_time|Timestamp| +|_cq_id (PK)|UUID| +|_cq_parent_id|UUID| +|account_id|String| +|region|String| +|available_mac_sec_port_speeds|StringArray| +|available_port_speeds|StringArray| +|available_providers|StringArray| +|location_code|String| +|location_name|String| \ No newline at end of file diff --git a/plugins/source/aws/resources/plugin/tables.go b/plugins/source/aws/resources/plugin/tables.go index 0e2f33895ddb92..1a75e19c9bab60 100644 --- a/plugins/source/aws/resources/plugin/tables.go +++ b/plugins/source/aws/resources/plugin/tables.go @@ -162,6 +162,7 @@ func tables() []*schema.Table { directconnect.Connections(), directconnect.Gateways(), directconnect.Lags(), + directconnect.Locations(), directconnect.VirtualGateways(), directconnect.VirtualInterfaces(), dms.ReplicationInstances(), diff --git a/website/pages/docs/plugins/sources/aws/tables.md b/website/pages/docs/plugins/sources/aws/tables.md index 92182cb534c3b2..496a215b43245b 100644 --- a/website/pages/docs/plugins/sources/aws/tables.md +++ b/website/pages/docs/plugins/sources/aws/tables.md @@ -110,6 +110,7 @@ - [aws_directconnect_gateway_associations](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_gateway_associations.md) - [aws_directconnect_gateway_attachments](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_gateway_attachments.md) - [aws_directconnect_lags](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_lags.md) +- [aws_directconnect_locations](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_locations.md) - [aws_directconnect_virtual_gateways](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_virtual_gateways.md) - [aws_directconnect_virtual_interfaces](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_directconnect_virtual_interfaces.md) - [aws_dms_replication_instances](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/docs/tables/aws_dms_replication_instances.md) From 94d03894b590c44cbebe1086fa1577686bc62f59 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 10 Feb 2023 11:21:45 -0600 Subject: [PATCH 3/7] Update locations.go --- .../resources/services/directconnect/locations.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go index cb495c2af17a5c..b555e70fe68cf0 100644 --- a/plugins/source/aws/resources/services/directconnect/locations.go +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -15,16 +15,8 @@ func Locations() *schema.Table { Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), Transform: transformers.TransformWithStruct(&types.Location{}), Columns: []schema.Column{ - { - Name: "account_id", - Type: schema.TypeString, - Resolver: client.ResolveAWSAccount, - }, - { - Name: "region", - Type: schema.TypeString, - Resolver: client.ResolveAWSRegion, - }, + client.DefaultAccountIDColumn(false), + client.DefaultRegionColumn(false), }, } } From c231f98d8c930ed85f00cdbef4249c61988ca7f6 Mon Sep 17 00:00:00 2001 From: bbernays Date: Fri, 10 Feb 2023 16:01:53 -0600 Subject: [PATCH 4/7] docs --- plugins/source/aws/docs/tables/aws_directconnect_locations.md | 2 +- .../source/aws/resources/services/directconnect/locations.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/source/aws/docs/tables/aws_directconnect_locations.md b/plugins/source/aws/docs/tables/aws_directconnect_locations.md index 845b933625b908..f94ec97eb61a31 100644 --- a/plugins/source/aws/docs/tables/aws_directconnect_locations.md +++ b/plugins/source/aws/docs/tables/aws_directconnect_locations.md @@ -1,6 +1,6 @@ # Table: aws_directconnect_locations -https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html +https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html The primary key for this table is **_cq_id**. diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go index b555e70fe68cf0..faf9cb1b804bf3 100644 --- a/plugins/source/aws/resources/services/directconnect/locations.go +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -10,7 +10,7 @@ import ( func Locations() *schema.Table { return &schema.Table{ Name: "aws_directconnect_locations", - Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html`, + Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html`, Resolver: fetchDirectConnectLocations, Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), Transform: transformers.TransformWithStruct(&types.Location{}), From ace3fba46f363b7ecc9d9efc6361fe807ff09599 Mon Sep 17 00:00:00 2001 From: bbernays Date: Sun, 12 Feb 2023 11:44:53 -0600 Subject: [PATCH 5/7] Update plugins/source/aws/resources/services/directconnect/locations.go Co-authored-by: Erez Rokah --- .../source/aws/resources/services/directconnect/locations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go index b555e70fe68cf0..faf9cb1b804bf3 100644 --- a/plugins/source/aws/resources/services/directconnect/locations.go +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -10,7 +10,7 @@ import ( func Locations() *schema.Table { return &schema.Table{ Name: "aws_directconnect_locations", - Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html`, + Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html`, Resolver: fetchDirectConnectLocations, Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), Transform: transformers.TransformWithStruct(&types.Location{}), From af0eadc24f795e8cfe1ab422386f4bf662a8fa49 Mon Sep 17 00:00:00 2001 From: cq-bot Date: Mon, 13 Feb 2023 09:42:08 +0000 Subject: [PATCH 6/7] chore: Update code and docs --- plugins/source/aws/docs/tables/aws_directconnect_locations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/source/aws/docs/tables/aws_directconnect_locations.md b/plugins/source/aws/docs/tables/aws_directconnect_locations.md index 845b933625b908..f94ec97eb61a31 100644 --- a/plugins/source/aws/docs/tables/aws_directconnect_locations.md +++ b/plugins/source/aws/docs/tables/aws_directconnect_locations.md @@ -1,6 +1,6 @@ # Table: aws_directconnect_locations -https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Connection.html +https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html The primary key for this table is **_cq_id**. From 7169ae32ced25ace0be8260000fb269bc63be2f8 Mon Sep 17 00:00:00 2001 From: bbernays Date: Mon, 13 Feb 2023 07:52:48 -0600 Subject: [PATCH 7/7] pk --- .../aws/docs/tables/aws_directconnect_locations.md | 10 +++++----- .../aws/resources/services/directconnect/locations.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/source/aws/docs/tables/aws_directconnect_locations.md b/plugins/source/aws/docs/tables/aws_directconnect_locations.md index f94ec97eb61a31..f5bd2fd310200a 100644 --- a/plugins/source/aws/docs/tables/aws_directconnect_locations.md +++ b/plugins/source/aws/docs/tables/aws_directconnect_locations.md @@ -2,7 +2,7 @@ https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html -The primary key for this table is **_cq_id**. +The composite primary key for this table is (**account_id**, **region**, **location_code**). ## Columns @@ -10,12 +10,12 @@ The primary key for this table is **_cq_id**. | ------------- | ------------- | |_cq_source_name|String| |_cq_sync_time|Timestamp| -|_cq_id (PK)|UUID| +|_cq_id|UUID| |_cq_parent_id|UUID| -|account_id|String| -|region|String| +|account_id (PK)|String| +|region (PK)|String| |available_mac_sec_port_speeds|StringArray| |available_port_speeds|StringArray| |available_providers|StringArray| -|location_code|String| +|location_code (PK)|String| |location_name|String| \ No newline at end of file diff --git a/plugins/source/aws/resources/services/directconnect/locations.go b/plugins/source/aws/resources/services/directconnect/locations.go index faf9cb1b804bf3..31c52d74ec8223 100644 --- a/plugins/source/aws/resources/services/directconnect/locations.go +++ b/plugins/source/aws/resources/services/directconnect/locations.go @@ -13,10 +13,10 @@ func Locations() *schema.Table { Description: `https://docs.aws.amazon.com/directconnect/latest/APIReference/API_Location.html`, Resolver: fetchDirectConnectLocations, Multiplex: client.ServiceAccountRegionMultiplexer("directconnect"), - Transform: transformers.TransformWithStruct(&types.Location{}), + Transform: transformers.TransformWithStruct(&types.Location{}, transformers.WithPrimaryKeys("LocationCode")), Columns: []schema.Column{ - client.DefaultAccountIDColumn(false), - client.DefaultRegionColumn(false), + client.DefaultAccountIDColumn(true), + client.DefaultRegionColumn(true), }, } }