fn: improve UX (#325)

* fn: make UX more consistent with regards to app name position

* fn: improve detection of missing routes

* fn: fix update operations

- No longer delete-than-add for configuration updates
- Path cleaning before most of routes operations
This commit is contained in:
C Cirello
2016-11-22 00:27:48 +01:00
committed by Seif Lotfy سيف لطفي
parent e2e82086c5
commit fe845e1886
10 changed files with 189 additions and 96 deletions

View File

@@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
@@ -14,10 +15,16 @@ func (s *Server) handleRouteDelete(c *gin.Context) {
log := common.Logger(ctx)
appName := c.Param("app")
routePath := c.Param("route")
err := Api.Datastore.RemoveRoute(appName, routePath)
routePath := path.Clean(c.Param("route"))
if err != nil {
route, err := Api.Datastore.GetRoute(appName, routePath)
if err != nil || route == nil {
log.Error(models.ErrRoutesNotFound)
c.JSON(http.StatusNotFound, simpleError(models.ErrRoutesNotFound))
return
}
if err := Api.Datastore.RemoveRoute(appName, routePath); err != nil {
log.WithError(err).Debug(models.ErrRoutesRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesRemoving))
return

View File

@@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"
"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
@@ -15,7 +16,7 @@ func handleRouteGet(c *gin.Context) {
log := common.Logger(ctx)
appName := c.Param("app")
routePath := c.Param("route")
routePath := path.Clean(c.Param("route"))
route, err := Api.Datastore.GetRoute(appName, routePath)
if err != nil {

View File

@@ -64,7 +64,11 @@ func TestRouteDelete(t *testing.T) {
tasks := mockTasksConduit()
defer close(tasks)
router := testRouter(&datastore.Mock{}, &mqs.Mock{}, testRunner(t), tasks)
router := testRouter(&datastore.Mock{
FakeRoutes: []*models.Route{
&models.Route{AppName: "a", Path: "/myroute"},
},
}, &mqs.Mock{}, testRunner(t), tasks)
for i, test := range []struct {
path string
@@ -74,6 +78,7 @@ func TestRouteDelete(t *testing.T) {
}{
{"/v1/apps/a/routes", "", http.StatusTemporaryRedirect, nil},
{"/v1/apps/a/routes/myroute", "", http.StatusOK, nil},
{"/v1/apps/a/routes/missing", "", http.StatusNotFound, nil},
} {
_, rec := routerRequest(t, router, "DELETE", test.path, nil)

View File

@@ -3,6 +3,7 @@ package server
import (
"context"
"net/http"
"path"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
@@ -30,7 +31,7 @@ func handleRouteUpdate(c *gin.Context) {
}
wroute.Route.AppName = c.Param("app")
wroute.Route.Path = c.Param("route")
wroute.Route.Path = path.Clean(c.Param("route"))
if wroute.Route.Image != "" {
err = Api.Runner.EnsureImageExists(ctx, &runner.Config{