Skip to content

Commit

Permalink
fix: remove ARN format check and return {} instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Nov 21, 2024
1 parent cdb8227 commit 78a5e78
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
19 changes: 7 additions & 12 deletions aws/backup_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ package aws
import (
"context"
"errors"
"regexp"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/backup"
"github.com/aws/smithy-go"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)

func getAwsBackupResourceTags(ctx context.Context, d *plugin.QueryData, arn string, pattern string) (interface{}, error) { // Create a regular expression object
re := regexp.MustCompile(pattern)

// Only return the tags associated with the resovery point
if !re.MatchString(arn) {
return nil, nil
}

func getAwsBackupResourceTags(ctx context.Context, d *plugin.QueryData, arn string) (interface{}, error) {
// Create Session
svc, err := BackupClient(ctx, d)
if err != nil {
Expand All @@ -35,20 +27,23 @@ func getAwsBackupResourceTags(ctx context.Context, d *plugin.QueryData, arn stri
}

op, err := svc.ListTags(ctx, params)
plugin.Logger(ctx).Debug("backup_tags.getAwsBackupResourceTags", "ListTagsOutput", op)
if err != nil {

var ae smithy.APIError
if errors.As(err, &ae) {
plugin.Logger(ctx).Debug("backup_tags.getAwsBackupResourceTags", "smithy.APIError", ae)
if ae.ErrorCode() == "ResourceNotFoundException" {
return &backup.ListTagsOutput{}, nil
return &backup.ListTagsOutput{
Tags: map[string]string{},
}, nil
}
}
plugin.Logger(ctx).Error("backup_tags.getAwsBackupResourceTags", "api_error", err)
return nil, err
}

if op.Tags == nil {
return nil, nil
op.Tags = map[string]string{}
}

return op, nil
Expand Down
5 changes: 1 addition & 4 deletions aws/table_aws_backup_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ func getAwsBackupPlan(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat
func getAwsBackupPlanTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
arn := backupPlanArn(h.Item)

// Define the regex pattern for the recovery point ARN
pattern := `arn:aws:backup:[a-z0-9\-]+:[0-9]{12}:backup-plan:.*`

return getAwsBackupResourceTags(ctx, d, arn, pattern)
return getAwsBackupResourceTags(ctx, d, arn)
}

func backupPlanArn(item interface{}) string {
Expand Down
5 changes: 1 addition & 4 deletions aws/table_aws_backup_recovery_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,7 @@ func getAwsBackupRecoveryPoint(ctx context.Context, d *plugin.QueryData, h *plug
func getAwsBackupRecoveryPointTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
arn := recoveryPointArn(h.Item)

// Define the regex pattern for the backup recovery point ARN
pattern := `arn:aws:backup:[a-z0-9\-]+:[0-9]{12}:recovery-point:.*`

return getAwsBackupResourceTags(ctx, d, arn, pattern)
return getAwsBackupResourceTags(ctx, d, arn)
}

func recoveryPointArn(item interface{}) string {
Expand Down
5 changes: 1 addition & 4 deletions aws/table_aws_backup_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ func getAwsBackupVaultNotification(ctx context.Context, d *plugin.QueryData, h *
func getAwsBackupVaultTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
arn := vaultArn(h.Item)

// Define the regex pattern for the backup vault ARN
pattern := `arn:aws:backup:[a-z0-9\-]+:[0-9]{12}:backup-vault:.*`

return getAwsBackupResourceTags(ctx, d, arn, pattern)
return getAwsBackupResourceTags(ctx, d, arn)
}

func getAwsBackupVaultAccessPolicy(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
Expand Down

0 comments on commit 78a5e78

Please sign in to comment.