diff --git a/pkg/diagnostics/report.go b/pkg/diagnostics/report.go index fb503cf2b..4feb3fad0 100644 --- a/pkg/diagnostics/report.go +++ b/pkg/diagnostics/report.go @@ -45,7 +45,7 @@ func RunReport(cmd *cobra.Command, args []string) { TypeMeta: metav1.TypeMeta{Kind: "BackingStoreList"}, } if !util.KubeList(bsList, &client.ListOptions{Namespace: options.Namespace}) { - log.Fatalf(`❌ Could not get backingstores in Namespace %q`, options.Namespace) + log.Fatalf(`❌ No backingstores were found in the %q namespace`, options.Namespace) } // Fetching all Namespacestores @@ -53,7 +53,7 @@ func RunReport(cmd *cobra.Command, args []string) { TypeMeta: metav1.TypeMeta{Kind: "NamespaceStoreList"}, } if !util.KubeList(nsList, &client.ListOptions{Namespace: options.Namespace}) { - log.Fatalf(`❌ Could not get namespacestores in Namespace %q`, options.Namespace) + log.Fatalf(`❌ No namespacestores were found in the %q namespace`, options.Namespace) } fmt.Println("") @@ -63,7 +63,7 @@ func RunReport(cmd *cobra.Command, args []string) { // retrieving the overridden env variables using `CONFIG_JS_` prefix overriddenEnvVar(coreApp, endpointApp) - // validating ARNs for backingstore and namespacestore + // validating ARNs for backingstores and namespacestores arnValidationCheck(bsList, nsList) // TODO: Add support for additional features @@ -99,53 +99,25 @@ func overriddenEnvVar(coreApp *appsv1.StatefulSet, endpointApp *appsv1.Deploymen func arnValidationCheck(bsList *nbv1.BackingStoreList, nsList *nbv1.NamespaceStoreList) { log := util.Logger() - log.Print("⏳ Performing validation check for ARNs...\n") - foundARNString := false + log.Print("⏳ Validating store ARNs...\n") // Validate ARNs for backingstores - fmt.Print("ARN Validation Check (BACKINGSTORES):\n----------------------------------\n") + bsArnList := make(map[string]string) for _, bs := range bsList.Items { - if bs.Spec.AWSS3 != nil { - if bs.Spec.AWSS3.AWSSTSRoleARN != nil { - arn := *bs.Spec.AWSS3.AWSSTSRoleARN - if isValidArn(&arn) { - fmt.Printf(" ✅ Backingstore \"%s\":\n\t ARN: %s\n\t Status: ✅ Valid\n", bs.Name, arn) - } else { - fmt.Printf(" ⚠️ Backingstore \"%s\":\n\t ARN: %s\n\t Status: ⚠️ Invalid (Not an S3 bucket ARN)\n", bs.Name, arn) - } - fmt.Println("") - foundARNString = true - } + if bs.Spec.AWSS3 != nil && bs.Spec.AWSS3.AWSSTSRoleARN != nil { + bsArnList[bs.Name] = *bs.Spec.AWSS3.AWSSTSRoleARN } } + printARNStatus("BACKINGSTORE", bsArnList) - if !foundARNString { - fmt.Print(" ❌ No aws sts arn string found.\n") - } - fmt.Println("") - - foundARNString = false // Validate ARNs for namespacestores - fmt.Print("ARN Validation Check (NAMESPACESTORES):\n----------------------------------\n") + nsArnList := make(map[string]string) for _, ns := range nsList.Items { - if ns.Spec.AWSS3 != nil { - if ns.Spec.AWSS3.AWSSTSRoleARN != nil { - arn := *ns.Spec.AWSS3.AWSSTSRoleARN - if isValidArn(&arn) { - fmt.Printf(" ✅ Namespacestore \"%s\":\n\t ARN: %s\n\t Status: ✅ Valid\n", ns.Name, arn) - } else { - fmt.Printf(" ⚠️ Namespacestore \"%s\":\n\t ARN: %s\n\t Status: ⚠️ Invalid (Not an S3 bucket ARN)\n", ns.Name, arn) - } - fmt.Println("") - foundARNString = true - } + if ns.Spec.AWSS3 != nil && ns.Spec.AWSS3.AWSSTSRoleARN != nil { + nsArnList[ns.Name] = *ns.Spec.AWSS3.AWSSTSRoleARN } } - - if !foundARNString { - fmt.Print(" ❌ No aws sts arn string found.\n") - } - fmt.Println("") + printARNStatus("NAMESPACESTORE", nsArnList) fmt.Println("") } @@ -182,5 +154,25 @@ func printOverriddenEnvVar(appName string, envVars []corev1.EnvVar) { // 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:::") + return strings.HasPrefix(*arn, "arn:aws:s3::") && len(*arn) > len("arn:aws:s3::") +} + +// 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) + } else { + fmt.Printf(" ⚠️ %s \"%s\":\n\t ARN: %s\n\t Status: ⚠️ Invalid (Not an S3 bucket ARN)\n", listType, name, arn) + } + fmt.Println("") + foundARNString = true + } + + if !foundARNString { + fmt.Print(" ❌ No AWS STS ARN string found.\n") + } + fmt.Println("") }