mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge pull request #349 from fnproject/pagination
add pagination to all list endpoints
This commit is contained in:
@@ -55,6 +55,7 @@ func (a *App) UpdateConfig(patch Config) {
|
||||
}
|
||||
|
||||
type AppFilter struct {
|
||||
// An SQL LIKE query. Empty does not filter.
|
||||
Name string
|
||||
Name string // prefix query TODO implemented
|
||||
PerPage int
|
||||
Cursor string
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -130,6 +130,10 @@ type Call struct {
|
||||
}
|
||||
|
||||
type CallFilter struct {
|
||||
Path string
|
||||
AppName string
|
||||
Path string // match
|
||||
AppName string // match
|
||||
FromTime strfmt.DateTime
|
||||
ToTime strfmt.DateTime
|
||||
Cursor string
|
||||
PerPage int
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ type Datastore interface {
|
||||
// Returns ErrRoutesNotFound when no matching route is found.
|
||||
GetRoute(ctx context.Context, appName, routePath string) (*Route, error)
|
||||
|
||||
// GetRoutes gets a slice of Routes, optionally filtered by filter.
|
||||
GetRoutes(ctx context.Context, filter *RouteFilter) ([]*Route, error)
|
||||
|
||||
// GetRoutesByApp gets a slice of routes for a appName, optionally filtering on filter (filter.AppName is ignored).
|
||||
// Returns ErrDatastoreEmptyAppName if appName is empty.
|
||||
GetRoutesByApp(ctx context.Context, appName string, filter *RouteFilter) ([]*Route, error)
|
||||
|
||||
@@ -96,51 +96,59 @@ var (
|
||||
code: http.StatusConflict,
|
||||
error: errors.New("Could not update route - path is immutable"),
|
||||
}
|
||||
ErrRoutesValidationFoundDynamicURL = err{
|
||||
ErrFoundDynamicURL = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Dynamic URL is not allowed"),
|
||||
}
|
||||
ErrRoutesValidationInvalidPath = err{
|
||||
ErrInvalidPath = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Invalid Path format"),
|
||||
}
|
||||
ErrRoutesValidationInvalidType = err{
|
||||
ErrInvalidType = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Invalid route Type"),
|
||||
}
|
||||
ErrRoutesValidationInvalidFormat = err{
|
||||
ErrInvalidFormat = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Invalid route Format"),
|
||||
}
|
||||
ErrRoutesValidationMissingAppName = err{
|
||||
ErrMissingAppName = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Missing route AppName"),
|
||||
}
|
||||
ErrRoutesValidationMissingImage = err{
|
||||
ErrMissingImage = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Missing route Image"),
|
||||
}
|
||||
ErrRoutesValidationMissingName = err{
|
||||
ErrMissingName = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Missing route Name"),
|
||||
}
|
||||
ErrRoutesValidationMissingPath = err{
|
||||
ErrMissingPath = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Missing route Path"),
|
||||
}
|
||||
ErrRoutesValidationMissingType = err{
|
||||
ErrMissingType = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Missing route Type"),
|
||||
}
|
||||
ErrRoutesValidationPathMalformed = err{
|
||||
ErrPathMalformed = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Path malformed"),
|
||||
}
|
||||
ErrRoutesValidationNegativeTimeout = err{
|
||||
ErrInvalidToTime = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("to_time is not an epoch time"),
|
||||
}
|
||||
ErrInvalidFromTime = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("from_time is not an epoch time"),
|
||||
}
|
||||
ErrNegativeTimeout = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Negative timeout"),
|
||||
}
|
||||
ErrRoutesValidationNegativeIdleTimeout = err{
|
||||
ErrNegativeIdleTimeout = err{
|
||||
code: http.StatusBadRequest,
|
||||
error: errors.New("Negative idle timeout"),
|
||||
}
|
||||
|
||||
@@ -63,51 +63,51 @@ func (r *Route) SetDefaults() {
|
||||
func (r *Route) Validate(skipZero bool) error {
|
||||
if !skipZero {
|
||||
if r.AppName == "" {
|
||||
return ErrRoutesValidationMissingAppName
|
||||
return ErrMissingAppName
|
||||
}
|
||||
|
||||
if r.Path == "" {
|
||||
return ErrRoutesValidationMissingPath
|
||||
return ErrMissingPath
|
||||
}
|
||||
|
||||
if r.Image == "" {
|
||||
return ErrRoutesValidationMissingImage
|
||||
return ErrMissingImage
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Path != "" {
|
||||
u, err := url.Parse(r.Path)
|
||||
if err != nil {
|
||||
return ErrRoutesValidationPathMalformed
|
||||
return ErrPathMalformed
|
||||
}
|
||||
|
||||
if strings.Contains(u.Path, ":") {
|
||||
return ErrRoutesValidationFoundDynamicURL
|
||||
return ErrFoundDynamicURL
|
||||
}
|
||||
|
||||
if !path.IsAbs(u.Path) {
|
||||
return ErrRoutesValidationInvalidPath
|
||||
return ErrInvalidPath
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Type != "" {
|
||||
if r.Type != TypeAsync && r.Type != TypeSync {
|
||||
return ErrRoutesValidationInvalidType
|
||||
return ErrInvalidType
|
||||
}
|
||||
}
|
||||
|
||||
if !skipZero || r.Format != "" {
|
||||
if r.Format != FormatDefault && r.Format != FormatHTTP {
|
||||
return ErrRoutesValidationInvalidFormat
|
||||
return ErrInvalidFormat
|
||||
}
|
||||
}
|
||||
|
||||
if r.Timeout < 0 {
|
||||
return ErrRoutesValidationNegativeTimeout
|
||||
return ErrNegativeTimeout
|
||||
}
|
||||
|
||||
if r.IdleTimeout < 0 {
|
||||
return ErrRoutesValidationNegativeIdleTimeout
|
||||
return ErrNegativeIdleTimeout
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -168,9 +168,11 @@ func (r *Route) Update(new *Route) {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO are these sql LIKE queries? or strict matches?
|
||||
type RouteFilter struct {
|
||||
Path string
|
||||
AppName string
|
||||
Image string
|
||||
PathPrefix string // this is prefix match TODO
|
||||
AppName string // this is exact match (important for security)
|
||||
Image string // this is exact match
|
||||
|
||||
Cursor string
|
||||
PerPage int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user