Skip to content

Commit

Permalink
Validating only STS ARN and updated the format
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Oct 30, 2024
1 parent 8276c47 commit 4dc5d8a
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions pkg/diagnostics/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws/arn"
nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
"github.com/noobaa/noobaa-operator/v5/pkg/bundle"
"github.com/noobaa/noobaa-operator/v5/pkg/options"
Expand Down Expand Up @@ -152,27 +153,41 @@ func printOverriddenEnvVar(appName string, envVars []corev1.EnvVar) {
fmt.Println("")
}

// isValidArn is a function to validate the ARN format for an s3 buckets
func isValidArn(arn *string) bool {
return strings.HasPrefix(*arn, "arn:aws:s3::") && len(*arn) > len("arn:aws:s3::")
// isValidSTSArn is a function to validate the STS ARN format
func isValidSTSArn(arnStr *string) bool {
if arnStr == nil {
return false
}

parsedArn, err := arn.Parse(*arnStr)
if err != nil {
return false
}

if parsedArn.Service == "sts" {
return true
}
return false
}

// printARNStatus is a function to print ARN validation status
func printARNStatus(listType string, arnList map[string]string) {
foundARNString := false
fmt.Printf("%s ARNs:\n----------------------------------\n", listType)
for name, arn := range arnList {
if isValidArn(&arn) {
fmt.Printf(" ✅ %s \"%s\":\n\t ARN: %s\n\t Status: ✅ Valid\n", listType, name, arn)
fmt.Printf("\t%s \"%s\":\n\t ARN: %s\n\t", listType, name, arn)
// currently validating only for AWS STS ARN, can be changed accordingly for other formats and validation
if isValidSTSArn(&arn) {
fmt.Printf(" Status: ✅ Valid STS ARN\n")
} else {
fmt.Printf(" ⚠️ %s \"%s\":\n\t ARN: %s\n\t Status: ⚠️ Invalid (Not an S3 bucket ARN)\n", listType, name, arn)
fmt.Printf(" Status: ⚠️ Invalid (Not an STS ARN)\n")
}
fmt.Println("")
foundARNString = true
fmt.Println("")
}

if !foundARNString {
fmt.Print(" ❌ No AWS STS ARN string found.\n")
fmt.Print(" ❌ No AWS ARN string found.\n")
}
fmt.Println("")
}

0 comments on commit 4dc5d8a

Please sign in to comment.