From b3e1a6746f77ba7747a19fe7b97ebf8b9fda66e7 Mon Sep 17 00:00:00 2001 From: Matheus Sousa <73663610+MateSousa@users.noreply.github.com> Date: Sun, 16 Jul 2023 07:51:24 -0300 Subject: [PATCH] Fix don't allow the domain name when creating the cluster (#97) --- server/cluster.go | 2 +- util/network.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/cluster.go b/server/cluster.go index aa4038b4..7748a1af 100644 --- a/server/cluster.go +++ b/server/cluster.go @@ -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) } } diff --git a/util/network.go b/util/network.go index 2834eca4..8cdc2304 100644 --- a/util/network.go +++ b/util/network.go @@ -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 { @@ -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 +}