-
Notifications
You must be signed in to change notification settings - Fork 544
feat: Add RDS BackTracks, Events and Option Groups #8671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e7e098
Add RDS BackTracks, Events and Option Groups
hermanschaaf 1881e44
Run make gen
hermanschaaf a2d0bcd
Merge branch 'main' into rds-resources
hermanschaaf c746781
Fix linting
hermanschaaf 6bb2866
Merge branch 'rds-resources' of github.com:cloudquery/cloudquery into…
hermanschaaf 0562108
Fix test
hermanschaaf f03e630
Merge branch 'main' into rds-resources
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
plugins/source/aws/docs/tables/aws_rds_cluster_backtracks.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
plugins/source/aws/resources/services/rds/cluster_backtracks.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
23 changes: 23 additions & 0 deletions
23
plugins/source/aws/resources/services/rds/cluster_backtracks_mock_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| return nil | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
plugins/source/aws/resources/services/rds/events_mock_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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{}) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
plugins/source/aws/resources/services/rds/option_groups.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
29 changes: 29 additions & 0 deletions
29
plugins/source/aws/resources/services/rds/option_groups_mock_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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{}) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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