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 +}