Implementing force delete for apps

Deployment-Impact: DB schema changed

API Impact: HTTP DELETE /apps/{app} accepts query parameters: /apps/{app}?force=True

Closes: #302
This commit is contained in:
Denis Makogon
2017-09-11 12:25:32 +03:00
parent 3e190342fb
commit 78f2d51bfa
3 changed files with 23 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/fnproject/fn/api/common"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
"strconv"
)
func (s *Server) handleAppDelete(c *gin.Context) {
@@ -21,10 +22,16 @@ func (s *Server) handleAppDelete(c *gin.Context) {
handleErrorResponse(c, err)
return
}
//TODO allow this? #528
if len(routes) > 0 {
handleErrorResponse(c, models.ErrDeleteAppsWithRoutes)
return
forceDelete, _ := strconv.ParseBool(c.Query("force"))
if !forceDelete {
if len(routes) > 0 {
handleErrorResponse(c, models.ErrDeleteAppsWithRoutes)
return
}
} else {
s.Datastore.BatchDeleteLogs(ctx, app.Name)
s.Datastore.BatchDeleteCalls(ctx, app.Name)
s.Datastore.BatchDeleteRoutes(ctx, app.Name)
}
err = s.FireBeforeAppDelete(ctx, app)