mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Remove V1 endpoints and Routes (#1210)
Largely a removal job, however many tests, particularly system level ones relied on Routes. These have been migrated to use Fns. * Add 410 response to swagger * No app names in log tags * Adding constraint in GetCall for FnID * Adding test to check FnID is required on call * Add fn_id to call selector * Fix text in docker mem warning * Correct buildConfig func name * Test fix up * Removing CPU setting from Agent test CPU setting has been deprecated, but the code base is still riddled with it. This just removes it from this layer. Really we need to remove it from Call. * Remove fn id check on calls * Reintroduce fn id required on call * Adding fnID to calls for execute test * Correct setting of app id in middleware * Removes root middlewares ability to redirect fun invocations * Add over sized test check * Removing call fn id check
This commit is contained in:
committed by
Owen Cliffe
parent
6a01dae923
commit
d56a49b321
15
fnext/api.go
15
fnext/api.go
@@ -34,18 +34,3 @@ type APIAppHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.
|
||||
func (f APIAppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
f(w, r, app)
|
||||
}
|
||||
|
||||
// APIRouteHandler may be used to add an http endpoint on the versioned route of fn API,
|
||||
// at /:version/apps/:app/routes/:route
|
||||
type APIRouteHandler interface {
|
||||
// Handle(ctx context.Context)
|
||||
ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route)
|
||||
}
|
||||
|
||||
// APIRouteHandlerFunc is a convenience for getting an APIRouteHandler.
|
||||
type APIRouteHandlerFunc func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route)
|
||||
|
||||
// ServeHTTP calls f(w, r).
|
||||
func (f APIRouteHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
f(w, r, app, route)
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ import (
|
||||
|
||||
// NewDatastore returns a Datastore that wraps the provided Datastore, calling any relevant
|
||||
// listeners around any of the Datastore methods.
|
||||
func NewDatastore(ds models.Datastore, al AppListener, rl RouteListener, fl FnListener, tl TriggerListener) models.Datastore {
|
||||
func NewDatastore(ds models.Datastore, al AppListener, fl FnListener, tl TriggerListener) models.Datastore {
|
||||
return &extds{
|
||||
Datastore: ds,
|
||||
al: al,
|
||||
rl: rl,
|
||||
fl: fl,
|
||||
tl: tl,
|
||||
}
|
||||
@@ -21,7 +20,6 @@ func NewDatastore(ds models.Datastore, al AppListener, rl RouteListener, fl FnLi
|
||||
type extds struct {
|
||||
models.Datastore
|
||||
al AppListener
|
||||
rl RouteListener
|
||||
fl FnListener
|
||||
tl TriggerListener
|
||||
}
|
||||
@@ -147,48 +145,6 @@ func (e *extds) GetApps(ctx context.Context, filter *models.AppFilter) (*models.
|
||||
return apps, err
|
||||
}
|
||||
|
||||
func (e *extds) InsertRoute(ctx context.Context, route *models.Route) (*models.Route, error) {
|
||||
err := e.rl.BeforeRouteCreate(ctx, route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
route, err = e.Datastore.InsertRoute(ctx, route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = e.rl.AfterRouteCreate(ctx, route)
|
||||
return route, err
|
||||
}
|
||||
|
||||
func (e *extds) UpdateRoute(ctx context.Context, route *models.Route) (*models.Route, error) {
|
||||
err := e.rl.BeforeRouteUpdate(ctx, route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
route, err = e.Datastore.UpdateRoute(ctx, route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = e.rl.AfterRouteUpdate(ctx, route)
|
||||
return route, err
|
||||
}
|
||||
|
||||
func (e *extds) RemoveRoute(ctx context.Context, appId string, routePath string) error {
|
||||
err := e.rl.BeforeRouteDelete(ctx, appId, routePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = e.Datastore.RemoveRoute(ctx, appId, routePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return e.rl.AfterRouteDelete(ctx, appId, routePath)
|
||||
}
|
||||
|
||||
func (e *extds) InsertFn(ctx context.Context, fn *models.Fn) (*models.Fn, error) {
|
||||
err := e.fl.BeforeFnCreate(ctx, fn)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,22 +41,6 @@ type AppListener interface {
|
||||
// }
|
||||
}
|
||||
|
||||
// RouteListener is an interface used to inject custom code at key points in the route lifecycle.
|
||||
type RouteListener interface {
|
||||
// BeforeRouteCreate called before route created in the datastore
|
||||
BeforeRouteCreate(ctx context.Context, route *models.Route) error
|
||||
// AfterRouteCreate called after route create in the datastore
|
||||
AfterRouteCreate(ctx context.Context, route *models.Route) error
|
||||
// BeforeRouteUpdate called before route update in datastore
|
||||
BeforeRouteUpdate(ctx context.Context, route *models.Route) error
|
||||
// AfterRouteUpdate called after route updated in datastore
|
||||
AfterRouteUpdate(ctx context.Context, route *models.Route) error
|
||||
// BeforeRouteDelete called before route deleted from the datastore
|
||||
BeforeRouteDelete(ctx context.Context, appId string, routePath string) error
|
||||
// AfterRouteDelete called after route deleted from the datastore
|
||||
AfterRouteDelete(ctx context.Context, appId string, routePath string) error
|
||||
}
|
||||
|
||||
// FnListener enables callbacks around Fn events
|
||||
type FnListener interface {
|
||||
// BeforeFnCreate called before fn created in the datastore
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
package fnext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// MiddlewareController allows a bit more flow control to the middleware, since we multiple paths a request can go down.
|
||||
// 1) Could be routed towards the API
|
||||
// 2) Could be routed towards a function
|
||||
type MiddlewareController interface {
|
||||
|
||||
// CallFunction skips any API routing and goes down the function path
|
||||
CallFunction(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
// If function has already been called
|
||||
FunctionCalled() bool
|
||||
}
|
||||
|
||||
// GetMiddlewareController returns MiddlewareController from context.
|
||||
func GetMiddlewareController(ctx context.Context) MiddlewareController {
|
||||
// return ctx.(MiddlewareContext)
|
||||
v := ctx.Value(MiddlewareControllerKey)
|
||||
return v.(MiddlewareController)
|
||||
}
|
||||
|
||||
// Middleware just takes a http.Handler and returns one. So the next middle ware must be called
|
||||
// within the returned handler or it would be ignored.
|
||||
type Middleware interface {
|
||||
|
||||
@@ -38,10 +38,6 @@ type ExtServer interface {
|
||||
AddAppEndpoint(method, path string, handler APIAppHandler)
|
||||
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
|
||||
AddAppEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App))
|
||||
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
|
||||
AddRouteEndpoint(method, path string, handler APIRouteHandler)
|
||||
// AddRouteEndpoint adds an endpoints to /v1/apps/:app/routes/:route/x
|
||||
AddRouteEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route))
|
||||
|
||||
// Datastore returns the Datastore Fn is using
|
||||
Datastore() models.Datastore
|
||||
|
||||
Reference in New Issue
Block a user