Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/source/aws/docs/tables/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions plugins/source/aws/docs/tables/aws_rds_cluster_backtracks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Table: aws_rds_cluster_backtracks

https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBClusterBacktracks.html

The composite primary key for this table is (**db_cluster_arn**, **backtrack_identifier**).

## Relations

This table depends on [aws_rds_clusters](aws_rds_clusters.md).

## Columns

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|String|
|_cq_sync_time|Timestamp|
|_cq_id|UUID|
|_cq_parent_id|UUID|
|account_id|String|
|region|String|
|db_cluster_arn (PK)|String|
|backtrack_identifier (PK)|String|
|backtrack_request_creation_time|Timestamp|
|backtrack_to|Timestamp|
|backtracked_from|Timestamp|
|db_cluster_identifier|String|
|status|String|
5 changes: 5 additions & 0 deletions plugins/source/aws/docs/tables/aws_rds_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DBCluster.html

The primary key for this table is **arn**.

## Relations

The following tables depend on aws_rds_clusters:
- [aws_rds_cluster_backtracks](aws_rds_cluster_backtracks.md)

## Columns

| Name | Type |
Expand Down
22 changes: 22 additions & 0 deletions plugins/source/aws/docs/tables/aws_rds_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Table: aws_rds_events

https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeEvents.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|
|date|Timestamp|
|event_categories|StringArray|
|message|String|
|source_arn|String|
|source_identifier|String|
|source_type|String|
28 changes: 28 additions & 0 deletions plugins/source/aws/docs/tables/aws_rds_option_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Table: aws_rds_option_groups

https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_OptionGroup.html

The primary key for this table is **arn**.

## Columns

| Name | Type |
| ------------- | ------------- |
|_cq_source_name|String|
|_cq_sync_time|Timestamp|
|_cq_id|UUID|
|_cq_parent_id|UUID|
|account_id|String|
|region|String|
|arn (PK)|String|
|allows_vpc_and_non_vpc_instance_memberships|Bool|
|copy_timestamp|Timestamp|
|engine_name|String|
|major_engine_version|String|
|option_group_arn|String|
|option_group_description|String|
|option_group_name|String|
|options|JSON|
|source_account_id|String|
|source_option_group|String|
|vpc_id|String|
2 changes: 2 additions & 0 deletions plugins/source/aws/resources/plugin/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ func tables() []*schema.Table {
rds.DbSecurityGroups(),
rds.DbSnapshots(),
rds.EngineVersions(),
rds.Events(),
rds.EventSubscriptions(),
rds.Instances(),
rds.OptionGroups(),
rds.ReservedInstances(),
rds.SubnetGroups(),
redshift.Clusters(),
Expand Down
52 changes: 52 additions & 0 deletions plugins/source/aws/resources/services/rds/cluster_backtracks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package rds

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/plugin-sdk/schema"
"github.com/cloudquery/plugin-sdk/transformers"
)

func clusterBacktracks() *schema.Table {
return &schema.Table{
Name: "aws_rds_cluster_backtracks",
Description: `https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBClusterBacktracks.html`,
Resolver: fetchRdsClusterBacktracks,
Transform: transformers.TransformWithStruct(
&types.DBClusterBacktrack{},
transformers.WithPrimaryKeys("BacktrackIdentifier"),
),
Columns: []schema.Column{
client.DefaultAccountIDColumn(false),
client.DefaultRegionColumn(false),
{
Name: "db_cluster_arn",
Type: schema.TypeString,
Resolver: schema.ParentColumnResolver("arn"),
CreationOptions: schema.ColumnCreationOptions{
PrimaryKey: true,
},
},
},
}
}

func fetchRdsClusterBacktracks(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
config := rds.DescribeDBClusterBacktracksInput{
DBClusterIdentifier: parent.Item.(types.DBCluster).DBClusterIdentifier,
}
c := meta.(*client.Client)
svc := c.Services().Rds
p := rds.NewDescribeDBClusterBacktracksPaginator(svc, &config)
for p.HasMorePages() {
resp, err := p.NextPage(ctx)
if err != nil {
return err
}
res <- resp.DBClusterBacktracks
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rds

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
"github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks"
"github.com/cloudquery/plugin-sdk/faker"
"github.com/golang/mock/gomock"
)

func buildRdsClusterBacktracks(t *testing.T, mockRds *mocks.MockRdsClient) {
var d types.DBClusterBacktrack
err := faker.FakeObject(&d)
if err != nil {
t.Fatal(err)
}

mockRds.EXPECT().DescribeDBClusterBacktracks(gomock.Any(), gomock.Any(), gomock.Any()).Return(&rds.DescribeDBClusterBacktracksOutput{
DBClusterBacktracks: []types.DBClusterBacktrack{d},
}, nil)
}
3 changes: 3 additions & 0 deletions plugins/source/aws/resources/services/rds/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ func Clusters() *schema.Table {
Resolver: resolveRdsClusterTags,
},
},
Relations: []*schema.Table{
clusterBacktracks(),
},
}
}
43 changes: 43 additions & 0 deletions plugins/source/aws/resources/services/rds/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package rds

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/plugin-sdk/schema"
"github.com/cloudquery/plugin-sdk/transformers"
)

