2015-09-30 03:21:17 +02:00
|
|
|
package router
|
|
|
|
|
2016-05-02 21:21:25 +02:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"github.com/drone/drone/router/middleware/header"
|
|
|
|
"github.com/drone/drone/router/middleware/session"
|
|
|
|
"github.com/drone/drone/router/middleware/token"
|
|
|
|
"github.com/drone/drone/server"
|
2016-07-09 00:40:29 +02:00
|
|
|
"github.com/drone/drone/server/template"
|
|
|
|
|
|
|
|
"github.com/drone/drone-ui/dist"
|
2016-05-02 21:21:25 +02:00
|
|
|
)
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
// Load loads the router
|
2016-05-02 21:21:25 +02:00
|
|
|
func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|
|
|
|
|
|
|
e := gin.New()
|
|
|
|
e.Use(gin.Recovery())
|
|
|
|
|
|
|
|
e.SetHTMLTemplate(template.Load())
|
2016-07-11 04:08:52 +02:00
|
|
|
|
|
|
|
fs := http.FileServer(dist.AssetFS())
|
|
|
|
e.GET("/static/*filepath", func(c *gin.Context) {
|
|
|
|
fs.ServeHTTP(c.Writer, c.Request)
|
|
|
|
})
|
2016-05-02 21:21:25 +02:00
|
|
|
|
|
|
|
e.Use(header.NoCache)
|
|
|
|
e.Use(header.Options)
|
|
|
|
e.Use(header.Secure)
|
|
|
|
e.Use(middleware...)
|
|
|
|
e.Use(session.SetUser())
|
|
|
|
e.Use(token.Refresh)
|
|
|
|
|
|
|
|
e.GET("/login", server.ShowLogin)
|
|
|
|
e.GET("/login/form", server.ShowLoginForm)
|
|
|
|
e.GET("/logout", server.GetLogout)
|
2016-07-09 00:40:29 +02:00
|
|
|
e.NoRoute(server.ShowIndex)
|
2016-05-02 21:21:25 +02:00
|
|
|
|
|
|
|
// TODO above will Go away with React UI
|
|
|
|
|
|
|
|
user := e.Group("/api/user")
|
|
|
|
{
|
|
|
|
user.Use(session.MustUser())
|
|
|
|
user.GET("", server.GetSelf)
|
|
|
|
user.GET("/feed", server.GetFeed)
|
|
|
|
user.GET("/repos", server.GetRepos)
|
|
|
|
user.GET("/repos/remote", server.GetRemoteRepos)
|
|
|
|
user.POST("/token", server.PostToken)
|
|
|
|
user.DELETE("/token", server.DeleteToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
users := e.Group("/api/users")
|
|
|
|
{
|
|
|
|
users.Use(session.MustAdmin())
|
|
|
|
users.GET("", server.GetUsers)
|
|
|
|
users.POST("", server.PostUser)
|
|
|
|
users.GET("/:login", server.GetUser)
|
|
|
|
users.PATCH("/:login", server.PatchUser)
|
|
|
|
users.DELETE("/:login", server.DeleteUser)
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:20:14 +02:00
|
|
|
teams := e.Group("/api/teams")
|
|
|
|
{
|
2016-10-14 12:21:40 +02:00
|
|
|
teams.Use(session.MustTeamAdmin())
|
2016-07-25 17:20:14 +02:00
|
|
|
|
|
|
|
team := teams.Group("/:team")
|
|
|
|
{
|
|
|
|
team.GET("/secrets", server.GetTeamSecrets)
|
|
|
|
team.POST("/secrets", server.PostTeamSecret)
|
|
|
|
team.DELETE("/secrets/:secret", server.DeleteTeamSecret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 02:13:21 +02:00
|
|
|
global := e.Group("/api/global")
|
|
|
|
{
|
|
|
|
global.Use(session.MustAdmin())
|
|
|
|
|
|
|
|
global.GET("/secrets", server.GetGlobalSecrets)
|
|
|
|
global.POST("/secrets", server.PostGlobalSecret)
|
|
|
|
global.DELETE("/secrets/:secret", server.DeleteGlobalSecret)
|
|
|
|
}
|
|
|
|
|
2016-05-02 21:21:25 +02:00
|
|
|
repos := e.Group("/api/repos/:owner/:name")
|
|
|
|
{
|
|
|
|
repos.POST("", server.PostRepo)
|
|
|
|
|
|
|
|
repo := repos.Group("")
|
|
|
|
{
|
|
|
|
repo.Use(session.SetRepo())
|
|
|
|
repo.Use(session.SetPerm())
|
|
|
|
repo.Use(session.MustPull)
|
|
|
|
|
|
|
|
repo.GET("", server.GetRepo)
|
|
|
|
repo.GET("/builds", server.GetBuilds)
|
|
|
|
repo.GET("/builds/:number", server.GetBuild)
|
|
|
|
repo.GET("/logs/:number/:job", server.GetBuildLogs)
|
|
|
|
repo.POST("/sign", session.MustPush, server.Sign)
|
|
|
|
|
2016-06-27 23:06:02 +02:00
|
|
|
repo.GET("/secrets", session.MustPush, server.GetSecrets)
|
2016-05-02 21:21:25 +02:00
|
|
|
repo.POST("/secrets", session.MustPush, server.PostSecret)
|
|
|
|
repo.DELETE("/secrets/:secret", session.MustPush, server.DeleteSecret)
|
|
|
|
|
|
|
|
// requires push permissions
|
|
|
|
repo.PATCH("", session.MustPush, server.PatchRepo)
|
2016-07-21 19:43:29 +02:00
|
|
|
repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo)
|
2016-07-21 23:04:42 +02:00
|
|
|
repo.POST("/chown", session.MustRepoAdmin(), server.ChownRepo)
|
2016-05-02 21:21:25 +02:00
|
|
|
|
|
|
|
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
|
|
|
|
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
badges := e.Group("/api/badges/:owner/:name")
|
|
|
|
{
|
|
|
|
badges.GET("/status.svg", server.GetBadge)
|
|
|
|
badges.GET("/cc.xml", server.GetCC)
|
|
|
|
}
|
|
|
|
|
|
|
|
e.POST("/hook", server.PostHook)
|
|
|
|
e.POST("/api/hook", server.PostHook)
|
|
|
|
|
|
|
|
stream := e.Group("/api/stream")
|
|
|
|
{
|
|
|
|
stream.Use(session.SetRepo())
|
|
|
|
stream.Use(session.SetPerm())
|
|
|
|
stream.Use(session.MustPull)
|
|
|
|
|
|
|
|
stream.GET("/:owner/:name", server.GetRepoEvents)
|
|
|
|
stream.GET("/:owner/:name/:build/:number", server.GetStream)
|
|
|
|
}
|
2016-07-09 00:40:29 +02:00
|
|
|
ws := e.Group("/ws")
|
|
|
|
{
|
|
|
|
ws.GET("/feed", server.EventStream)
|
|
|
|
ws.GET("/logs/:owner/:name/:build/:number",
|
|
|
|
session.SetRepo(),
|
|
|
|
session.SetPerm(),
|
|
|
|
session.MustPull,
|
|
|
|
server.LogStream,
|
|
|
|
)
|
|
|
|
}
|
2016-05-02 21:21:25 +02:00
|
|
|
|
|
|
|
auth := e.Group("/authorize")
|
|
|
|
{
|
|
|
|
auth.GET("", server.GetLogin)
|
|
|
|
auth.POST("", server.GetLogin)
|
|
|
|
auth.POST("/token", server.GetLoginToken)
|
|
|
|
}
|
|
|
|
|
2016-05-11 07:19:45 +02:00
|
|
|
builds := e.Group("/api/builds")
|
|
|
|
{
|
|
|
|
builds.Use(session.MustAdmin())
|
|
|
|
builds.GET("", server.GetBuildQueue)
|
|
|
|
}
|
|
|
|
|
2016-05-11 23:37:56 +02:00
|
|
|
agents := e.Group("/api/agents")
|
|
|
|
{
|
|
|
|
agents.Use(session.MustAdmin())
|
|
|
|
agents.GET("", server.GetAgents)
|
|
|
|
}
|
2016-05-11 07:19:45 +02:00
|
|
|
|
2016-05-02 21:21:25 +02:00
|
|
|
queue := e.Group("/api/queue")
|
|
|
|
{
|
|
|
|
queue.Use(session.AuthorizeAgent)
|
|
|
|
queue.POST("/pull", server.Pull)
|
|
|
|
queue.POST("/pull/:os/:arch", server.Pull)
|
|
|
|
queue.POST("/wait/:id", server.Wait)
|
|
|
|
queue.POST("/stream/:id", server.Stream)
|
|
|
|
queue.POST("/status/:id", server.Update)
|
2016-05-11 23:37:56 +02:00
|
|
|
queue.POST("/ping", server.Ping)
|
2016-05-23 23:35:58 +02:00
|
|
|
|
|
|
|
queue.POST("/logs/:id", server.PostLogs)
|
|
|
|
queue.GET("/logs/:id", server.WriteLogs)
|
2016-05-02 21:21:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DELETE THESE
|
|
|
|
// gitlab := e.Group("/gitlab/:owner/:name")
|
|
|
|
// {
|
|
|
|
// gitlab.Use(session.SetRepo())
|
|
|
|
// gitlab.GET("/commits/:sha", GetCommit)
|
|
|
|
// gitlab.GET("/pulls/:number", GetPullRequest)
|
|
|
|
//
|
|
|
|
// redirects := gitlab.Group("/redirect")
|
|
|
|
// {
|
|
|
|
// redirects.GET("/commits/:sha", RedirectSha)
|
|
|
|
// redirects.GET("/pulls/:number", RedirectPullRequest)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// bots := e.Group("/bots")
|
|
|
|
// {
|
|
|
|
// bots.Use(session.MustUser())
|
|
|
|
// bots.POST("/slack", Slack)
|
|
|
|
// bots.POST("/slack/:command", Slack)
|
|
|
|
// }
|
|
|
|
|
2016-07-09 00:40:29 +02:00
|
|
|
return e
|
2016-05-02 21:21:25 +02:00
|
|
|
}
|