Skip to content

Commit

Permalink
Output warning log if cluster ID has invalid characters
Browse files Browse the repository at this point in the history
Signed-off-by: Frances Thai <[email protected]>
  • Loading branch information
notfelineit committed May 31, 2024
1 parent 0d8ca1b commit 4c10a9d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/vt/vtadmin/cluster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
stderrors "errors"
"fmt"
"io"
"regexp"
"strconv"
"time"

Expand Down Expand Up @@ -50,6 +51,8 @@ var (
DefaultReadPoolWaitTimeout = time.Millisecond * 100
)

var ClusterIDPattern = regexp.MustCompile("^[a-zA-Z0-9+.-]*$")

// Config represents the options to configure a vtadmin cluster.
type Config struct {
ID string
Expand Down Expand Up @@ -149,6 +152,10 @@ func LoadConfig(r io.Reader, configType string) (cfg *Config, id string, err err
return nil, "", ErrNoConfigID
}

if !ClusterIDPattern.MatchString(id) {
log.Warning("cluster id must only contain alphanumeric characters, +, ., or -")
}

tmp := map[string]string{}
if err := v.Unmarshal(&tmp); err != nil {
return nil, id, err
Expand Down

0 comments on commit 4c10a9d

Please sign in to comment.