mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Drop validation.IsValidSocketAddr
It's not used anywhere, and if someone was going to validate an IP:port somewhere, they should think about exactly what they want rather than just using this function. (E.g., validation should be slightly different for an IP:port to bind to vs an IP:port to connect to.)
This commit is contained in:
parent
bd6c1fcc20
commit
8fc691be94
@ -19,9 +19,7 @@ package validation
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
@ -493,18 +491,3 @@ func hasChDirPrefix(value string) []string {
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// IsValidSocketAddr checks that string represents a valid socket address
|
||||
// as defined in RFC 789. (e.g 0.0.0.0:10254 or [::]:10254))
|
||||
func IsValidSocketAddr(value string) []string {
|
||||
var errs []string
|
||||
ip, port, err := net.SplitHostPort(value)
|
||||
if err != nil {
|
||||
errs = append(errs, "must be a valid socket address format, (e.g. 0.0.0.0:10254 or [::]:10254)")
|
||||
return errs
|
||||
}
|
||||
portInt, _ := strconv.Atoi(port)
|
||||
errs = append(errs, IsValidPortNum(portInt)...)
|
||||
errs = append(errs, IsValidIP(ip)...)
|
||||
return errs
|
||||
}
|
||||
|
@ -710,31 +710,3 @@ func TestIsDomainPrefixedPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidSocketAddr(t *testing.T) {
|
||||
goodValues := []string{
|
||||
"0.0.0.0:10254",
|
||||
"127.0.0.1:8888",
|
||||
"[2001:db8:1f70::999:de8:7648:6e8]:10254",
|
||||
"[::]:10254",
|
||||
}
|
||||
for _, val := range goodValues {
|
||||
if errs := IsValidSocketAddr(val); len(errs) != 0 {
|
||||
t.Errorf("expected no errors for %q: %v", val, errs)
|
||||
}
|
||||
}
|
||||
|
||||
badValues := []string{
|
||||
"0.0.0.0.0:2020",
|
||||
"0.0.0.0",
|
||||
"6.6.6.6:909090",
|
||||
"2001:db8:1f70::999:de8:7648:6e8:87567:102545",
|
||||
"",
|
||||
"*",
|
||||
}
|
||||
for _, val := range badValues {
|
||||
if errs := IsValidSocketAddr(val); len(errs) == 0 {
|
||||
t.Errorf("expected errors for %q", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user