@@ -15,11 +15,13 @@ import (
1515)
1616
1717var (
18- _ rds.DescribeDBSnapshotsAPIClient = (rdsSnapshotClient )(nil )
19- _ runner = (* rdsSnapshotScan )(nil )
18+ _ rds.DescribeDBClusterSnapshotsAPIClient = (rdsSnapshotClient )(nil )
19+ _ rds.DescribeDBSnapshotsAPIClient = (rdsSnapshotClient )(nil )
20+ _ runner = (* rdsSnapshotScan )(nil )
2021)
2122
2223type rdsSnapshotClient interface {
24+ rds.DescribeDBClusterSnapshotsAPIClient
2325 rds.DescribeDBSnapshotsAPIClient
2426}
2527
@@ -46,6 +48,22 @@ func (r *rdsSnapshotScan) scan(ctx context.Context, target string) ([]Result, er
4648 return nil , fmt .Errorf ("%w: target account ID is required" , errEmptyTarget )
4749 }
4850
51+ outputSnapShoots , err := r .scanSnapshots (ctx , target )
52+ if err != nil {
53+ return nil , err
54+ }
55+
56+ outputClusterSnapShoots , err := r .scanClusterSnapshots (ctx , target )
57+ if err != nil {
58+ return nil , err
59+ }
60+
61+ outputSnapShoots = append (outputSnapShoots , outputClusterSnapShoots ... )
62+
63+ return outputSnapShoots , nil
64+ }
65+
66+ func (r * rdsSnapshotScan ) scanSnapshots (ctx context.Context , target string ) ([]Result , error ) {
4967 slog .Debug (
5068 "starting RDS snapshot scan" ,
5169 slog .String ("region" , r .region ),
@@ -102,3 +120,67 @@ func (r *rdsSnapshotScan) scan(ctx context.Context, target string) ([]Result, er
102120
103121 return output , nil
104122}
123+
124+ func (r * rdsSnapshotScan ) scanClusterSnapshots (
125+ ctx context.Context ,
126+ target string ,
127+ ) ([]Result , error ) {
128+ slog .Debug (
129+ "starting RDS cluster snapshot scan" ,
130+ slog .String ("region" , r .region ),
131+ slog .String ("target" , target ),
132+ )
133+
134+ var output []Result
135+
136+ paginator := rds .NewDescribeDBClusterSnapshotsPaginator (
137+ r .client ,
138+ & rds.DescribeDBClusterSnapshotsInput {
139+ DBClusterIdentifier : nil ,
140+ DBClusterSnapshotIdentifier : nil ,
141+ DbClusterResourceId : nil ,
142+ Filters : nil ,
143+ IncludePublic : aws .Bool (true ),
144+ IncludeShared : aws .Bool (true ),
145+ Marker : nil ,
146+ MaxRecords : nil ,
147+ SnapshotType : nil ,
148+ },
149+ )
150+ for paginator .HasMorePages () {
151+ if ctx .Err () != nil {
152+ return nil , fmt .Errorf ("%w: %w" , errCtxCancelled , ctx .Err ())
153+ }
154+
155+ page , err := paginator .NextPage (ctx )
156+ if err != nil {
157+ return nil , fmt .Errorf ("failed to fetch RDS cluster snapshots, %w" , err )
158+ }
159+
160+ for _ , snapshot := range page .DBClusterSnapshots {
161+ if ! strings .Contains (* snapshot .DBClusterSnapshotIdentifier , target ) {
162+ slog .Debug ("skipping RDS cluster snapshots" ,
163+ slog .String ("name" , * snapshot .DBClusterSnapshotIdentifier ),
164+ slog .String ("region" , r .region ),
165+ )
166+
167+ continue
168+ }
169+
170+ output = append (output , Result {
171+ CreationDate : snapshot .SnapshotCreateTime .Format (time .RFC3339 ),
172+ Identifier : * snapshot .DBClusterSnapshotIdentifier ,
173+ Region : r .region ,
174+ RType : r .runType (),
175+ })
176+ }
177+ }
178+
179+ slog .Debug ("finished RDS cluster snapshot scan" ,
180+ slog .Int ("count" , len (output )),
181+ slog .String ("region" , r .region ),
182+ slog .String ("target" , target ),
183+ )
184+
185+ return output , nil
186+ }
0 commit comments