mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Set shortcodes in trigger response entities based on config or request URL (#1099)
* adding trigger short code injection * more annotation provider stuff * fixed up tests * Fix validator
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
"github.com/fnproject/fn/api/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -28,5 +29,32 @@ func (s *Server) handleTriggerList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Annotate the outbound triggers
|
||||
|
||||
// this is fairly cludgy bit hard to do in datastore middleware confidently
|
||||
appCache := make(map[string]*models.App)
|
||||
newTriggers := make([]*models.Trigger, len(triggers.Items))
|
||||
|
||||
for idx, t := range triggers.Items {
|
||||
app, ok := appCache[t.AppID]
|
||||
if !ok {
|
||||
gotApp, err := s.Datastore().GetAppByID(ctx, t.AppID)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, fmt.Errorf("failed to get app for trigger %s", err))
|
||||
return
|
||||
}
|
||||
app = gotApp
|
||||
appCache[app.ID] = gotApp
|
||||
}
|
||||
|
||||
newT, err := s.triggerAnnotator.AnnotateTrigger(c, app, t)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
newTriggers[idx] = newT
|
||||
}
|
||||
|
||||
triggers.Items = newTriggers
|
||||
c.JSON(http.StatusOK, triggers)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user