Add endpoint list validation regex and function

This commit is contained in:
Daniel 2022-02-17 15:39:09 +01:00
parent 0c835dd6f7
commit 2106192633

View file

@ -2,6 +2,7 @@ package endpoints
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -58,6 +59,27 @@ entriesLoop:
return endpoints, nil return endpoints, nil
} }
// ListEntryValidationRegex is a regex to bullshit check endpoint list entries.
var ListEntryValidationRegex = strings.Join([]string{
`^(\+|\-) `, // Rule verdict.
`[A-z0-9\.:\-*/]+`, // Entity matching.
`( `, // Start of optional matching.
`[A-z0-9*]+`, // Protocol matching.
`(/[A-z0-9]+(\-[A-z0-9]+)?)?`, // Port and port range matching.
`)?$`, // End of optional matching.
}, "")
// ValidateEndpointListConfigOption validates the given value.
func ValidateEndpointListConfigOption(value interface{}) error {
list, ok := value.([]string)
if !ok {
return errors.New("invalid type")
}
_, err := ParseEndpoints(list)
return err
}
// IsSet returns whether the Endpoints object is "set". // IsSet returns whether the Endpoints object is "set".
func (e Endpoints) IsSet() bool { func (e Endpoints) IsSet() bool {
return len(e) > 0 return len(e) > 0