2014-12-15 14:25:02 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Unknwon/macaron"
|
2015-01-16 04:54:19 -06:00
|
|
|
"github.com/macaron-contrib/binding"
|
2014-12-15 14:25:02 -06:00
|
|
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
2015-01-16 04:54:19 -06:00
|
|
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
2014-12-15 14:25:02 -06:00
|
|
|
)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Register adds http routes
|
2015-01-16 04:54:19 -06:00
|
|
|
func Register(r *macaron.Macaron) {
|
2015-01-15 05:16:54 -06:00
|
|
|
reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true})
|
2015-01-16 07:32:18 -06:00
|
|
|
reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
|
2015-01-19 11:01:04 -06:00
|
|
|
reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN)
|
2015-01-26 13:26:17 -06:00
|
|
|
reqAccountAdmin := middleware.RoleAuth(m.ROLE_ADMIN)
|
2015-01-16 04:54:19 -06:00
|
|
|
bind := binding.Bind
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// not logged in views
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/", reqSignedIn, Index)
|
2015-01-29 08:46:54 -06:00
|
|
|
r.Get("/logout", Logout)
|
2015-01-21 02:52:40 -06:00
|
|
|
r.Post("/login", bind(dtos.LoginCommand{}), LoginPost)
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/login/:name", OAuthLogin)
|
2015-01-27 03:09:54 -06:00
|
|
|
r.Get("/login", LoginView)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed views
|
2015-01-19 12:10:29 -06:00
|
|
|
r.Get("/profile/", reqSignedIn, Index)
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/account/", reqSignedIn, Index)
|
|
|
|
r.Get("/account/datasources/", reqSignedIn, Index)
|
2015-01-19 12:10:29 -06:00
|
|
|
r.Get("/account/users/", reqSignedIn, Index)
|
2015-01-16 05:28:35 -06:00
|
|
|
r.Get("/account/apikeys/", reqSignedIn, Index)
|
2015-01-18 01:56:19 -06:00
|
|
|
r.Get("/account/import/", reqSignedIn, Index)
|
2015-01-28 04:33:50 -06:00
|
|
|
r.Get("/admin/users", reqGrafanaAdmin, Index)
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/dashboard/*", reqSignedIn, Index)
|
2014-12-16 05:04:08 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// sign up
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/signup", Index)
|
2015-01-26 05:58:03 -06:00
|
|
|
r.Post("/api/user/signup", bind(m.CreateUserCommand{}), SignUp)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed api
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/api", func() {
|
2015-01-19 11:01:04 -06:00
|
|
|
// user
|
|
|
|
r.Group("/user", func() {
|
|
|
|
r.Get("/", GetUser)
|
2015-01-26 05:58:03 -06:00
|
|
|
r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser)
|
2015-01-19 11:01:04 -06:00
|
|
|
r.Post("/using/:id", SetUsingAccount)
|
|
|
|
r.Get("/accounts", GetUserAccounts)
|
2015-02-02 10:17:57 -06:00
|
|
|
r.Get("/stars/", GetUserStars)
|
2015-02-02 04:32:32 -06:00
|
|
|
r.Post("/stars/dashboard/:id", StarDashboard)
|
|
|
|
r.Delete("/stars/dashboard/:id", UnstarDashboard)
|
2015-01-19 11:01:04 -06:00
|
|
|
})
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// account
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/account", func() {
|
2015-01-26 08:42:22 -06:00
|
|
|
r.Get("/", GetAccount)
|
2015-01-26 05:58:03 -06:00
|
|
|
r.Post("/", bind(m.CreateAccountCommand{}), CreateAccount)
|
2015-01-26 08:42:22 -06:00
|
|
|
r.Put("/", bind(m.UpdateAccountCommand{}), UpdateAccount)
|
2015-01-26 05:58:03 -06:00
|
|
|
r.Post("/users", bind(m.AddAccountUserCommand{}), AddAccountUser)
|
2015-01-19 11:01:04 -06:00
|
|
|
r.Get("/users", GetAccountUsers)
|
|
|
|
r.Delete("/users/:id", RemoveAccountUser)
|
2015-01-26 13:26:17 -06:00
|
|
|
}, reqAccountAdmin)
|
|
|
|
|
2015-01-27 01:26:11 -06:00
|
|
|
// auth api keys
|
|
|
|
r.Group("/auth/keys", func() {
|
2015-01-16 05:06:24 -06:00
|
|
|
r.Combo("/").
|
2015-01-27 01:26:11 -06:00
|
|
|
Get(GetApiKeys).
|
|
|
|
Post(bind(m.AddApiKeyCommand{}), AddApiKey).
|
|
|
|
Put(bind(m.UpdateApiKeyCommand{}), UpdateApiKey)
|
|
|
|
r.Delete("/:id", DeleteApiKey)
|
2015-01-26 13:26:17 -06:00
|
|
|
}, reqAccountAdmin)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Data sources
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/datasources", func() {
|
|
|
|
r.Combo("/").Get(GetDataSources).Put(AddDataSource).Post(UpdateDataSource)
|
|
|
|
r.Delete("/:id", DeleteDataSource)
|
|
|
|
r.Any("/proxy/:id/*", reqSignedIn, ProxyDataSourceRequest)
|
2015-01-26 13:26:17 -06:00
|
|
|
}, reqAccountAdmin)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Dashboard
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/dashboard", func() {
|
|
|
|
r.Combo("/:slug").Get(GetDashboard).Delete(DeleteDashboard)
|
2015-01-16 08:28:44 -06:00
|
|
|
r.Post("/", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
|
2015-01-14 07:25:12 -06:00
|
|
|
})
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Search
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/search/", Search)
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// metrics
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/metrics/test", GetTestMetrics)
|
2015-01-15 05:16:54 -06:00
|
|
|
}, reqSignedIn)
|
|
|
|
|
|
|
|
// admin api
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Group("/api/admin", func() {
|
2015-01-19 11:01:04 -06:00
|
|
|
r.Get("/users", AdminSearchUsers)
|
2015-01-16 07:32:18 -06:00
|
|
|
}, reqGrafanaAdmin)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
|
|
|
// rendering
|
2015-01-16 04:54:19 -06:00
|
|
|
r.Get("/render/*", reqSignedIn, RenderToPng)
|
2015-01-06 02:11:00 -06:00
|
|
|
|
2015-01-16 04:54:19 -06:00
|
|
|
r.NotFound(NotFound)
|
2014-12-15 14:25:02 -06:00
|
|
|
}
|