From 3d789c05418e2fc4a329d01524f76849d55fd2b6 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Wed, 2 Aug 2017 23:23:41 +0200 Subject: [PATCH] api: better routes --- api/handlers_server.go | 4 ---- api/handlers_test.go | 12 ------------ api/routes.go | 1 - api/routes_server.go | 36 +++++++++++------------------------- api/routes_server_files.go | 33 ++++++++++++--------------------- 5 files changed, 23 insertions(+), 63 deletions(-) diff --git a/api/handlers_server.go b/api/handlers_server.go index 85b5107..5d4430e 100644 --- a/api/handlers_server.go +++ b/api/handlers_server.go @@ -22,10 +22,6 @@ func handlePatchServer(c *gin.Context) { } -func handlePutServer(c *gin.Context) { - -} - func handlePostServerReinstall(c *gin.Context) { } diff --git a/api/handlers_test.go b/api/handlers_test.go index 16d44ca..9ddcc2c 100644 --- a/api/handlers_test.go +++ b/api/handlers_test.go @@ -21,18 +21,6 @@ func TestHandleGetIndex(t *testing.T) { assert.Equal(t, http.StatusOK, recorder.Code) } -func TestHandlePutConfig(t *testing.T) { - router := gin.New() - recorder := httptest.NewRecorder() - - req, _ := http.NewRequest("PUT", "/", strings.NewReader("{}")) - - router.PUT("/", handlePutConfig) - router.ServeHTTP(recorder, req) - - assert.Equal(t, http.StatusOK, recorder.Code) -} - func TestHandlePatchConfig(t *testing.T) { router := gin.New() recorder := httptest.NewRecorder() diff --git a/api/routes.go b/api/routes.go index f32fd7e..2ff7cda 100644 --- a/api/routes.go +++ b/api/routes.go @@ -6,7 +6,6 @@ import ( func (api *API) registerRoutes() { api.router.GET("/", AuthHandler(""), handleGetIndex) - api.router.PUT("/config", AuthHandler("c:config"), handlePutConfig) api.router.PATCH("/config", AuthHandler("c:config"), handlePatchConfig) api.registerServerRoutes() diff --git a/api/routes_server.go b/api/routes_server.go index 5708767..fa06199 100644 --- a/api/routes_server.go +++ b/api/routes_server.go @@ -2,33 +2,19 @@ package api func (api *API) registerServerRoutes() { - // Big Picture Actions api.router.GET("/servers", AuthHandler("c:list"), handleGetServers) api.router.POST("/servers", AuthHandler("c:create"), handlePostServers) + api.router.DELETE("/server/:server", AuthHandler("g:server:delete"), handleDeleteServers) + api.router.GET("/server/:server", AuthHandler("s:get"), handleGetServer) + api.router.PATCH("/server/:server", AuthHandler("s:config"), handlePatchServer) - api.router.DELETE("/servers", AuthHandler("g:server:delete"), handleDeleteServers) - - // Server Actions - api.router.GET("/server", AuthHandler("s:get"), handleGetServer) - - api.router.PATCH("/server", AuthHandler("s:config"), handlePatchServer) - - api.router.PUT("/server", AuthHandler("s:config"), handlePutServer) - - api.router.POST("/server/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) - - api.router.POST("/server/password", AuthHandler(""), handlePostServerPassword) - - api.router.POST("/server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) - - api.router.PUT("/server/power", AuthHandler("s:power"), handlePutServerPower) - - api.router.POST("/server/command", AuthHandler("s:command"), handlePostServerCommand) - - api.router.GET("/server/log", AuthHandler("s:console"), handleGetServerLog) - - api.router.POST("/server/suspend", AuthHandler(""), handlePostServerSuspend) - - api.router.POST("/server/unsuspend", AuthHandler(""), handlePostServerUnsuspend) + api.router.POST("/server/:server/reinstall", AuthHandler("s:install-server"), handlePostServerReinstall) + api.router.POST("/server/:server/rebuild", AuthHandler("g:server:rebuild"), handlePostServerRebuild) + api.router.POST("/server/:server/password", AuthHandler(""), handlePostServerPassword) + api.router.POST("/server/:server/power", AuthHandler("s:power"), handlePutServerPower) + api.router.POST("/server/:server/command", AuthHandler("s:command"), handlePostServerCommand) + api.router.GET("/server/:server/log", AuthHandler("s:console"), handleGetServerLog) + api.router.POST("/server/:server/suspend", AuthHandler(""), handlePostServerSuspend) + api.router.POST("/server/:server/unsuspend", AuthHandler(""), handlePostServerUnsuspend) } diff --git a/api/routes_server_files.go b/api/routes_server_files.go index 2a8d933..f3b7b6e 100644 --- a/api/routes_server_files.go +++ b/api/routes_server_files.go @@ -1,29 +1,20 @@ package api func (api *API) registerServerFileRoutes() { - // TODO: better and more consistent route names. + api.router.GET("/server/:server/files/file/:file", AuthHandler("s:files:read"), handleGetFile) + api.router.GET("/server/:server/files/stat/:file", AuthHandler("s:files:"), handleGetFileStat) + api.router.GET("/server/:server/files/dir/:directory", AuthHandler("s:files:get"), handleGetDirectory) - api.router.POST("/server/file/folder", AuthHandler("s:files:create"), handlePostFilesFolder) + api.router.POST("/server/:server/files/dir/:directory", AuthHandler("s:files:create"), handlePostFilesFolder) + api.router.POST("/server/:server/files/file/:file", AuthHandler("s:files:post"), handlePostFile) - api.router.GET("/server/directory/:directory", AuthHandler("s:files:get"), handleGetDirectory) + api.router.POST("/server/:server/files/copy/:file", AuthHandler("s:files:copy"), handlePostFileCopy) + api.router.POST("/server/:server/files/move/:file", AuthHandler("s:files:move"), handlePostFileMove) + api.router.POST("/server/:server/files/rename/:file", AuthHandler("s:files:move"), handlePostFileMove) + api.router.POST("/server/:server/files/compress/:file", AuthHandler("s:files:compress"), handlePostFileCompress) + api.router.POST("/server/:server/files/decompress/:file", AuthHandler("s:files:decompress"), handlePostFileDecompress) - api.router.POST("/server/file/copy", AuthHandler("s:files:copy"), handlePostFileCopy) + api.router.DELETE("/server/:server/files/file/:file", AuthHandler("s:files:delete"), handleDeleteFile) - api.router.POST("/server/file/{move,rename}", AuthHandler("s:files:move"), handlePostFileMove) - - api.router.POST("/server/file/delete", AuthHandler("s:files:delete"), handlePostFileDelete) - - api.router.POST("/server/file/compress", AuthHandler("s:files:compress"), handlePostFileCompress) - - api.router.POST("/server/file/decompress", AuthHandler("s:files:decompress"), handlePostFileDecompress) - - api.router.GET("/server/file/stat/:file", AuthHandler("s:files:"), handleGetFileStat) - - api.router.GET("/server/file/f/:file", AuthHandler("s:files:read"), handleGetFile) - - api.router.POST("/server/file/save", AuthHandler("s:files:post"), handlePostFile) - - api.router.DELETE("/server/file/f/:file", AuthHandler("s:files:delete"), handleDeleteFile) - - api.router.GET("/server/file/download/:token", handleGetDownloadFile) + api.router.GET("/server/:server/files/download/:token", handleGetDownloadFile) }