mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add annotation to trigger on create if endpoints are enabled (#1177)
* Add annotations for creation of triggers and fns along with the test for them fixes #1178 * Log errors and still return created resource for annotation failures
This commit is contained in:
committed by
Tom Coupland
parent
24f41c29b2
commit
d336035678
@@ -3,12 +3,14 @@ package server
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fnproject/fn/api/common"
|
||||
"github.com/fnproject/fn/api/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (s *Server) handleFnCreate(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
log := common.Logger(ctx)
|
||||
|
||||
fn := &models.Fn{}
|
||||
err := c.BindJSON(fn)
|
||||
@@ -24,7 +26,22 @@ func (s *Server) handleFnCreate(c *gin.Context) {
|
||||
fnCreated, err := s.datastore.InsertFn(ctx, fn)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, fnCreated)
|
||||
app, err := s.datastore.GetAppByID(ctx, fnCreated.AppID)
|
||||
if err != nil {
|
||||
log.Debugln("Failed to lookup app.")
|
||||
c.JSON(http.StatusOK, fnCreated)
|
||||
return
|
||||
}
|
||||
|
||||
fnAnnotated, err := s.fnAnnotator.AnnotateFn(c, app, fnCreated)
|
||||
if err != nil {
|
||||
log.Debugln("Failed to annotate fn")
|
||||
c.JSON(http.StatusOK, fnCreated)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, fnAnnotated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user