grafana/pkg/api/api.go

115 lines
3.6 KiB
Go
Raw Normal View History

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"
"github.com/macaron-contrib/binding"
)
2015-01-14 07:25:12 -06:00
// Register adds http routes
func Register(r *macaron.Macaron) {
reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true})
reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true})
reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN)
reqAccountAdmin := middleware.RoleAuth(m.ROLE_ADMIN)
bind := binding.Bind
2015-01-14 07:25:12 -06:00
// not logged in views
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)
r.Get("/login/:name", OAuthLogin)
r.Get("/login", LoginView)
2015-01-14 07:25:12 -06:00
// authed views
2015-01-19 12:10:29 -06:00
r.Get("/profile/", reqSignedIn, Index)
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)
r.Get("/admin/settings", reqGrafanaAdmin, Index)
r.Get("/admin/users", reqGrafanaAdmin, Index)
r.Get("/admin/users/create", reqGrafanaAdmin, Index)
r.Get("/admin/users/edit/:id", reqGrafanaAdmin, Index)
r.Get("/dashboard/*", reqSignedIn, Index)
2014-12-16 05:04:08 -06:00
2015-01-14 07:25:12 -06:00
// sign up
r.Get("/signup", Index)
r.Post("/api/user/signup", bind(m.CreateUserCommand{}), SignUp)
2015-01-14 07:25:12 -06:00
// authed api
r.Group("/api", func() {
// user
r.Group("/user", func() {
r.Get("/", GetUser)
r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser)
r.Post("/using/:id", UserSetUsingOrg)
r.Get("/orgs", GetUserOrgList)
r.Post("/stars/dashboard/:id", StarDashboard)
r.Delete("/stars/dashboard/:id", UnstarDashboard)
r.Put("/password", bind(m.ChangeUserPasswordCommand{}), ChangeUserPassword)
})
2015-01-14 07:25:12 -06:00
// account
2015-02-23 11:29:01 -06:00
r.Group("/org", func() {
r.Get("/", GetOrg)
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)
}, reqAccountAdmin)
2015-01-27 01:26:11 -06:00
// auth api keys
r.Group("/auth/keys", func() {
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)
}, reqAccountAdmin)
2015-01-14 07:25:12 -06:00
// Data sources
r.Group("/datasources", func() {
r.Combo("/").Get(GetDataSources).Put(AddDataSource).Post(UpdateDataSource)
r.Delete("/:id", DeleteDataSource)
r.Get("/:id", GetDataSourceById)
}, reqAccountAdmin)
r.Get("/frontend/settings/", GetFrontendSettings)
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-14 07:25:12 -06:00
// Search
r.Get("/search/", Search)
2015-01-14 07:25:12 -06:00
// metrics
r.Get("/metrics/test", GetTestMetrics)
}, reqSignedIn)
// admin api
r.Group("/api/admin", func() {
r.Get("/settings", AdminGetSettings)
r.Get("/users", AdminSearchUsers)
r.Get("/users/:id", AdminGetUser)
r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
r.Put("/users/:id/details", bind(dtos.AdminUpdateUserForm{}), AdminUpdateUser)
r.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
r.Delete("/users/:id", AdminDeleteUser)
}, reqGrafanaAdmin)
// rendering
r.Get("/render/*", reqSignedIn, RenderToPng)
r.NotFound(NotFound)
}