From 78a5e78bf63d57f3a40a1255202ffd95a489ce9c Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Thu, 21 Nov 2024 13:59:42 +0100 Subject: [PATCH] fix: remove ARN format check and return {} instead of null --- aws/backup_tags.go | 19 +++++++------------ aws/table_aws_backup_plan.go | 5 +---- aws/table_aws_backup_recovery_point.go | 5 +---- aws/table_aws_backup_vault.go | 5 +---- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/aws/backup_tags.go b/aws/backup_tags.go index e4899b9c9..a888e881a 100644 --- a/aws/backup_tags.go +++ b/aws/backup_tags.go @@ -3,7 +3,6 @@ package aws import ( "context" "errors" - "regexp" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/backup" @@ -11,14 +10,7 @@ import ( "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 { @@ -35,12 +27,15 @@ 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) @@ -48,7 +43,7 @@ func getAwsBackupResourceTags(ctx context.Context, d *plugin.QueryData, arn stri } if op.Tags == nil { - return nil, nil + op.Tags = map[string]string{} } return op, nil diff --git a/aws/table_aws_backup_plan.go b/aws/table_aws_backup_plan.go index 7a21c1664..73af6e153 100644 --- a/aws/table_aws_backup_plan.go +++ b/aws/table_aws_backup_plan.go @@ -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 { diff --git a/aws/table_aws_backup_recovery_point.go b/aws/table_aws_backup_recovery_point.go index 108453042..c22ff65dd 100644 --- a/aws/table_aws_backup_recovery_point.go +++ b/aws/table_aws_backup_recovery_point.go @@ -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 { diff --git a/aws/table_aws_backup_vault.go b/aws/table_aws_backup_vault.go index 5e5841e83..ab29630c1 100644 --- a/aws/table_aws_backup_vault.go +++ b/aws/table_aws_backup_vault.go @@ -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) {