mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge branch 'master' of github.com:iron-io/functions into runner-route-not-found
This commit is contained in:
@@ -56,5 +56,5 @@ func handleAppCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, appResponse{"App successfully created", wapp})
|
||||
c.JSON(http.StatusCreated, appResponse{"App successfully created", wapp.App})
|
||||
}
|
||||
|
||||
@@ -29,5 +29,5 @@ func handleAppGet(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, &models.AppWrapper{app})
|
||||
c.JSON(http.StatusOK, appResponse{"Successfully loaded app", app})
|
||||
}
|
||||
|
||||
@@ -23,5 +23,5 @@ func handleAppList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, &models.AppsWrapper{apps})
|
||||
c.JSON(http.StatusOK, appsResponse{"Successfully listed applications", apps})
|
||||
}
|
||||
|
||||
@@ -39,5 +39,5 @@ func handleAppUpdate(c *gin.Context) {
|
||||
wapp.App = app
|
||||
|
||||
// Nothing to update right now in apps
|
||||
c.JSON(http.StatusOK, appResponse{"App successfully updated", wapp})
|
||||
c.JSON(http.StatusOK, appResponse{"App successfully updated", wapp.App})
|
||||
}
|
||||
|
||||
@@ -17,23 +17,23 @@ import (
|
||||
)
|
||||
|
||||
type appResponse struct {
|
||||
Message string
|
||||
App models.AppWrapper
|
||||
Message string `json:"message"`
|
||||
App *models.App `json:"app"`
|
||||
}
|
||||
|
||||
type appsResponse struct {
|
||||
Message string
|
||||
Apps models.AppsWrapper
|
||||
Message string `json:"message"`
|
||||
Apps models.Apps `json:"apps"`
|
||||
}
|
||||
|
||||
type routeResponse struct {
|
||||
Message string
|
||||
Route models.RouteWrapper
|
||||
Message string `json:"message"`
|
||||
Route *models.Route `json:"route"`
|
||||
}
|
||||
|
||||
type routesResponse struct {
|
||||
Message string
|
||||
Routes models.RoutesWrapper
|
||||
Message string `json:"message"`
|
||||
Routes models.Routes `json:"routes"`
|
||||
}
|
||||
|
||||
func testRouter() *gin.Engine {
|
||||
|
||||
@@ -75,5 +75,5 @@ func handleRouteCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, routeResponse{"Route successfully created", wroute})
|
||||
c.JSON(http.StatusCreated, routeResponse{"Route successfully created", wroute.Route})
|
||||
}
|
||||
|
||||
@@ -33,5 +33,5 @@ func handleRouteGet(c *gin.Context) {
|
||||
|
||||
log.WithFields(logrus.Fields{"route": route}).Debug("Got route")
|
||||
|
||||
c.JSON(http.StatusOK, &models.RouteWrapper{route})
|
||||
c.JSON(http.StatusOK, routeResponse{"Successfully loaded route", route})
|
||||
}
|
||||
|
||||
@@ -37,5 +37,5 @@ func handleRouteList(c *gin.Context) {
|
||||
|
||||
log.WithFields(logrus.Fields{"routes": routes}).Debug("Got routes")
|
||||
|
||||
c.JSON(http.StatusOK, &models.RoutesWrapper{Routes: routes})
|
||||
c.JSON(http.StatusOK, routesResponse{"Sucessfully listed routes", routes})
|
||||
}
|
||||
|
||||
@@ -45,5 +45,5 @@ func handleRouteUpdate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, routeResponse{"Route successfully updated", wroute})
|
||||
c.JSON(http.StatusOK, routeResponse{"Route successfully updated", wroute.Route})
|
||||
}
|
||||
|
||||
@@ -106,7 +106,9 @@ func handleRunner(c *gin.Context) {
|
||||
log.WithField("routes", routes).Debug("Got routes from datastore")
|
||||
for _, el := range routes {
|
||||
if params, match := matchRoute(el.Path, route); match {
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
var stdout bytes.Buffer // TODO: should limit the size of this, error if gets too big. akin to: https://golang.org/pkg/io/#LimitReader
|
||||
stderr := runner.NewFuncLogger(appName, route, el.Image, reqID)
|
||||
|
||||
envVars := map[string]string{
|
||||
"METHOD": c.Request.Method,
|
||||
@@ -130,13 +132,18 @@ func handleRunner(c *gin.Context) {
|
||||
envVars["PARAM_"+strings.ToUpper(param.Key)] = param.Value
|
||||
}
|
||||
|
||||
// headers
|
||||
for header, value := range c.Request.Header {
|
||||
envVars["HEADER_"+strings.ToUpper(header)] = strings.Join(value, " ")
|
||||
}
|
||||
|
||||
cfg := &runner.Config{
|
||||
Image: el.Image,
|
||||
Timeout: 30 * time.Second,
|
||||
ID: reqID,
|
||||
AppName: appName,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
Stderr: stderr,
|
||||
Env: envVars,
|
||||
}
|
||||
|
||||
@@ -151,7 +158,7 @@ func handleRunner(c *gin.Context) {
|
||||
if result.Status() == "success" {
|
||||
c.Data(http.StatusOK, "", stdout.Bytes())
|
||||
} else {
|
||||
log.WithFields(logrus.Fields{"app": appName, "route": el, "req_id": reqID}).Debug(stderr.String())
|
||||
// log.WithFields(logrus.Fields{"app": appName, "route": el, "req_id": reqID}).Debug(stderr.String())
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// Version of IronFunctions
|
||||
var Version = "0.0.2"
|
||||
var Version = "0.0.32"
|
||||
|
||||
func handleVersion(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"version": Version})
|
||||
|
||||
Reference in New Issue
Block a user