From f1f159229291c6a39f9832768cd3ff03a1c0180d Mon Sep 17 00:00:00 2001 From: cdavid Date: Wed, 22 Mar 2023 21:54:31 -0700 Subject: [PATCH] PSE: Fix the case when securityPrincipals list is empty (#110) --- cmd/cluster/network/endpoint/update_endpoint.go | 4 ++-- cmd/util/util.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/cluster/network/endpoint/update_endpoint.go b/cmd/cluster/network/endpoint/update_endpoint.go index 1403bcec..dd8188d2 100644 --- a/cmd/cluster/network/endpoint/update_endpoint.go +++ b/cmd/cluster/network/endpoint/update_endpoint.go @@ -17,10 +17,10 @@ package endpoint import ( "fmt" - "strings" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/yugabyte/ybm-cli/cmd/util" ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client" ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal" ) @@ -58,7 +58,7 @@ var updateEndpointCmd = &cobra.Command{ } securityPrincipalsString, _ := cmd.Flags().GetString("security-principals") - securityPrincipalsList := strings.Split(securityPrincipalsString, ",") + securityPrincipalsList := util.SplitAndIgnoreEmpty(securityPrincipalsString, ",") regionArnMap := make(map[string][]string) regionArnMap[pseGetResponse.Data.Spec.ClusterRegionInfoId] = securityPrincipalsList diff --git a/cmd/util/util.go b/cmd/util/util.go index 152dd0b9..acddb606 100644 --- a/cmd/util/util.go +++ b/cmd/util/util.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "net" + "strings" "time" "github.com/golang-jwt/jwt/v5" @@ -99,3 +100,14 @@ func Filter[T any](ss []T, test func(T) bool) (ret []T) { } return } + +func SplitAndIgnoreEmpty(str string, sep string) []string { + split := Filter(strings.Split(str, sep), func(s string) bool { + return s != "" + }) + // If the string is empty, we want to return an empty slice + if split == nil { + return []string{} + } + return split +}