2014-10-10 03:26:51 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
2014-10-20 19:26:43 +00:00
|
|
|
"regexp"
|
|
|
|
|
2014-10-10 03:26:51 +00:00
|
|
|
"github.com/drone/drone/server/handler"
|
|
|
|
"github.com/drone/drone/server/middleware"
|
|
|
|
|
|
|
|
"github.com/zenazn/goji/web"
|
|
|
|
)
|
|
|
|
|
|
|
|
func New() *web.Mux {
|
|
|
|
mux := web.New()
|
|
|
|
|
|
|
|
mux.Get("/api/logins", handler.GetLoginList)
|
|
|
|
mux.Get("/api/auth/:host", handler.GetLogin)
|
|
|
|
mux.Post("/api/auth/:host", handler.GetLogin)
|
|
|
|
mux.Get("/api/badge/:host/:owner/:name/status.svg", handler.GetBadge)
|
|
|
|
mux.Get("/api/badge/:host/:owner/:name/cc.xml", handler.GetCC)
|
2014-10-22 07:41:25 +00:00
|
|
|
mux.Get("/api/hook/:host/:token", handler.PostHook)
|
|
|
|
mux.Put("/api/hook/:host/:token", handler.PostHook)
|
|
|
|
mux.Post("/api/hook/:host/:token", handler.PostHook)
|
|
|
|
|
|
|
|
// these routes are here for backward compatibility
|
|
|
|
// to help people troubleshoot why their upgrade isn't
|
|
|
|
// working correctly. remove at some point
|
2014-10-10 03:26:51 +00:00
|
|
|
mux.Get("/api/hook/:host", handler.PostHook)
|
|
|
|
mux.Put("/api/hook/:host", handler.PostHook)
|
|
|
|
mux.Post("/api/hook/:host", handler.PostHook)
|
2014-10-22 07:41:25 +00:00
|
|
|
////
|
2014-10-10 03:26:51 +00:00
|
|
|
|
2014-10-16 18:35:25 +00:00
|
|
|
streams := web.New()
|
|
|
|
streams.Get("/api/stream/stdout/:id", handler.WsConsole)
|
|
|
|
streams.Get("/api/stream/user", handler.WsUser)
|
|
|
|
mux.Handle("/api/stream/*", streams)
|
|
|
|
|
2014-10-10 03:26:51 +00:00
|
|
|
repos := web.New()
|
|
|
|
repos.Use(middleware.SetRepo)
|
|
|
|
repos.Use(middleware.RequireRepoRead)
|
|
|
|
repos.Use(middleware.RequireRepoAdmin)
|
2014-10-20 19:26:43 +00:00
|
|
|
repos.Get(regexp.MustCompile(`^\/api\/repos\/(?P<host>(.*))\/(?P<owner>(.*))\/(?P<name>(.*))\/branches\/(?P<branch>(.*))\/commits\/(?P<commit>(.*))\/console$`), handler.GetOutput)
|
|
|
|
repos.Get(regexp.MustCompile(`^\/api\/repos\/(?P<host>(.*))\/(?P<owner>(.*))\/(?P<name>(.*))\/branches\/(?P<branch>(.*))\/commits\/(?P<commit>(.*))$`), handler.GetCommit)
|
2014-11-10 08:24:47 +00:00
|
|
|
repos.Post(regexp.MustCompile(`^\/api\/repos\/(?P<host>(.*))\/(?P<owner>(.*))\/(?P<name>(.*))\/branches\/(?P<branch>(.*))\/commits\/(?P<commit>(.*))$`), handler.PostCommit)
|
2014-10-10 03:26:51 +00:00
|
|
|
repos.Get("/api/repos/:host/:owner/:name/commits", handler.GetCommitList)
|
|
|
|
repos.Get("/api/repos/:host/:owner/:name", handler.GetRepo)
|
|
|
|
repos.Put("/api/repos/:host/:owner/:name", handler.PutRepo)
|
|
|
|
repos.Post("/api/repos/:host/:owner/:name", handler.PostRepo)
|
|
|
|
repos.Delete("/api/repos/:host/:owner/:name", handler.DelRepo)
|
2014-11-04 21:28:17 +00:00
|
|
|
mux.Handle("/api/repos/:host/:owner/:name", repos)
|
|
|
|
mux.Handle("/api/repos/:host/:owner/:name/*", repos)
|
2014-10-10 03:26:51 +00:00
|
|
|
|
|
|
|
users := web.New()
|
|
|
|
users.Use(middleware.RequireUserAdmin)
|
|
|
|
users.Get("/api/users/:host/:login", handler.GetUser)
|
|
|
|
users.Post("/api/users/:host/:login", handler.PostUser)
|
|
|
|
users.Delete("/api/users/:host/:login", handler.DelUser)
|
|
|
|
users.Get("/api/users", handler.GetUserList)
|
2014-11-04 21:28:17 +00:00
|
|
|
mux.Handle("/api/users", users)
|
|
|
|
mux.Handle("/api/users/*", users)
|
2014-10-10 03:26:51 +00:00
|
|
|
|
|
|
|
user := web.New()
|
|
|
|
user.Use(middleware.RequireUser)
|
|
|
|
user.Get("/api/user/feed", handler.GetUserFeed)
|
2014-11-11 16:01:10 +00:00
|
|
|
user.Get("/api/user/activity", handler.GetUserActivity)
|
2014-10-10 03:26:51 +00:00
|
|
|
user.Get("/api/user/repos", handler.GetUserRepos)
|
2014-10-28 15:16:50 +00:00
|
|
|
user.Post("/api/user/sync", handler.PostUserSync)
|
2014-10-10 03:26:51 +00:00
|
|
|
user.Get("/api/user", handler.GetUserCurrent)
|
|
|
|
user.Put("/api/user", handler.PutUser)
|
2014-11-04 21:28:17 +00:00
|
|
|
mux.Handle("/api/user", user)
|
|
|
|
mux.Handle("/api/user/*", user)
|
2014-10-10 03:26:51 +00:00
|
|
|
|
|
|
|
work := web.New()
|
|
|
|
work.Use(middleware.RequireUserAdmin)
|
|
|
|
work.Get("/api/work/started", handler.GetWorkStarted)
|
|
|
|
work.Get("/api/work/pending", handler.GetWorkPending)
|
|
|
|
work.Get("/api/work/assignments", handler.GetWorkAssigned)
|
|
|
|
work.Get("/api/workers", handler.GetWorkers)
|
|
|
|
work.Post("/api/workers", handler.PostWorker)
|
|
|
|
work.Delete("/api/workers", handler.DelWorker)
|
2014-11-04 21:28:17 +00:00
|
|
|
mux.Handle("/api/work", work)
|
|
|
|
mux.Handle("/api/work/*", work)
|
2014-10-10 03:26:51 +00:00
|
|
|
|
|
|
|
return mux
|
|
|
|
}
|