Skip to content

Commit

Permalink
Remove port validation from edge syslog config
Browse files Browse the repository at this point in the history
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 <kobi.samoray@broadcom.com>
  • Loading branch information
ksamoray committed Apr 18, 2024
1 parent 8e5b83d commit 0615ad5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions nsxt/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0615ad5

Please sign in to comment.