The V2 Calls api endpoints have been added beneath fns: (#1203)

/fns/{fnID}/calls
/fns/{fnID}/calls/{callID}

The S3 implementation forces our hand as we if we want to list Calls
under a Fn, we have to use the FnID as a prefix on the object names,
which mean we need it to look up any Call. It also makes sense in
terms of resource hierarchy.

These endpoints can optionally be disabled (as other endpoints), if a
service provider needs to provide this functionality via other means.

The 'calls' test has been fully migrated to fn calls. This has been
done to reduce the copy pasta a bit, and on balance is ok as the
routes calls will be removed soon.
This commit is contained in:
Tom Coupland
2018-09-12 15:45:53 +01:00
committed by GitHub
parent 6684299096
commit c3537399f1
14 changed files with 615 additions and 81 deletions

View File

@@ -7,13 +7,28 @@ import (
"github.com/gin-gonic/gin"
)
func (s *Server) handleCallGet(c *gin.Context) {
func (s *Server) handleCallGet1(c *gin.Context) {
ctx := c.Request.Context()
callID := c.Param(api.ParamCallID)
appID := c.MustGet(api.AppID).(string)
callObj, err := s.logstore.GetCall(ctx, appID, callID)
callObj, err := s.logstore.GetCall1(ctx, appID, callID)
if err != nil {
handleV1ErrorResponse(c, err)
return
}
c.JSON(http.StatusOK, callResponse{"Successfully loaded call", callObj})
}
func (s *Server) handleCallGet(c *gin.Context) {
ctx := c.Request.Context()
fnID := c.Param(api.ParamFnID)
callID := c.Param(api.ParamCallID)
callObj, err := s.logstore.GetCall(ctx, fnID, callID)
if err != nil {
handleV1ErrorResponse(c, err)
return

View File

@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
)
func (s *Server) handleCallList(c *gin.Context) {
func (s *Server) handleCallList1(c *gin.Context) {
ctx := c.Request.Context()
var err error
@@ -26,7 +26,7 @@ func (s *Server) handleCallList(c *gin.Context) {
return
}
calls, err := s.logstore.GetCalls(ctx, &filter)
calls, err := s.logstore.GetCalls1(ctx, &filter)
var nextCursor string
if len(calls) > 0 && len(calls) == filter.PerPage {
@@ -41,6 +41,30 @@ func (s *Server) handleCallList(c *gin.Context) {
})
}
func (s *Server) handleCallList(c *gin.Context) {
ctx := c.Request.Context()
var err error
fnID := c.MustGet(api.ParamFnID).(string)
// TODO api.ParamRouteName needs to be escaped probably, since it has '/' a lot
filter := models.CallFilter{FnID: fnID}
filter.Cursor, filter.PerPage = pageParams(c, false) // ids are url safe
filter.FromTime, filter.ToTime, err = timeParams(c)
if err != nil {
handleV1ErrorResponse(c, err)
return
}
calls, err := s.logstore.GetCalls(ctx, &filter)
if err != nil {
handleErrorResponse(c, err)
}
c.JSON(http.StatusOK, calls)
}
// "" gets parsed to a zero time, which is fine (ignored in query)
func timeParams(c *gin.Context) (fromTime, toTime common.DateTime, err error) {
fromStr := c.Query("from_time")

View File

@@ -197,6 +197,7 @@ type Server struct {
noHTTTPTriggerEndpoint bool
noHybridAPI bool
noFnInvokeEndpoint bool
noCallEndpoints bool
appListeners *appListeners
routeListeners *routeListeners
fnListeners *fnListeners
@@ -747,6 +748,14 @@ func WithoutHybridAPI() Option {
}
}
// WithoutCallEndpoints unconditionally disables the call resources in the api
func WithoutCallEndpoints() Option {
return func(ctx context.Context, s *Server) error {
s.noCallEndpoints = true
return nil
}
}
// WithJaeger maps EnvJaegerURL
func WithJaeger(jaegerURL string) Option {
return func(ctx context.Context, s *Server) error {
@@ -1039,6 +1048,10 @@ func (s *Server) startGears(ctx context.Context, cancel context.CancelFunc) {
}
}
func (s *Server) notImplementedResponse(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
func (s *Server) bindHandlers(ctx context.Context) {
engine := s.Router
admin := s.AdminRouter
@@ -1082,9 +1095,9 @@ func (s *Server) bindHandlers(ctx context.Context) {
withAppCheck.GET("/routes/:route", s.handleRouteGetAPI)
withAppCheck.PATCH("/routes/*route", s.handleRoutesPatch)
withAppCheck.DELETE("/routes/*route", s.handleRouteDelete)
withAppCheck.GET("/calls/:call", s.handleCallGet)
withAppCheck.GET("/calls/:call", s.handleCallGet1)
withAppCheck.GET("/calls/:call/log", s.handleCallLogGet)
withAppCheck.GET("/calls", s.handleCallList)
withAppCheck.GET("/calls", s.handleCallList1)
}
apps.POST("/routes", s.handleRoutesPostPut)
@@ -1115,6 +1128,14 @@ func (s *Server) bindHandlers(ctx context.Context) {
v2.DELETE("/triggers/:triggerID", s.handleTriggerDelete)
}
if !s.noCallEndpoints {
v2.GET("/fns/:fnID/calls", s.handleCallList)
v2.GET("/fns/:fnID/calls/:callID", s.handleCallGet)
} else {
v2.GET("/fns/:fnID/calls", s.notImplementedResponse)
v2.GET("/fns/:fnID/calls/:callID", s.notImplementedResponse)
}
if !s.noHybridAPI { // Hybrid API - this should only be enabled on API servers
runner := cleanv2.Group("/runner")
runner.PUT("/async", s.handleRunnerEnqueue)