Skip to content

Commit

Permalink
Fix don't allow the domain name when creating the cluster (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
MateSousa authored Jul 16, 2023
1 parent ef4a945 commit b3e1a67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (req *CreateClusterRequest) validate() error {

invalidNodes := make([]string, 0)
for _, node := range req.Nodes {
if !util.IsIPPort(node) {
if !util.IsHostPort(node) {
invalidNodes = append(invalidNodes, node)
}
}
Expand Down
10 changes: 8 additions & 2 deletions util/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"strings"
)

func IsIPPort(s string) bool {
func IsHostPort(s string) bool {
parts := strings.Split(s, ":")
if len(parts) != 2 {
return false
}
return IsIP(parts[0]) && IsPort(parts[1])

return (IsIP(parts[0]) || IsDomain(parts[0])) && IsPort(parts[1])
}

func IsIP(ip string) bool {
Expand All @@ -45,3 +46,8 @@ func IsPort(port string) bool {
}
return p > 0 && p < 65536
}

func IsDomain(domain string) bool {
_, err := net.LookupHost(domain)
return err == nil
}

0 comments on commit b3e1a67

Please sign in to comment.