func Events() *schema.Table {
return &schema.Table{
Name: "aws_rds_events",
Description: `https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeEvents.html`,
Resolver: fetchRdsEvents,
Transform: transformers.TransformWithStruct(&types.Event{}),
Multiplex: client.ServiceAccountRegionMultiplexer("rds"),
Columns: []schema.Column{
client.DefaultAccountIDColumn(false),
client.DefaultRegionColumn(false),
},
}
}

func fetchRdsEvents(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
c := meta.(*client.Client)
svc := c.Services().Rds
duration := int32(60 * 24 * 14) // 14 days (maximum)
config := rds.DescribeEventsInput{
Duration: &duration,
}
p := rds.NewDescribeEventsPaginator(svc, &config)
for p.HasMorePages() {
page, err := p.NextPage(ctx)
if err != nil {
return err
}
res <- page.Events
}
Comment on lines +29 to +41
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make this an incremental table?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because I wanted to keep it simple for the first iteration, and wasn't sure it was justified for the number of events you're likely to get for a single cluster (I think you're generally going to need one request anyway). We can always add it as an improvement later

return nil
}
29 changes: 29 additions & 0 deletions plugins/source/aws/resources/services/rds/events_mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package rds

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/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 buildRDSEvents(t *testing.T, ctrl *gomock.Controller) client.Services {
mock := mocks.NewMockRdsClient(ctrl)
var events []types.Event
if err := faker.FakeObject(&events); err != nil {
t.Fatal(err)
}
mock.EXPECT().DescribeEvents(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&rds.DescribeEventsOutput{Events: events},
nil,
)
return client.Services{Rds: mock}
}

func TestRDSEvents(t *testing.T) {
client.AwsMockTestHelper(t, Events(), buildRDSEvents, client.TestOptions{})
}
2 changes: 2 additions & 0 deletions plugins/source/aws/resources/services/rds/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func buildRdsDBClusters(t *testing.T, ctrl *gomock.Controller) client.Services {
t.Fatal(err)
}

buildRdsClusterBacktracks(t, m)

m.EXPECT().DescribeDBClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&rds.DescribeDBClustersOutput{
DBClusters: []rdsTypes.DBCluster{l},
Expand Down
48 changes: 48 additions & 0 deletions plugins/source/aws/resources/services/rds/option_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package rds

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/plugin-sdk/schema"
"github.com/cloudquery/plugin-sdk/transformers"
)

func OptionGroups() *schema.Table {
return &schema.Table{
Name: "aws_rds_option_groups",
Description: `https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_OptionGroup.html`,
Resolver: fetchOptionGroups,
Transform: transformers.TransformWithStruct(&types.OptionGroup{}),
Multiplex: client.ServiceAccountRegionMultiplexer("rds"),
Columns: []schema.Column{
client.DefaultAccountIDColumn(false),
client.DefaultRegionColumn(false),
{
Name: "arn",
Type: schema.TypeString,
Resolver: schema.PathResolver("OptionGroupArn"),
CreationOptions: schema.ColumnCreationOptions{
PrimaryKey: true,
},
},
},
}
}

func fetchOptionGroups(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
c := meta.(*client.Client)
svc := c.Services().Rds
config := rds.DescribeOptionGroupsInput{}
p := rds.NewDescribeOptionGroupsPaginator(svc, &config)
for p.HasMorePages() {
page, err := p.NextPage(ctx)
if err != nil {
return err
}
res <- page.OptionGroupsList
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package rds

import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/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 buildOptionGroups(t *testing.T, ctrl *gomock.Controller) client.Services {
mock := mocks.NewMockRdsClient(ctrl)
var s types.OptionGroup
if err := faker.FakeObject(&s); err != nil {
t.Fatal(err)
}
mock.EXPECT().DescribeOptionGroups(gomock.Any(), &rds.DescribeOptionGroupsInput{}, gomock.Any()).Return(
&rds.DescribeOptionGroupsOutput{OptionGroupsList: []types.OptionGroup{s}},
nil,
)
return client.Services{Rds: mock}
}

func TestRDSOptionGroups(t *testing.T) {
client.AwsMockTestHelper(t, OptionGroups(), buildOptionGroups, client.TestOptions{})
}
3 changes: 3 additions & 0 deletions website/pages/docs/plugins/sources/aws/tables.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.