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:
James Jeffrey
2018-08-21 02:26:36 -07:00
committed by Tom Coupland
parent 24f41c29b2
commit d336035678
4 changed files with 101 additions and 21 deletions

View File

@@ -1,8 +1,10 @@
package server
import (
"fmt"
"net/http"
"github.com/fnproject/fn/api/common"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
)
@@ -10,6 +12,7 @@ import (
func (s *Server) handleTriggerCreate(c *gin.Context) {
ctx := c.Request.Context()
trigger := &models.Trigger{}
log := common.Logger(ctx)
err := c.BindJSON(trigger)
if err != nil {
@@ -27,5 +30,19 @@ func (s *Server) handleTriggerCreate(c *gin.Context) {
return
}
c.JSON(http.StatusOK, triggerCreated)
app, err := s.datastore.GetAppByID(ctx, triggerCreated.AppID)
if err != nil {
log.Debugln(fmt.Errorf("unexpected error - trigger app not available: %s", err))
c.JSON(http.StatusOK, triggerCreated)
return
}
triggerAnnotated, err := s.triggerAnnotator.AnnotateTrigger(c, app, triggerCreated)
if err != nil {
log.Debugln("Failed to annotate trigger on cration")
c.JSON(http.StatusOK, triggerCreated)
return
}
c.JSON(http.StatusOK, triggerAnnotated)
}