mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
server updates (#566)
* server updates - improved route create/update validation/defaults - improved/added route test cases * cleanup * negative concurrency check
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
8a9678e4af
commit
1d0ba54b35
@@ -43,63 +43,34 @@ type Route struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed")
|
||||
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
|
||||
ErrRoutesValidationInvalidType = errors.New("Invalid route Type")
|
||||
ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format")
|
||||
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
|
||||
ErrRoutesValidationMissingImage = errors.New("Missing route Image")
|
||||
ErrRoutesValidationMissingName = errors.New("Missing route Name")
|
||||
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
|
||||
ErrRoutesValidationMissingType = errors.New("Missing route Type")
|
||||
ErrRoutesValidationPathMalformed = errors.New("Path malformed")
|
||||
ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout")
|
||||
ErrRoutesValidationFoundDynamicURL = errors.New("Dynamic URL is not allowed")
|
||||
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
|
||||
ErrRoutesValidationInvalidType = errors.New("Invalid route Type")
|
||||
ErrRoutesValidationInvalidFormat = errors.New("Invalid route Format")
|
||||
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
|
||||
ErrRoutesValidationMissingImage = errors.New("Missing route Image")
|
||||
ErrRoutesValidationMissingName = errors.New("Missing route Name")
|
||||
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
|
||||
ErrRoutesValidationMissingType = errors.New("Missing route Type")
|
||||
ErrRoutesValidationPathMalformed = errors.New("Path malformed")
|
||||
ErrRoutesValidationNegativeTimeout = errors.New("Negative timeout")
|
||||
ErrRoutesValidationNegativeMaxConcurrency = errors.New("Negative MaxConcurrency")
|
||||
)
|
||||
|
||||
func (r *Route) Validate() error {
|
||||
var res []error
|
||||
|
||||
// SetDefaults sets zeroed field to defaults.
|
||||
func (r *Route) SetDefaults() {
|
||||
if r.Memory == 0 {
|
||||
r.Memory = 128
|
||||
}
|
||||
|
||||
if r.AppName == "" {
|
||||
res = append(res, ErrRoutesValidationMissingAppName)
|
||||
}
|
||||
|
||||
if r.Path == "" {
|
||||
res = append(res, ErrRoutesValidationMissingPath)
|
||||
}
|
||||
|
||||
u, err := url.Parse(r.Path)
|
||||
if err != nil {
|
||||
res = append(res, ErrRoutesValidationPathMalformed)
|
||||
}
|
||||
|
||||
if strings.Contains(u.Path, ":") {
|
||||
res = append(res, ErrRoutesValidationFoundDynamicURL)
|
||||
}
|
||||
|
||||
if !path.IsAbs(u.Path) {
|
||||
res = append(res, ErrRoutesValidationInvalidPath)
|
||||
}
|
||||
|
||||
if r.Type == TypeNone {
|
||||
r.Type = TypeSync
|
||||
}
|
||||
|
||||
if r.Type != TypeAsync && r.Type != TypeSync {
|
||||
res = append(res, ErrRoutesValidationInvalidType)
|
||||
}
|
||||
|
||||
if r.Format == "" {
|
||||
r.Format = FormatDefault
|
||||
}
|
||||
|
||||
if r.Format != FormatDefault && r.Format != FormatHTTP {
|
||||
res = append(res, ErrRoutesValidationInvalidFormat)
|
||||
}
|
||||
|
||||
if r.MaxConcurrency == 0 {
|
||||
r.MaxConcurrency = 1
|
||||
}
|
||||
@@ -114,7 +85,59 @@ func (r *Route) Validate() error {
|
||||
|
||||
if r.Timeout == 0 {
|
||||
r.Timeout = defaultRouteTimeout
|
||||
} else if r.Timeout < 0 {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates field values, skipping zeroed fields if skipZero is true.
|
||||
func (r *Route) Validate(skipZero bool) error {
|
||||
var res []error
|
||||
|
||||
if !skipZero {
|
||||
if r.AppName == "" {
|
||||
res = append(res, ErrRoutesValidationMissingAppName)
|
||||
}
|
||||
|
||||
if r.Image == "" {
|
||||
res = append(res, ErrRoutesValidationMissingImage)
|
||||
}
|
||||
|
||||
if r.Path == "" {
|
||||
res = append(res, ErrRoutesValidationMissingPath)
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Path != "" {
|
||||
u, err := url.Parse(r.Path)
|
||||
if err != nil {
|
||||
res = append(res, ErrRoutesValidationPathMalformed)
|
||||
}
|
||||
|
||||
if strings.Contains(u.Path, ":") {
|
||||
res = append(res, ErrRoutesValidationFoundDynamicURL)
|
||||
}
|
||||
|
||||
if !path.IsAbs(u.Path) {
|
||||
res = append(res, ErrRoutesValidationInvalidPath)
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Type != "" {
|
||||
if r.Type != TypeAsync && r.Type != TypeSync {
|
||||
res = append(res, ErrRoutesValidationInvalidType)
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Format != "" {
|
||||
if r.Format != FormatDefault && r.Format != FormatHTTP {
|
||||
res = append(res, ErrRoutesValidationInvalidFormat)
|
||||
}
|
||||
}
|
||||
|
||||
if r.MaxConcurrency < 0 {
|
||||
res = append(res, ErrRoutesValidationNegativeMaxConcurrency)
|
||||
}
|
||||
|
||||
if r.Timeout < 0 {
|
||||
res = append(res, ErrRoutesValidationNegativeTimeout)
|
||||
}
|
||||
|
||||
@@ -182,6 +205,7 @@ func (r *Route) Update(new *Route) {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO are these sql LIKE queries? or strict matches?
|
||||
type RouteFilter struct {
|
||||
Path string
|
||||
AppName string
|
||||
|
||||
Reference in New Issue
Block a user