goploy/route/Index.go

123 lines
9.2 KiB
Go
Raw Normal View History

2020-08-04 14:28:25 +08:00
package route
import (
"github.com/zhenorzz/goploy/controller"
"github.com/zhenorzz/goploy/core"
router "github.com/zhenorzz/goploy/core"
"github.com/zhenorzz/goploy/middleware"
"github.com/zhenorzz/goploy/ws"
2020-09-18 20:18:27 +08:00
"net/http"
2020-08-04 14:28:25 +08:00
)
// Init router
func Init() *router.Router {
var rt = new(router.Router)
// rt.Middleware(example)
// no need to check login
rt.RegisterWhiteList(map[string]struct{}{
2020-11-23 17:49:38 +08:00
"/user/login": {},
"/deploy/webhook": {},
"/deploy/callback": {},
2020-08-04 14:28:25 +08:00
})
// websocket route
2020-09-18 20:18:27 +08:00
rt.Add("/ws/connect", http.MethodGet, ws.GetHub().Connect)
2021-02-26 16:45:13 +08:00
rt.Add("/ws/xterm", http.MethodGet, ws.GetHub().Xterm)
2020-08-04 14:28:25 +08:00
// user route
2020-09-18 20:18:27 +08:00
rt.Add("/user/login", http.MethodPost, controller.User{}.Login)
rt.Add("/user/info", http.MethodGet, controller.User{}.Info)
rt.Add("/user/getList", http.MethodGet, controller.User{}.GetList)
rt.Add("/user/getTotal", http.MethodGet, controller.User{}.GetTotal)
rt.Add("/user/getOption", http.MethodGet, controller.User{}.GetOption)
rt.Add("/user/add", http.MethodPost, controller.User{}.Add).Role(core.RoleAdmin)
2021-02-20 13:12:16 +08:00
rt.Add("/user/edit", http.MethodPut, controller.User{}.Edit).Role(core.RoleAdmin)
2020-09-18 20:18:27 +08:00
rt.Add("/user/remove", http.MethodDelete, controller.User{}.Remove).Role(core.RoleAdmin)
2021-02-20 13:12:16 +08:00
rt.Add("/user/changePassword", http.MethodPut, controller.User{}.ChangePassword)
2020-08-04 14:28:25 +08:00
// namespace route
2020-09-18 20:18:27 +08:00
rt.Add("/namespace/getList", http.MethodGet, controller.Namespace{}.GetList)
rt.Add("/namespace/getTotal", http.MethodGet, controller.Namespace{}.GetTotal)
rt.Add("/namespace/getBindUserList", http.MethodGet, controller.Namespace{}.GetBindUserList)
rt.Add("/namespace/getUserOption", http.MethodGet, controller.Namespace{}.GetUserOption)
rt.Add("/namespace/add", http.MethodPost, controller.Namespace{}.Add).Role(core.RoleAdmin)
2021-02-20 13:12:16 +08:00
rt.Add("/namespace/edit", http.MethodPut, controller.Namespace{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager})
2020-09-18 20:18:27 +08:00
rt.Add("/namespace/addUser", http.MethodPost, controller.Namespace{}.AddUser).Roles([]string{core.RoleAdmin, core.RoleManager})
rt.Add("/namespace/removeUser", http.MethodDelete, controller.Namespace{}.RemoveUser).Roles([]string{core.RoleAdmin, core.RoleManager})
2020-08-04 14:28:25 +08:00
// project route
2020-09-18 20:18:27 +08:00
rt.Add("/project/getList", http.MethodGet, controller.Project{}.GetList)
rt.Add("/project/getTotal", http.MethodGet, controller.Project{}.GetTotal)
rt.Add("/project/getRemoteBranchList", http.MethodGet, controller.Project{}.GetRemoteBranchList)
rt.Add("/project/getBindServerList", http.MethodGet, controller.Project{}.GetBindServerList)
rt.Add("/project/getBindUserList", http.MethodGet, controller.Project{}.GetBindUserList)
2021-01-06 17:29:25 +08:00
rt.Add("/project/getProjectFileList", http.MethodGet, controller.Project{}.GetProjectFileList)
rt.Add("/project/getProjectFileContent", http.MethodGet, controller.Project{}.GetProjectFileContent)
2020-09-18 20:18:27 +08:00
rt.Add("/project/add", http.MethodPost, controller.Project{}.Add).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-02-20 13:12:16 +08:00
rt.Add("/project/edit", http.MethodPut, controller.Project{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/project/setAutoDeploy", http.MethodPut, controller.Project{}.SetAutoDeploy).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/project/remove", http.MethodDelete, controller.Project{}.Remove).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-01-06 17:29:25 +08:00
rt.Add("/project/uploadFile", http.MethodPost, controller.Project{}.UploadFile).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/project/removeFile", http.MethodDelete, controller.Project{}.RemoveFile).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/project/addServer", http.MethodPost, controller.Project{}.AddServer).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/project/addUser", http.MethodPost, controller.Project{}.AddUser).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/project/removeServer", http.MethodDelete, controller.Project{}.RemoveServer).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/project/removeUser", http.MethodDelete, controller.Project{}.RemoveUser).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-01-06 17:29:25 +08:00
rt.Add("/project/addFile", http.MethodPost, controller.Project{}.AddFile).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-02-20 13:12:16 +08:00
rt.Add("/project/editFile", http.MethodPut, controller.Project{}.EditFile).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/project/addTask", http.MethodPost, controller.Project{}.AddTask).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-02-20 13:12:16 +08:00
rt.Add("/project/removeTask", http.MethodDelete, controller.Project{}.RemoveTask).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/project/getTaskList", http.MethodGet, controller.Project{}.GetTaskList).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-25 20:05:25 +08:00
rt.Add("/project/getReviewList", http.MethodGet, controller.Project{}.GetReviewList)
2020-08-04 14:28:25 +08:00
2021-05-23 22:29:35 +08:00
rt.Add("/repository/getCommitList", http.MethodGet, controller.Repository{}.GetCommitList)
rt.Add("/repository/getBranchList", http.MethodGet, controller.Repository{}.GetBranchList)
rt.Add("/repository/getTagList", http.MethodGet, controller.Repository{}.GetTagList)
2020-08-04 14:28:25 +08:00
// monitor route
2020-09-18 20:18:27 +08:00
rt.Add("/monitor/getList", http.MethodGet, controller.Monitor{}.GetList)
rt.Add("/monitor/getTotal", http.MethodGet, controller.Monitor{}.GetTotal)
rt.Add("/monitor/check", http.MethodPost, controller.Monitor{}.Check).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/monitor/add", http.MethodPost, controller.Monitor{}.Add).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2021-02-20 13:12:16 +08:00
rt.Add("/monitor/edit", http.MethodPut, controller.Monitor{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/monitor/toggle", http.MethodPut, controller.Monitor{}.Toggle).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/monitor/remove", http.MethodDelete, controller.Monitor{}.Remove).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-08-04 14:28:25 +08:00
//// deploy route
2020-09-18 20:18:27 +08:00
rt.Add("/deploy/getList", http.MethodGet, controller.Deploy{}.GetList)
2020-12-23 17:38:39 +08:00
rt.Add("/deploy/getPublishTrace", http.MethodGet, controller.Deploy{}.GetPublishTrace)
rt.Add("/deploy/getPublishTraceDetail", http.MethodGet, controller.Deploy{}.GetPublishTraceDetail)
2020-09-18 20:18:27 +08:00
rt.Add("/deploy/getPreview", http.MethodGet, controller.Deploy{}.GetPreview)
2021-02-20 13:12:16 +08:00
rt.Add("/deploy/review", http.MethodPut, controller.Deploy{}.Review).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
rt.Add("/deploy/resetState", http.MethodPut, controller.Deploy{}.ResetState).Roles([]string{core.RoleAdmin, core.RoleManager})
2021-02-12 23:05:06 +08:00
rt.Add("/deploy/publish", http.MethodPost, controller.Deploy{}.Publish, middleware.HasPublishAuth)
rt.Add("/deploy/rebuild", http.MethodPost, controller.Deploy{}.Rebuild, middleware.HasPublishAuth)
2020-11-07 17:37:26 +08:00
rt.Add("/deploy/greyPublish", http.MethodPost, controller.Deploy{}.GreyPublish, middleware.HasPublishAuth).Roles([]string{core.RoleAdmin, core.RoleManager, core.RoleGroupManager})
2020-09-18 20:18:27 +08:00
rt.Add("/deploy/webhook", http.MethodPost, controller.Deploy{}.Webhook, middleware.FilterEvent)
2020-09-25 20:05:25 +08:00
rt.Add("/deploy/callback", http.MethodGet, controller.Deploy{}.Callback)
2020-08-04 14:28:25 +08:00
// server route
2020-09-18 20:18:27 +08:00
rt.Add("/server/getList", http.MethodGet, controller.Server{}.GetList)
rt.Add("/server/getTotal", http.MethodGet, controller.Server{}.GetTotal)
rt.Add("/server/getOption", http.MethodGet, controller.Server{}.GetOption)
2021-02-14 14:22:22 +08:00
rt.Add("/server/getPublicKey", http.MethodGet, controller.Server{}.GetPublicKey)
2020-09-18 20:18:27 +08:00
rt.Add("/server/check", http.MethodPost, controller.Server{}.Check).Roles([]string{core.RoleAdmin, core.RoleManager})
rt.Add("/server/add", http.MethodPost, controller.Server{}.Add).Roles([]string{core.RoleAdmin, core.RoleManager})
2021-02-20 13:12:16 +08:00
rt.Add("/server/edit", http.MethodPut, controller.Server{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager})
2021-05-25 16:12:08 +08:00
rt.Add("/server/toggle", http.MethodPut, controller.Server{}.Toggle).Roles([]string{core.RoleAdmin, core.RoleManager})
2020-08-04 14:28:25 +08:00
// crontab route
2020-09-18 20:18:27 +08:00
rt.Add("/crontab/getList", http.MethodGet, controller.Crontab{}.GetList)
rt.Add("/crontab/getTotal", http.MethodGet, controller.Crontab{}.GetTotal)
2021-05-20 13:21:21 +08:00
rt.Add("/crontab/getCrontabsInRemoteServer", http.MethodGet, controller.Crontab{}.GetCrontabsInRemoteServer)
2020-09-18 20:18:27 +08:00
rt.Add("/crontab/getBindServerList", http.MethodGet, controller.Crontab{}.GetBindServerList)
rt.Add("/crontab/add", http.MethodPost, controller.Crontab{}.Add).Roles([]string{core.RoleAdmin, core.RoleManager})
2021-02-20 13:12:16 +08:00
rt.Add("/crontab/edit", http.MethodPut, controller.Crontab{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager})
2020-09-18 20:18:27 +08:00
rt.Add("/crontab/import", http.MethodPost, controller.Crontab{}.Import).Roles([]string{core.RoleAdmin, core.RoleManager})
rt.Add("/crontab/remove", http.MethodDelete, controller.Crontab{}.Remove).Roles([]string{core.RoleAdmin, core.RoleManager})
rt.Add("/crontab/addServer", http.MethodPost, controller.Crontab{}.AddServer).Roles([]string{core.RoleAdmin, core.RoleManager})
rt.Add("/crontab/removeCrontabServer", http.MethodDelete, controller.Crontab{}.RemoveCrontabServer).Roles([]string{core.RoleAdmin, core.RoleManager})
2020-08-04 14:28:25 +08:00
rt.Start()
return rt
}