Files
fn-serverless/api/server/call_list.go
Tom Coupland d56a49b321 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
2018-09-17 16:44:51 +01:00

76 lines
1.5 KiB
Go

package server
import (
"net/http"
"strconv"
"time"
"github.com/fnproject/fn/api"
"github.com/fnproject/fn/api/common"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
)
func (s *Server) handleCallList(c *gin.Context) {
ctx := c.Request.Context()
var err error
fnID := c.Param(api.ParamFnID)
if fnID == "" {
handleErrorResponse(c, models.ErrFnsMissingID)
return
}
_, err = s.datastore.GetFnByID(ctx, c.Param(api.ParamFnID))
if err != nil {
handleErrorResponse(c, err)
return
}
filter := models.CallFilter{FnID: fnID}
filter.Cursor, filter.PerPage = pageParams(c)
filter.FromTime, filter.ToTime, err = timeParams(c)
if err != nil {
handleErrorResponse(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")
toStr := c.Query("to_time")
var ok bool
if fromStr != "" {
fromTime, ok = strToTime(fromStr)
if !ok {
return fromTime, toTime, models.ErrInvalidFromTime
}
}
if toStr != "" {
toTime, ok = strToTime(toStr)
if !ok {
return fromTime, toTime, models.ErrInvalidToTime
}
}
return fromTime, toTime, nil
}
func strToTime(str string) (common.DateTime, bool) {
sec, err := strconv.ParseInt(str, 10, 64)
if err != nil {
return common.DateTime(time.Time{}), false
}
return common.DateTime(time.Unix(sec, 0)), true
}