From 0615ad5e84f9c815ca77de92226569a9a8b2aeb8 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Thu, 18 Apr 2024 19:37:20 +0300 Subject: [PATCH] Remove port validation from edge syslog config validateSinglePort() validates a string value and therefore unsuitable for use in this case. NSX will validate the port in any case. Fixes: #1186 Signed-off-by: Kobi Samoray --- nsxt/validators.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nsxt/validators.go b/nsxt/validators.go index d0628e191..eba088928 100644 --- a/nsxt/validators.go +++ b/nsxt/validators.go @@ -15,9 +15,20 @@ import ( // Validations for Port objects -func isSinglePort(v string) bool { - i, err := strconv.ParseUint(v, 10, 32) - if err != nil { +func isSinglePort(vi interface{}) bool { + var i uint64 + switch vi := vi.(type) { + case int: + i = uint64(vi) + case string: + var err error + i, err = strconv.ParseUint(vi, 10, 32) + if err != nil { + return false + } + case uint64: + i = vi + default: return false } if i > 65536 { @@ -51,10 +62,9 @@ func validatePortRange() schema.SchemaValidateFunc { func validateSinglePort() schema.SchemaValidateFunc { return func(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - if !isSinglePort(value) { + if !isSinglePort(v) { errors = append(errors, fmt.Errorf( - "expected %q to be a single port number. Got %s", k, value)) + "expected %q to be a single port number. Got %v", k, v)) } return }