Skip to content

Commit

Permalink
Add region to scan errors (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccampo133 authored Feb 13, 2024
1 parent dee284d commit b0b7606
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions aws/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ func scanRDSClusterRepositories(
ctx context.Context,
awsClient *awsClient,
) scanResponse {
repositories := []scan.Repository{}
var scanErrors []error
rdsClusters, err := awsClient.getRDSClusters(ctx)
if err != nil {
scanErrors = append(scanErrors, fmt.Errorf(
"error scanning RDS clusters: %w",
err,
))
scanErrors = append(
scanErrors,
fmt.Errorf(
"error scanning RDS clusters for region %s: %w",
awsClient.config.Region,
err,
),
)
}
repositories := make([]scan.Repository, 0, len(rdsClusters))
for _, cluster := range rdsClusters {
repositories = append(
repositories,
Expand All @@ -46,15 +50,19 @@ func scanRDSInstanceRepositories(
ctx context.Context,
awsClient *awsClient,
) scanResponse {
repositories := []scan.Repository{}
var scanErrors []error
rdsInstances, err := awsClient.getRDSInstances(ctx)
if err != nil {
scanErrors = append(scanErrors, fmt.Errorf(
"error scanning RDS instances: %w",
err,
))
scanErrors = append(
scanErrors,
fmt.Errorf(
"error scanning RDS instances for region %s: %w",
awsClient.config.Region,
err,
),
)
}
repositories := make([]scan.Repository, 0, len(rdsInstances))
for _, instance := range rdsInstances {
// Skip cluster instances, since they were already added when retrieving
// the RDS clusters.
Expand All @@ -75,15 +83,19 @@ func scanRedshiftRepositories(
ctx context.Context,
awsClient *awsClient,
) scanResponse {
repositories := []scan.Repository{}
var scanErrors []error
redshiftClusters, err := awsClient.getRedshiftClusters(ctx)
if err != nil {
scanErrors = append(scanErrors, fmt.Errorf(
"error scanning Redshift clusters: %w",
err,
))
scanErrors = append(
scanErrors,
fmt.Errorf(
"error scanning Redshift clusters for region %s: %w",
awsClient.config.Region,
err,
),
)
}
repositories := make([]scan.Repository, 0, len(redshiftClusters))
for _, cluster := range redshiftClusters {
repositories = append(
repositories,
Expand All @@ -100,15 +112,19 @@ func scanDynamoDBRepositories(
ctx context.Context,
awsClient *awsClient,
) scanResponse {
repositories := []scan.Repository{}
var scanErrors []error
dynamodbTables, err := awsClient.getDynamoDBTables(ctx)
if err != nil {
scanErrors = append(scanErrors, fmt.Errorf(
"error scanning DynamoDB tables: %w",
err,
))
scanErrors = append(
scanErrors,
fmt.Errorf(
"error scanning DynamoDB tables for region %s: %w",
awsClient.config.Region,
err,
),
)
}
repositories := make([]scan.Repository, 0, len(dynamodbTables))
for _, table := range dynamodbTables {
repositories = append(
repositories,
Expand All @@ -125,24 +141,25 @@ func scanS3Buckets(
ctx context.Context,
awsClient *awsClient,
) scanResponse {
repos := []scan.Repository{}
var scanErrors []error

buckets, err := awsClient.getS3Buckets(ctx)
if err != nil {
scanErrors = append(
scanErrors,
fmt.Errorf("error scanning S3 buckets: %w", err),
fmt.Errorf(
"error scanning S3 buckets for region %s: %w",
awsClient.config.Region,
err,
),
)
}

repos := make([]scan.Repository, 0, len(buckets))
for _, bucket := range buckets {
repos = append(
repos,
newRepositoryFromS3Bucket(bucket),
)
}

return scanResponse{
repositories: repos,
scanErrors: scanErrors,
Expand Down

0 comments on commit b0b7606

Please sign in to comment.