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
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user