Skip to content

Commit

Permalink
PSE: Fix the case when securityPrincipals list is empty (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdavid authored Mar 23, 2023
1 parent 64630b1 commit f1f1592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/cluster/network/endpoint/update_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cmd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"net"
"strings"
"time"

"github.com/golang-jwt/jwt/v5"
Expand Down Expand Up @@ -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
}

0 comments on commit f1f1592

Please sign in to comment.