2014-12-15 14:25:02 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Unknwon/macaron"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2015-02-10 03:19:43 -06:00
|
|
|
"github.com/macaron-contrib/binding"
|
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-02-12 08:46:14 -06:00
|
|
|
r.Get("/admin/settings", reqGrafanaAdmin, Index)
|
2015-01-28 04:33:50 -06:00
|
|
|
r.Get("/admin/users", reqGrafanaAdmin, Index)
|
2015-02-10 09:26:23 -06:00
|
|
|
r.Get("/admin/users/create", reqGrafanaAdmin, Index)
|
|
|
|
r.Get("/admin/users/edit/:id", 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-02-23 13:07:49 -06:00
|
|
|
r.Post("/using/:id", UserSetUsingOrg)
|
|
|
|
r.Get("/orgs", GetUserOrgList)
|
2015-02-02 04:32:32 -06:00
|
|
|
r.Post("/stars/dashboard/:id", StarDashboard)
|
|
|
|
r.Delete("/stars/dashboard/:id", UnstarDashboard)
|
2015-02-19 09:09:49 -06:00
|
|
|
r.Put("/password", bind(m.ChangeUserPasswordCommand{}), ChangeUserPassword)
|
2015-01-19 11:01:04 -06:00
|
|
|
})
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// account
|
2015-02-23 11:29:01 -06:00
|
|
|
r.Group("/org", func() {
|
|
|
|
r.Get("/", GetOrg)
|
2015-02-23 13:07:49 -06:00
|
|
|
r.Post("/", bind(m.CreateOrgCommand{}), CreateOrg)
|
|
|
|
r.Put("/", bind(m.UpdateOrgCommand{}), UpdateOrg)
|
|
|
|
r.Post("/users", bind(m.AddOrgUserCommand{}), AddOrgUser)
|
2015-02-23 11:29:01 -06:00
|
|
|
r.Get("/users", GetOrgUsers)
|
|
|
|
r.Delete("/users/:id", RemoveOrgUser)
|
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)
|
2015-02-14 03:04:27 -06:00
|
|
|
r.Get("/:id", GetDataSourceById)
|
2015-01-26 13:26:17 -06:00
|
|
|
}, reqAccountAdmin)
|
|
|
|
|
2015-02-18 07:06:44 -06:00
|
|
|
r.Get("/frontend/settings/", GetFrontendSettings)
|
2015-02-10 03:19:43 -06:00
|
|
|
r.Any("/datasources/proxy/:id/*", reqSignedIn, ProxyDataSourceRequest)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Dashboard
|
2015-02-03 08:04:35 -06:00
|
|
|
r.Group("/dashboards", func() {
|
|
|
|
r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
|
|
|
|
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
|
|
|
|
r.Get("/home", GetHomeDashboard)
|
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-02-12 08:46:14 -06:00
|
|
|
r.Get("/settings", AdminGetSettings)
|
2015-01-19 11:01:04 -06:00
|
|
|
r.Get("/users", AdminSearchUsers)
|
2015-02-10 08:36:51 -06:00
|
|
|
r.Get("/users/:id", AdminGetUser)
|
|
|
|
r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
|
2015-02-23 04:24:22 -06:00
|
|
|
r.Put("/users/:id/details", bind(dtos.AdminUpdateUserForm{}), AdminUpdateUser)
|
|
|
|
r.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
|
2015-02-11 09:47:22 -06:00
|
|
|
r.Delete("/users/:id", AdminDeleteUser)
|
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
|
|
|
}
|