Skip to content

Commit

Permalink
aws-dump: Added RDS resources
Browse files Browse the repository at this point in the history
  • Loading branch information
hamstah committed Aug 5, 2019
1 parent afa9192 commit c38c61c
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 2 deletions.
1 change: 1 addition & 0 deletions aws/dump/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ github.com/aws/aws-sdk-go v1.16.36/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi
github.com/aws/aws-sdk-go v1.21.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.21.9 h1:+HXP97l4IbJvccwwNoweEknroEcX8QLwExcnc+Kxobg=
github.com/aws/aws-sdk-go v1.21.9/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.21.10 h1:lTRdgyxraKbnNhx7kWeoW/Uow1TKnSNDpQGTtEXJQgk=
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
338 changes: 338 additions & 0 deletions aws/dump/resources/rds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
package resources

import (
"github.com/aws/aws-sdk-go/service/rds"
"github.com/fatih/structs"
)

var (
RDSService = Service{
Name: "rds",
Reports: map[string]Report{
"db-clusters": RDSListDBClusters,
"db-instance-automated-backups": RDSListDBInstanceAutomatedBackups,
"db-instances": RDSListDBInstances,
"db-parameter-groups": RDSListDBParameterGroups,
"db-security-groups": RDSListDBSecurityGroups,
"db-snapshots": RDSListDBSnapshots,
"db-subnet-groups": RDSListDBSubnetGroups,
"event-subscriptions": RDSListEventSubscriptions,
"events": RDSListEvents,
"global-clusters": RDSListGlobalClusters,
"option-groups": RDSListOptionGroups,
"reserved-db-instances": RDSListReservedDBInstances,
},
}
)

func RDSListDBClusters(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBClustersPages(&rds.DescribeDBClustersInput{},
func(page *rds.DescribeDBClustersOutput, lastPage bool) bool {
for _, resource := range page.DBClusters {
r := Resource{
ID: *resource.DBClusterIdentifier,
ARN: *resource.DBClusterArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-cluster",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBInstanceAutomatedBackups(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBInstanceAutomatedBackupsPages(&rds.DescribeDBInstanceAutomatedBackupsInput{},
func(page *rds.DescribeDBInstanceAutomatedBackupsOutput, lastPage bool) bool {
for _, resource := range page.DBInstanceAutomatedBackups {
r := Resource{
ID: *resource.DBInstanceArn,
ARN: *resource.DBInstanceArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-instance-automated-backup",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBInstances(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBInstancesPages(&rds.DescribeDBInstancesInput{},
func(page *rds.DescribeDBInstancesOutput, lastPage bool) bool {
for _, resource := range page.DBInstances {
r := Resource{
ID: *resource.DBInstanceIdentifier,
ARN: *resource.DBInstanceArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-instance",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBParameterGroups(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBParameterGroupsPages(&rds.DescribeDBParameterGroupsInput{},
func(page *rds.DescribeDBParameterGroupsOutput, lastPage bool) bool {
for _, resource := range page.DBParameterGroups {
r := Resource{
ID: *resource.DBParameterGroupArn,
ARN: *resource.DBParameterGroupArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-parameter-group",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBSecurityGroups(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBSecurityGroupsPages(&rds.DescribeDBSecurityGroupsInput{},
func(page *rds.DescribeDBSecurityGroupsOutput, lastPage bool) bool {
for _, resource := range page.DBSecurityGroups {
r := Resource{
ID: *resource.DBSecurityGroupArn,
ARN: *resource.DBSecurityGroupArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-security-group",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBSnapshots(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBSnapshotsPages(&rds.DescribeDBSnapshotsInput{},
func(page *rds.DescribeDBSnapshotsOutput, lastPage bool) bool {
for _, resource := range page.DBSnapshots {
r := Resource{
ID: *resource.DBSnapshotIdentifier,
ARN: *resource.DBSnapshotArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-snapshot",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListDBSubnetGroups(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeDBSubnetGroupsPages(&rds.DescribeDBSubnetGroupsInput{},
func(page *rds.DescribeDBSubnetGroupsOutput, lastPage bool) bool {
for _, resource := range page.DBSubnetGroups {
r := Resource{
ID: *resource.DBSubnetGroupArn,
ARN: *resource.DBSubnetGroupArn,
AccountID: session.AccountID,
Service: "rds",
Type: "db-subnet-group",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListEventSubscriptions(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeEventSubscriptionsPages(&rds.DescribeEventSubscriptionsInput{},
func(page *rds.DescribeEventSubscriptionsOutput, lastPage bool) bool {
for _, resource := range page.EventSubscriptionsList {
r := Resource{
ID: *resource.EventSubscriptionArn,
ARN: *resource.EventSubscriptionArn,
AccountID: session.AccountID,
Service: "rds",
Type: "event-subscription",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListEvents(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeEventsPages(&rds.DescribeEventsInput{},
func(page *rds.DescribeEventsOutput, lastPage bool) bool {
for _, resource := range page.Events {
r := Resource{
ID: *resource.SourceArn,
ARN: *resource.SourceArn,
AccountID: session.AccountID,
Service: "rds",
Type: "event",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListGlobalClusters(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeGlobalClustersPages(&rds.DescribeGlobalClustersInput{},
func(page *rds.DescribeGlobalClustersOutput, lastPage bool) bool {
for _, resource := range page.GlobalClusters {
r := Resource{
ID: *resource.GlobalClusterIdentifier,
ARN: *resource.GlobalClusterArn,
AccountID: session.AccountID,
Service: "rds",
Type: "global-cluster",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListOptionGroups(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeOptionGroupsPages(&rds.DescribeOptionGroupsInput{},
func(page *rds.DescribeOptionGroupsOutput, lastPage bool) bool {
for _, resource := range page.OptionGroupsList {
r := Resource{
ID: *resource.OptionGroupArn,
ARN: *resource.OptionGroupArn,
AccountID: session.AccountID,
Service: "rds",
Type: "option-group",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}

func RDSListReservedDBInstances(session *Session) *ReportResult {

client := rds.New(session.Session, session.Config)

resources := []Resource{}
err := client.DescribeReservedDBInstancesPages(&rds.DescribeReservedDBInstancesInput{},
func(page *rds.DescribeReservedDBInstancesOutput, lastPage bool) bool {
for _, resource := range page.ReservedDBInstances {
r := Resource{
ID: *resource.ReservedDBInstanceArn,
ARN: *resource.ReservedDBInstanceArn,
AccountID: session.AccountID,
Service: "rds",
Type: "reserved-db-instance",
Region: *session.Config.Region,
Metadata: structs.Map(resource),
}
resources = append(resources, r)
}

return true
})

return &ReportResult{resources, err}
}
5 changes: 3 additions & 2 deletions aws/dump/resources/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ func AllServices() map[string]Service {
"lambda": LambdaService,
"route53": Route53Service,
"s3": S3Service,
}
}
"rds": RDSService,
}
}

0 comments on commit c38c61c

Please sign in to comment.