mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package server
|
|
|
|
// TODO: it would be nice to move these into the top level folder so people can use these with the "functions" package, eg: functions.ApiHandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api"
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/fnproject/fn/fnext"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Server) apiHandlerWrapperFn(apiHandler fnext.APIHandler) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
apiHandler.ServeHTTP(c.Writer, c.Request)
|
|
}
|
|
}
|
|
|
|
func (s *Server) apiAppHandlerWrapperFn(apiHandler fnext.APIAppHandler) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
// get the app
|
|
appID := c.MustGet(api.AppID).(string)
|
|
app, err := s.datastore.GetAppByID(c.Request.Context(), appID)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
c.Abort()
|
|
return
|
|
}
|
|
if app == nil {
|
|
handleErrorResponse(c, models.ErrAppsNotFound)
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
apiHandler.ServeHTTP(c.Writer, c.Request, app)
|
|
}
|
|
}
|
|
|
|
// AddEndpoint adds an endpoint to /v1/x
|
|
func (s *Server) AddEndpoint(method, path string, handler fnext.APIHandler) {
|
|
v1 := s.Router.Group("/v1")
|
|
// v1.GET("/apps/:app/log", logHandler(cfg))
|
|
v1.Handle(method, path, s.apiHandlerWrapperFn(handler))
|
|
}
|
|
|
|
// AddEndpointFunc adds an endpoint to /v1/x
|
|
func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request)) {
|
|
s.AddEndpoint(method, path, fnext.APIHandlerFunc(handler))
|
|
}
|
|
|
|
// AddAppEndpoint adds an endpoints to /v1/apps/:app/x
|
|
func (s *Server) AddAppEndpoint(method, path string, handler fnext.APIAppHandler) {
|
|
v1 := s.Router.Group("/v1")
|
|
v1.Use(s.checkAppPresenceByName())
|
|
v1.Handle(method, "/apps/:app"+path, s.apiAppHandlerWrapperFn(handler))
|
|
}
|
|
|
|
// AddAppEndpointFunc adds an endpoints to /v1/apps/:app/x
|
|
func (s *Server) AddAppEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App)) {
|
|
s.AddAppEndpoint(method, path, fnext.APIAppHandlerFunc(handler))
|
|
}
|