2020-12-15 02:32:06 -06:00
|
|
|
// Package api contains API logic.
|
2014-12-15 14:25:02 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-12-09 09:22:24 -06:00
|
|
|
"time"
|
|
|
|
|
2016-01-13 08:38:54 -06:00
|
|
|
"github.com/go-macaron/binding"
|
2016-02-20 16:51:22 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/avatar"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
2021-02-04 00:37:28 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/frontendlogging"
|
2018-06-25 09:36:47 -05:00
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
2020-12-15 02:32:06 -06:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2021-04-01 13:04:02 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2019-06-26 01:47:03 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2021-04-14 09:31:27 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
|
|
acmiddleware "github.com/grafana/grafana/pkg/services/accesscontrol/middleware"
|
2014-12-15 14:25:02 -06:00
|
|
|
)
|
|
|
|
|
2020-12-15 02:32:06 -06:00
|
|
|
var plog = log.New("api")
|
|
|
|
|
2020-10-28 03:36:57 -05:00
|
|
|
// registerRoutes registers all API HTTP routes.
|
2018-03-22 16:13:46 -05:00
|
|
|
func (hs *HTTPServer) registerRoutes() {
|
2021-03-16 10:46:34 -05:00
|
|
|
reqNoAuth := middleware.NoAuth()
|
2018-10-11 05:36:04 -05:00
|
|
|
reqSignedIn := middleware.ReqSignedIn
|
2021-06-14 11:02:05 -05:00
|
|
|
reqNotSignedIn := middleware.ReqNotSignedIn
|
2021-02-27 11:04:28 -06:00
|
|
|
reqSignedInNoAnonymous := middleware.ReqSignedInNoAnonymous
|
2018-10-11 05:36:04 -05:00
|
|
|
reqGrafanaAdmin := middleware.ReqGrafanaAdmin
|
|
|
|
reqEditorRole := middleware.ReqEditorRole
|
|
|
|
reqOrgAdmin := middleware.ReqOrgAdmin
|
2019-03-14 04:02:46 -05:00
|
|
|
reqCanAccessTeams := middleware.AdminOrFeatureEnabled(hs.Cfg.EditorsCanAdmin)
|
2020-12-11 04:44:44 -06:00
|
|
|
reqSnapshotPublicModeOrSignedIn := middleware.SnapshotPublicModeOrSignedIn(hs.Cfg)
|
2020-12-15 12:09:04 -06:00
|
|
|
redirectFromLegacyPanelEditURL := middleware.RedirectFromLegacyPanelEditURL(hs.Cfg)
|
2021-04-14 09:31:27 -05:00
|
|
|
authorize := acmiddleware.Middleware(hs.AccessControl)
|
2019-02-11 14:12:01 -06:00
|
|
|
quota := middleware.Quota(hs.QuotaService)
|
2015-01-16 04:54:19 -06:00
|
|
|
bind := binding.Bind
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2018-04-27 06:41:58 -05:00
|
|
|
r := hs.RouteRegister
|
2016-08-29 07:45:28 -05:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// not logged in views
|
2019-01-15 08:15:52 -06:00
|
|
|
r.Get("/logout", hs.Logout)
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), routing.Wrap(hs.LoginPost))
|
2019-01-15 08:15:52 -06:00
|
|
|
r.Get("/login/:name", quota("session"), hs.OAuthLogin)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/login", hs.LoginView)
|
|
|
|
r.Get("/invite/:code", hs.Index)
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed views
|
2020-11-10 16:36:35 -06:00
|
|
|
r.Get("/", reqSignedIn, hs.Index)
|
2021-02-27 11:04:28 -06:00
|
|
|
r.Get("/profile/", reqSignedInNoAnonymous, hs.Index)
|
|
|
|
r.Get("/profile/password", reqSignedInNoAnonymous, hs.Index)
|
2020-11-10 16:36:35 -06:00
|
|
|
r.Get("/.well-known/change-password", redirectToChangePassword)
|
2021-02-27 11:04:28 -06:00
|
|
|
r.Get("/profile/switch-org/:id", reqSignedInNoAnonymous, hs.ChangeActiveOrgAndRedirectToHome)
|
2019-03-04 08:51:18 -06:00
|
|
|
r.Get("/org/", reqOrgAdmin, hs.Index)
|
|
|
|
r.Get("/org/new", reqGrafanaAdmin, hs.Index)
|
|
|
|
r.Get("/datasources/", reqOrgAdmin, hs.Index)
|
|
|
|
r.Get("/datasources/new", reqOrgAdmin, hs.Index)
|
|
|
|
r.Get("/datasources/edit/*", reqOrgAdmin, hs.Index)
|
2021-05-03 03:27:12 -05:00
|
|
|
r.Get("/org/users", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersRead, accesscontrol.ScopeUsersAll), hs.Index)
|
2019-03-04 08:51:18 -06:00
|
|
|
r.Get("/org/users/new", reqOrgAdmin, hs.Index)
|
2021-04-22 08:15:57 -05:00
|
|
|
r.Get("/org/users/invite", authorize(reqOrgAdmin, accesscontrol.ActionUsersCreate), hs.Index)
|
2019-03-14 04:02:46 -05:00
|
|
|
r.Get("/org/teams", reqCanAccessTeams, hs.Index)
|
|
|
|
r.Get("/org/teams/*", reqCanAccessTeams, hs.Index)
|
2019-03-04 08:51:18 -06:00
|
|
|
r.Get("/org/apikeys/", reqOrgAdmin, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/dashboard/import/", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/configuration", reqGrafanaAdmin, hs.Index)
|
|
|
|
r.Get("/admin", reqGrafanaAdmin, hs.Index)
|
2021-06-14 10:36:48 -05:00
|
|
|
r.Get("/admin/settings", authorize(reqGrafanaAdmin, accesscontrol.ActionSettingsRead), hs.Index)
|
2021-05-03 03:27:12 -05:00
|
|
|
r.Get("/admin/users", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, accesscontrol.ScopeGlobalUsersAll), hs.Index)
|
2021-04-22 05:19:41 -05:00
|
|
|
r.Get("/admin/users/create", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersCreate), hs.Index)
|
|
|
|
r.Get("/admin/users/edit/:id", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead), hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/admin/orgs", reqGrafanaAdmin, hs.Index)
|
|
|
|
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, hs.Index)
|
2021-06-14 10:36:48 -05:00
|
|
|
r.Get("/admin/stats", authorize(reqGrafanaAdmin, accesscontrol.ActionServerStatsRead), hs.Index)
|
2021-04-22 05:19:41 -05:00
|
|
|
r.Get("/admin/ldap", authorize(reqGrafanaAdmin, accesscontrol.ActionLDAPStatusRead), hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
|
|
|
|
r.Get("/styleguide", reqSignedIn, hs.Index)
|
|
|
|
|
|
|
|
r.Get("/plugins", reqSignedIn, hs.Index)
|
2019-05-02 12:15:39 -05:00
|
|
|
r.Get("/plugins/:id/", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/plugins/:id/edit", reqSignedIn, hs.Index) // deprecated
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/plugins/:id/page/:page", reqSignedIn, hs.Index)
|
2019-05-02 12:15:39 -05:00
|
|
|
r.Get("/a/:id/*", reqSignedIn, hs.Index) // App Root Page
|
2018-10-09 10:47:43 -05:00
|
|
|
|
2020-06-17 05:51:41 -05:00
|
|
|
r.Get("/d/:uid/:slug", reqSignedIn, redirectFromLegacyPanelEditURL, hs.Index)
|
|
|
|
r.Get("/d/:uid", reqSignedIn, redirectFromLegacyPanelEditURL, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/dashboard/script/*", reqSignedIn, hs.Index)
|
2020-11-10 16:36:35 -06:00
|
|
|
r.Get("/dashboard/new", reqSignedIn, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/dashboard-solo/snapshot/*", hs.Index)
|
|
|
|
r.Get("/d-solo/:uid/:slug", reqSignedIn, hs.Index)
|
2019-10-14 11:21:44 -05:00
|
|
|
r.Get("/d-solo/:uid", reqSignedIn, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/dashboard-solo/script/*", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/import/dashboard", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/dashboards/", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/dashboards/*", reqSignedIn, hs.Index)
|
2020-10-14 05:48:48 -05:00
|
|
|
r.Get("/goto/:uid", reqSignedIn, hs.redirectFromShortURL, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
|
2021-07-02 07:43:12 -05:00
|
|
|
r.Get("/explore", authorize(func(c *models.ReqContext) {
|
|
|
|
if f, ok := reqSignedIn.(func(c *models.ReqContext)); ok {
|
|
|
|
f(c)
|
|
|
|
}
|
|
|
|
middleware.EnsureEditorOrViewerCanEdit(c)
|
|
|
|
}, accesscontrol.ActionDatasourcesExplore), hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
|
|
|
|
r.Get("/playlists/", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/playlists/*", reqSignedIn, hs.Index)
|
2021-05-17 03:15:17 -05:00
|
|
|
r.Get("/alerting/", reqSignedIn, hs.Index)
|
|
|
|
r.Get("/alerting/*", reqSignedIn, hs.Index)
|
2015-12-22 04:07:15 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// sign up
|
2020-09-07 10:24:46 -05:00
|
|
|
r.Get("/verify", hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/signup", hs.Index)
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Get("/api/user/signup/options", routing.Wrap(GetSignUpOptions))
|
|
|
|
r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), routing.Wrap(SignUp))
|
|
|
|
r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), routing.Wrap(hs.SignUpStep2))
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-07-20 08:52:49 -05:00
|
|
|
// invited
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Get("/api/user/invite/:code", routing.Wrap(GetInviteInfoByCode))
|
|
|
|
r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), routing.Wrap(hs.CompleteInvite))
|
2015-07-20 08:52:49 -05:00
|
|
|
|
2015-06-08 03:57:01 -05:00
|
|
|
// reset password
|
2021-06-14 11:02:05 -05:00
|
|
|
r.Get("/user/password/send-reset-email", reqNotSignedIn, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/user/password/reset", hs.Index)
|
2015-06-08 03:57:01 -05:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), routing.Wrap(SendResetPasswordEmail))
|
|
|
|
r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), routing.Wrap(ResetPassword))
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2015-03-21 07:53:16 -05:00
|
|
|
// dashboard snapshots
|
2021-03-16 10:46:34 -05:00
|
|
|
r.Get("/dashboard/snapshot/*", reqNoAuth, hs.Index)
|
2018-10-09 10:47:43 -05:00
|
|
|
r.Get("/dashboard/snapshots/", reqSignedIn, hs.Index)
|
2015-03-26 14:34:58 -05:00
|
|
|
|
2019-02-04 10:37:07 -06:00
|
|
|
// api renew session based on cookie
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Get("/api/login/ping", quota("session"), routing.Wrap(hs.LoginAPIPing))
|
2015-04-07 02:25:00 -05:00
|
|
|
|
2021-04-21 08:17:23 -05:00
|
|
|
// expose plugin file system assets
|
|
|
|
r.Get("/public/plugins/:pluginId/*", hs.GetPluginAssets)
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// authed api
|
2018-06-25 09:36:47 -05:00
|
|
|
r.Group("/api", func(apiRoute routing.RouteRegister) {
|
2015-05-19 04:47:14 -05:00
|
|
|
// user (signed in)
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/user", func(userRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
userRoute.Get("/", routing.Wrap(GetSignedInUser))
|
|
|
|
userRoute.Put("/", bind(models.UpdateUserCommand{}), routing.Wrap(UpdateSignedInUser))
|
|
|
|
userRoute.Post("/using/:id", routing.Wrap(UserSetUsingOrg))
|
|
|
|
userRoute.Get("/orgs", routing.Wrap(GetSignedInUserOrgList))
|
|
|
|
userRoute.Get("/teams", routing.Wrap(GetSignedInUserTeamList))
|
|
|
|
|
|
|
|
userRoute.Post("/stars/dashboard/:id", routing.Wrap(StarDashboard))
|
|
|
|
userRoute.Delete("/stars/dashboard/:id", routing.Wrap(UnstarDashboard))
|
|
|
|
|
|
|
|
userRoute.Put("/password", bind(models.ChangeUserPasswordCommand{}), routing.Wrap(ChangeUserPassword))
|
|
|
|
userRoute.Get("/quotas", routing.Wrap(GetUserQuotas))
|
|
|
|
userRoute.Put("/helpflags/:id", routing.Wrap(SetHelpFlag))
|
2016-11-09 03:41:39 -06:00
|
|
|
// For dev purpose
|
2021-01-15 07:43:20 -06:00
|
|
|
userRoute.Get("/helpflags/clear", routing.Wrap(ClearHelpFlags))
|
2016-04-02 15:54:06 -05:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
userRoute.Get("/preferences", routing.Wrap(GetUserPreferences))
|
|
|
|
userRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), routing.Wrap(UpdateUserPreferences))
|
2019-03-08 08:15:38 -06:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
userRoute.Get("/auth-tokens", routing.Wrap(hs.GetUserAuthTokens))
|
|
|
|
userRoute.Post("/revoke-auth-token", bind(models.RevokeAuthTokenCmd{}), routing.Wrap(hs.RevokeUserAuthToken))
|
2021-02-27 11:04:28 -06:00
|
|
|
}, reqSignedInNoAnonymous)
|
2015-01-19 11:01:04 -06:00
|
|
|
|
2015-05-19 04:47:14 -05:00
|
|
|
// users (admin permission required)
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/users", func(usersRoute routing.RouteRegister) {
|
2021-05-11 13:04:29 -05:00
|
|
|
const userIDScope = `global:users:{{ index . ":id" }}`
|
2021-05-03 03:27:12 -05:00
|
|
|
usersRoute.Get("/", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, accesscontrol.ScopeGlobalUsersAll), routing.Wrap(SearchUsers))
|
|
|
|
usersRoute.Get("/search", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, accesscontrol.ScopeGlobalUsersAll), routing.Wrap(SearchUsersWithPaging))
|
2021-04-14 09:31:27 -05:00
|
|
|
usersRoute.Get("/:id", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, userIDScope), routing.Wrap(GetUserByID))
|
|
|
|
usersRoute.Get("/:id/teams", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersTeamRead, userIDScope), routing.Wrap(GetUserTeams))
|
|
|
|
usersRoute.Get("/:id/orgs", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, userIDScope), routing.Wrap(GetUserOrgList))
|
2017-01-30 23:25:55 -06:00
|
|
|
// query parameters /users/lookup?loginOrEmail=admin@example.com
|
2021-05-03 03:27:12 -05:00
|
|
|
usersRoute.Get("/lookup", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersRead, accesscontrol.ScopeGlobalUsersAll), routing.Wrap(GetUserByLoginOrEmail))
|
2021-04-14 09:31:27 -05:00
|
|
|
usersRoute.Put("/:id", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersWrite, userIDScope), bind(models.UpdateUserCommand{}), routing.Wrap(UpdateUser))
|
|
|
|
usersRoute.Post("/:id/using/:orgId", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersWrite, userIDScope), routing.Wrap(UpdateUserActiveOrg))
|
|
|
|
})
|
2015-05-18 10:28:15 -05:00
|
|
|
|
2017-12-08 09:25:45 -06:00
|
|
|
// team (admin permission required)
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
teamsRoute.Post("/", bind(models.CreateTeamCommand{}), routing.Wrap(hs.CreateTeam))
|
|
|
|
teamsRoute.Put("/:teamId", bind(models.UpdateTeamCommand{}), routing.Wrap(hs.UpdateTeam))
|
|
|
|
teamsRoute.Delete("/:teamId", routing.Wrap(hs.DeleteTeamByID))
|
|
|
|
teamsRoute.Get("/:teamId/members", routing.Wrap(hs.GetTeamMembers))
|
|
|
|
teamsRoute.Post("/:teamId/members", bind(models.AddTeamMemberCommand{}), routing.Wrap(hs.AddTeamMember))
|
|
|
|
teamsRoute.Put("/:teamId/members/:userId", bind(models.UpdateTeamMemberCommand{}), routing.Wrap(hs.UpdateTeamMember))
|
|
|
|
teamsRoute.Delete("/:teamId/members/:userId", routing.Wrap(hs.RemoveTeamMember))
|
|
|
|
teamsRoute.Get("/:teamId/preferences", routing.Wrap(hs.GetTeamPreferences))
|
|
|
|
teamsRoute.Put("/:teamId/preferences", bind(dtos.UpdatePrefsCmd{}), routing.Wrap(hs.UpdateTeamPreferences))
|
2019-03-14 04:02:46 -05:00
|
|
|
}, reqCanAccessTeams)
|
2017-04-09 18:24:16 -05:00
|
|
|
|
2018-04-06 07:08:23 -05:00
|
|
|
// team without requirement of user to be org admin
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
teamsRoute.Get("/:teamId", routing.Wrap(hs.GetTeamByID))
|
|
|
|
teamsRoute.Get("/search", routing.Wrap(hs.SearchTeams))
|
2018-04-06 07:08:23 -05:00
|
|
|
})
|
|
|
|
|
2015-09-10 12:18:36 -05:00
|
|
|
// org information available to all users.
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
orgRoute.Get("/", routing.Wrap(GetOrgCurrent))
|
|
|
|
orgRoute.Get("/quotas", routing.Wrap(GetOrgQuotas))
|
2015-09-10 12:18:36 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
// current org
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
|
2021-05-05 09:52:21 -05:00
|
|
|
const usersScope = `users:{{ index . ":userId" }}`
|
2021-04-22 05:19:41 -05:00
|
|
|
orgRoute.Put("/", reqOrgAdmin, bind(dtos.UpdateOrgForm{}), routing.Wrap(UpdateOrgCurrent))
|
|
|
|
orgRoute.Put("/address", reqOrgAdmin, bind(dtos.UpdateOrgAddressForm{}), routing.Wrap(UpdateOrgAddressCurrent))
|
2021-05-03 03:27:12 -05:00
|
|
|
orgRoute.Get("/users", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersRead, accesscontrol.ScopeUsersAll), routing.Wrap(hs.GetOrgUsersForCurrentOrg))
|
2021-05-12 07:10:35 -05:00
|
|
|
orgRoute.Get("/users/search", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersRead, accesscontrol.ScopeUsersAll), routing.Wrap(hs.SearchOrgUsersWithPaging))
|
2021-05-03 03:27:12 -05:00
|
|
|
orgRoute.Post("/users", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersAdd, accesscontrol.ScopeUsersAll), quota("user"), bind(models.AddOrgUserCommand{}), routing.Wrap(AddOrgUserToCurrentOrg))
|
2021-05-05 09:52:21 -05:00
|
|
|
orgRoute.Patch("/users/:userId", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersRoleUpdate, usersScope), bind(models.UpdateOrgUserCommand{}), routing.Wrap(UpdateOrgUserForCurrentOrg))
|
|
|
|
orgRoute.Delete("/users/:userId", authorize(reqOrgAdmin, accesscontrol.ActionOrgUsersRemove, usersScope), routing.Wrap(RemoveOrgUserForCurrentOrg))
|
2015-07-17 02:51:34 -05:00
|
|
|
|
|
|
|
// invites
|
2021-04-22 08:15:57 -05:00
|
|
|
orgRoute.Get("/invites", authorize(reqOrgAdmin, accesscontrol.ActionUsersCreate), routing.Wrap(GetPendingOrgInvites))
|
|
|
|
orgRoute.Post("/invites", authorize(reqOrgAdmin, accesscontrol.ActionUsersCreate), quota("user"), bind(dtos.AddInviteForm{}), routing.Wrap(AddOrgInvite))
|
|
|
|
orgRoute.Patch("/invites/:code/revoke", authorize(reqOrgAdmin, accesscontrol.ActionUsersCreate), routing.Wrap(RevokeInvite))
|
2015-12-17 23:46:40 -06:00
|
|
|
|
2016-04-02 15:54:06 -05:00
|
|
|
// prefs
|
2021-04-22 05:19:41 -05:00
|
|
|
orgRoute.Get("/preferences", reqOrgAdmin, routing.Wrap(GetOrgPreferences))
|
|
|
|
orgRoute.Put("/preferences", reqOrgAdmin, bind(dtos.UpdatePrefsCmd{}), routing.Wrap(UpdateOrgPreferences))
|
|
|
|
})
|
2015-05-19 03:16:32 -05:00
|
|
|
|
2018-04-06 07:08:23 -05:00
|
|
|
// current org without requirement of user to be org admin
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
orgRoute.Get("/users/lookup", routing.Wrap(hs.GetOrgUsersForCurrentOrgLookup))
|
2018-04-06 07:08:23 -05:00
|
|
|
})
|
|
|
|
|
2015-05-19 03:16:32 -05:00
|
|
|
// create new org
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Post("/orgs", quota("org"), bind(models.CreateOrgCommand{}), routing.Wrap(CreateOrg))
|
2015-05-19 03:16:32 -05:00
|
|
|
|
2015-05-19 04:47:14 -05:00
|
|
|
// search all orgs
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/orgs", reqGrafanaAdmin, routing.Wrap(SearchOrgs))
|
2015-05-19 04:47:14 -05:00
|
|
|
|
2015-05-19 03:16:32 -05:00
|
|
|
// orgs (admin routes)
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/orgs/:orgId", func(orgsRoute routing.RouteRegister) {
|
2021-05-05 09:52:21 -05:00
|
|
|
const usersScope = `users:{{ index . ":userId" }}`
|
2021-04-22 05:19:41 -05:00
|
|
|
orgsRoute.Get("/", reqGrafanaAdmin, routing.Wrap(GetOrgByID))
|
|
|
|
orgsRoute.Put("/", reqGrafanaAdmin, bind(dtos.UpdateOrgForm{}), routing.Wrap(UpdateOrg))
|
|
|
|
orgsRoute.Put("/address", reqGrafanaAdmin, bind(dtos.UpdateOrgAddressForm{}), routing.Wrap(UpdateOrgAddress))
|
|
|
|
orgsRoute.Delete("/", reqGrafanaAdmin, routing.Wrap(DeleteOrgByID))
|
2021-05-05 09:52:21 -05:00
|
|
|
orgsRoute.Get("/users", authorize(reqGrafanaAdmin, accesscontrol.ActionOrgUsersRead, accesscontrol.ScopeUsersAll), routing.Wrap(hs.GetOrgUsers))
|
|
|
|
orgsRoute.Post("/users", authorize(reqGrafanaAdmin, accesscontrol.ActionOrgUsersAdd, accesscontrol.ScopeUsersAll), bind(models.AddOrgUserCommand{}), routing.Wrap(AddOrgUser))
|
|
|
|
orgsRoute.Patch("/users/:userId", authorize(reqGrafanaAdmin, accesscontrol.ActionOrgUsersRoleUpdate, usersScope), bind(models.UpdateOrgUserCommand{}), routing.Wrap(UpdateOrgUser))
|
|
|
|
orgsRoute.Delete("/users/:userId", authorize(reqGrafanaAdmin, accesscontrol.ActionOrgUsersRemove, usersScope), routing.Wrap(RemoveOrgUser))
|
2021-04-22 05:19:41 -05:00
|
|
|
orgsRoute.Get("/quotas", reqGrafanaAdmin, routing.Wrap(GetOrgQuotas))
|
|
|
|
orgsRoute.Put("/quotas/:target", reqGrafanaAdmin, bind(models.UpdateOrgQuotaCmd{}), routing.Wrap(UpdateOrgQuota))
|
|
|
|
})
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-01-12 15:50:56 -06:00
|
|
|
// orgs (admin routes)
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/orgs/name/:name", func(orgsRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
orgsRoute.Get("/", routing.Wrap(hs.GetOrgByName))
|
2016-01-12 15:50:56 -06:00
|
|
|
}, reqGrafanaAdmin)
|
|
|
|
|
2015-01-27 01:26:11 -06:00
|
|
|
// auth api keys
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/auth/keys", func(keysRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
keysRoute.Get("/", routing.Wrap(GetAPIKeys))
|
|
|
|
keysRoute.Post("/", quota("api_key"), bind(models.AddApiKeyCommand{}), routing.Wrap(hs.AddAPIKey))
|
|
|
|
keysRoute.Delete("/:id", routing.Wrap(DeleteAPIKey))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-03-17 01:35:06 -05:00
|
|
|
// Preferences
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/preferences", func(prefRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
prefRoute.Post("/set-home-dash", bind(models.SavePreferencesCommand{}), routing.Wrap(SetHomeDashboard))
|
2016-03-17 01:35:06 -05:00
|
|
|
})
|
2016-03-11 08:30:05 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Data sources
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
datasourceRoute.Get("/", routing.Wrap(hs.GetDataSources))
|
|
|
|
datasourceRoute.Post("/", quota("data_source"), bind(models.AddDataSourceCommand{}), routing.Wrap(AddDataSource))
|
2021-05-18 13:39:56 -05:00
|
|
|
datasourceRoute.Put("/:id", bind(models.UpdateDataSourceCommand{}), routing.Wrap(hs.UpdateDataSource))
|
|
|
|
datasourceRoute.Delete("/:id", routing.Wrap(hs.DeleteDataSourceById))
|
|
|
|
datasourceRoute.Delete("/uid/:uid", routing.Wrap(hs.DeleteDataSourceByUID))
|
|
|
|
datasourceRoute.Delete("/name/:name", routing.Wrap(hs.DeleteDataSourceByName))
|
2021-01-15 07:43:20 -06:00
|
|
|
datasourceRoute.Get("/:id", routing.Wrap(GetDataSourceById))
|
|
|
|
datasourceRoute.Get("/uid/:uid", routing.Wrap(GetDataSourceByUID))
|
|
|
|
datasourceRoute.Get("/name/:name", routing.Wrap(GetDataSourceByName))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/datasources/id/:name", routing.Wrap(GetDataSourceIdByName), reqSignedIn)
|
2016-03-07 14:25:26 -06:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/plugins", routing.Wrap(hs.GetPluginList))
|
2021-03-17 10:06:10 -05:00
|
|
|
apiRoute.Get("/plugins/:pluginId/settings", routing.Wrap(hs.GetPluginSettingByID))
|
2021-03-08 00:02:49 -06:00
|
|
|
apiRoute.Get("/plugins/:pluginId/markdown/:name", routing.Wrap(hs.GetPluginMarkdown))
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/plugins/:pluginId/health", routing.Wrap(hs.CheckHealth))
|
2020-03-03 04:45:16 -06:00
|
|
|
apiRoute.Any("/plugins/:pluginId/resources", hs.CallResource)
|
|
|
|
apiRoute.Any("/plugins/:pluginId/resources/*", hs.CallResource)
|
2021-05-12 13:05:16 -05:00
|
|
|
apiRoute.Get("/plugins/errors", routing.Wrap(hs.GetPluginErrorsList))
|
|
|
|
|
2021-05-20 03:42:26 -05:00
|
|
|
if hs.Cfg.PluginAdminEnabled {
|
2021-05-12 13:05:16 -05:00
|
|
|
apiRoute.Group("/plugins", func(pluginRoute routing.RouteRegister) {
|
|
|
|
pluginRoute.Post("/:pluginId/install", bind(dtos.InstallPluginCommand{}), routing.Wrap(hs.InstallPlugin))
|
|
|
|
pluginRoute.Post("/:pluginId/uninstall", routing.Wrap(hs.UninstallPlugin))
|
|
|
|
}, reqGrafanaAdmin)
|
|
|
|
}
|
2016-03-11 02:57:20 -06:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/plugins", func(pluginRoute routing.RouteRegister) {
|
2021-03-08 00:02:49 -06:00
|
|
|
pluginRoute.Get("/:pluginId/dashboards/", routing.Wrap(hs.GetPluginDashboards))
|
2021-03-18 07:53:01 -05:00
|
|
|
pluginRoute.Post("/:pluginId/settings", bind(models.UpdatePluginSettingCmd{}), routing.Wrap(hs.UpdatePluginSetting))
|
2021-01-15 07:43:20 -06:00
|
|
|
pluginRoute.Get("/:pluginId/metrics", routing.Wrap(hs.CollectPluginMetrics))
|
2015-12-03 09:43:55 -06:00
|
|
|
}, reqOrgAdmin)
|
|
|
|
|
2018-10-09 10:47:43 -05:00
|
|
|
apiRoute.Get("/frontend/settings/", hs.GetFrontendSettings)
|
2017-09-13 07:53:38 -05:00
|
|
|
apiRoute.Any("/datasources/proxy/:id/*", reqSignedIn, hs.ProxyDataSourceRequest)
|
|
|
|
apiRoute.Any("/datasources/proxy/:id", reqSignedIn, hs.ProxyDataSourceRequest)
|
2020-03-03 04:45:16 -06:00
|
|
|
apiRoute.Any("/datasources/:id/resources", hs.CallDatasourceResource)
|
|
|
|
apiRoute.Any("/datasources/:id/resources/*", hs.CallDatasourceResource)
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Any("/datasources/:id/health", routing.Wrap(hs.CheckDatasourceHealth))
|
2015-02-10 03:19:43 -06:00
|
|
|
|
2018-01-29 06:51:01 -06:00
|
|
|
// Folders
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/folders", func(folderRoute routing.RouteRegister) {
|
2021-03-17 10:06:10 -05:00
|
|
|
folderRoute.Get("/", routing.Wrap(hs.GetFolders))
|
|
|
|
folderRoute.Get("/id/:id", routing.Wrap(hs.GetFolderByID))
|
2021-01-15 07:43:20 -06:00
|
|
|
folderRoute.Post("/", bind(models.CreateFolderCommand{}), routing.Wrap(hs.CreateFolder))
|
2018-02-20 08:25:16 -06:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
folderRoute.Group("/:uid", func(folderUidRoute routing.RouteRegister) {
|
2021-03-17 10:06:10 -05:00
|
|
|
folderUidRoute.Get("/", routing.Wrap(hs.GetFolderByUID))
|
|
|
|
folderUidRoute.Put("/", bind(models.UpdateFolderCommand{}), routing.Wrap(hs.UpdateFolder))
|
2021-03-02 03:34:01 -06:00
|
|
|
folderUidRoute.Delete("/", routing.Wrap(hs.DeleteFolder))
|
2018-02-20 08:25:16 -06:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
folderUidRoute.Group("/permissions", func(folderPermissionRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
folderPermissionRoute.Get("/", routing.Wrap(hs.GetFolderPermissionList))
|
|
|
|
folderPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), routing.Wrap(hs.UpdateFolderPermissions))
|
2018-02-20 08:25:16 -06:00
|
|
|
})
|
|
|
|
})
|
2018-01-29 06:51:01 -06:00
|
|
|
})
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Dashboard
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/dashboards", func(dashboardRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
dashboardRoute.Get("/uid/:uid", routing.Wrap(hs.GetDashboard))
|
2021-01-20 02:28:10 -06:00
|
|
|
dashboardRoute.Delete("/uid/:uid", routing.Wrap(hs.DeleteDashboardByUID))
|
2018-01-29 14:23:07 -06:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
dashboardRoute.Post("/calculate-diff", bind(dtos.CalculateDiffOptions{}), routing.Wrap(CalculateDashboardDiff))
|
2021-04-28 06:38:33 -05:00
|
|
|
dashboardRoute.Post("/trim", bind(models.TrimDashboardCommand{}), routing.Wrap(hs.TrimDashboard))
|
2017-06-07 04:50:09 -05:00
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
dashboardRoute.Post("/db", bind(models.SaveDashboardCommand{}), routing.Wrap(hs.PostDashboard))
|
|
|
|
dashboardRoute.Get("/home", routing.Wrap(hs.GetHomeDashboard))
|
2017-09-13 07:53:38 -05:00
|
|
|
dashboardRoute.Get("/tags", GetDashboardTags)
|
2021-03-08 00:02:49 -06:00
|
|
|
dashboardRoute.Post("/import", bind(dtos.ImportDashboardCommand{}), routing.Wrap(hs.ImportDashboard))
|
2017-10-12 10:38:49 -05:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
dashIdRoute.Get("/versions", routing.Wrap(GetDashboardVersions))
|
|
|
|
dashIdRoute.Get("/versions/:id", routing.Wrap(GetDashboardVersion))
|
|
|
|
dashIdRoute.Post("/restore", bind(dtos.RestoreDashboardVersionCommand{}), routing.Wrap(hs.RestoreDashboardVersion))
|
2017-10-12 10:38:49 -05:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
dashIdRoute.Group("/permissions", func(dashboardPermissionRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
dashboardPermissionRoute.Get("/", routing.Wrap(hs.GetDashboardPermissionList))
|
|
|
|
dashboardPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), routing.Wrap(hs.UpdateDashboardPermissions))
|
2017-10-12 10:38:49 -05:00
|
|
|
})
|
|
|
|
})
|
2015-01-14 07:25:12 -06:00
|
|
|
})
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2016-01-19 07:05:24 -06:00
|
|
|
// Dashboard snapshots
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/dashboard/snapshots", func(dashboardRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
dashboardRoute.Get("/", routing.Wrap(SearchDashboardSnapshots))
|
2016-01-19 07:05:24 -06:00
|
|
|
})
|
2016-01-19 03:37:36 -06:00
|
|
|
|
2015-12-22 04:07:15 -06:00
|
|
|
// Playlist
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/playlists", func(playlistRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
playlistRoute.Get("/", routing.Wrap(SearchPlaylists))
|
|
|
|
playlistRoute.Get("/:id", ValidateOrgPlaylist, routing.Wrap(GetPlaylist))
|
|
|
|
playlistRoute.Get("/:id/items", ValidateOrgPlaylist, routing.Wrap(GetPlaylistItems))
|
|
|
|
playlistRoute.Get("/:id/dashboards", ValidateOrgPlaylist, routing.Wrap(GetPlaylistDashboards))
|
|
|
|
playlistRoute.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, routing.Wrap(DeletePlaylist))
|
|
|
|
playlistRoute.Put("/:id", reqEditorRole, bind(models.UpdatePlaylistCommand{}), ValidateOrgPlaylist, routing.Wrap(UpdatePlaylist))
|
|
|
|
playlistRoute.Post("/", reqEditorRole, bind(models.CreatePlaylistCommand{}), routing.Wrap(CreatePlaylist))
|
2015-12-22 04:07:15 -06:00
|
|
|
})
|
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// Search
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/search/sorting", routing.Wrap(hs.ListSortOptions))
|
|
|
|
apiRoute.Get("/search/", routing.Wrap(Search))
|
2015-01-26 13:26:17 -06:00
|
|
|
|
2015-01-14 07:25:12 -06:00
|
|
|
// metrics
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), routing.Wrap(hs.QueryMetrics))
|
|
|
|
apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, routing.Wrap(GenerateSQLTestData))
|
2021-03-08 00:02:49 -06:00
|
|
|
apiRoute.Get("/tsdb/testdata/random-walk", routing.Wrap(hs.GetTestDataRandomWalk))
|
2017-09-13 07:53:38 -05:00
|
|
|
|
2019-10-31 18:22:00 -05:00
|
|
|
// DataSource w/ expressions
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Post("/ds/query", bind(dtos.MetricRequest{}), routing.Wrap(hs.QueryMetricsV2))
|
2019-10-31 18:22:00 -05:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
|
2021-03-08 00:02:49 -06:00
|
|
|
alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), routing.Wrap(hs.AlertTest))
|
2021-01-15 07:43:20 -06:00
|
|
|
alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), routing.Wrap(PauseAlert))
|
|
|
|
alertsRoute.Get("/:alertId", ValidateOrgAlert, routing.Wrap(GetAlert))
|
|
|
|
alertsRoute.Get("/", routing.Wrap(GetAlerts))
|
|
|
|
alertsRoute.Get("/states-for-dashboard", routing.Wrap(GetAlertStatesForDashboard))
|
2016-04-26 10:36:50 -05:00
|
|
|
})
|
|
|
|
|
2021-05-04 06:58:39 -05:00
|
|
|
apiRoute.Get("/alert-notifiers", reqEditorRole, routing.Wrap(
|
2021-05-13 13:01:38 -05:00
|
|
|
GetAlertNotifiers(hs.Alertmanager != nil && hs.Cfg.IsNgAlertEnabled())),
|
2021-05-04 06:58:39 -05:00
|
|
|
)
|
2016-07-14 06:32:16 -05:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/alert-notifications", func(alertNotifications routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
alertNotifications.Get("/", routing.Wrap(GetAlertNotifications))
|
|
|
|
alertNotifications.Post("/test", bind(dtos.NotificationTestCommand{}), routing.Wrap(NotificationTest))
|
|
|
|
alertNotifications.Post("/", bind(models.CreateAlertNotificationCommand{}), routing.Wrap(CreateAlertNotification))
|
|
|
|
alertNotifications.Put("/:notificationId", bind(models.UpdateAlertNotificationCommand{}), routing.Wrap(UpdateAlertNotification))
|
|
|
|
alertNotifications.Get("/:notificationId", routing.Wrap(GetAlertNotificationByID))
|
|
|
|
alertNotifications.Delete("/:notificationId", routing.Wrap(DeleteAlertNotification))
|
|
|
|
alertNotifications.Get("/uid/:uid", routing.Wrap(GetAlertNotificationByUID))
|
|
|
|
alertNotifications.Put("/uid/:uid", bind(models.UpdateAlertNotificationWithUidCommand{}), routing.Wrap(UpdateAlertNotificationByUID))
|
|
|
|
alertNotifications.Delete("/uid/:uid", routing.Wrap(DeleteAlertNotificationByUID))
|
2016-10-19 01:01:14 -05:00
|
|
|
}, reqEditorRole)
|
2016-07-14 06:32:16 -05:00
|
|
|
|
2019-08-12 13:03:48 -05:00
|
|
|
// alert notifications without requirement of user to be org editor
|
|
|
|
apiRoute.Group("/alert-notifications", func(orgRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
orgRoute.Get("/lookup", routing.Wrap(GetAlertNotificationLookup))
|
2019-08-12 13:03:48 -05:00
|
|
|
})
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Get("/annotations", routing.Wrap(GetAnnotations))
|
|
|
|
apiRoute.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), routing.Wrap(DeleteAnnotations))
|
2017-04-12 08:46:41 -05:00
|
|
|
|
2018-06-25 09:36:47 -05:00
|
|
|
apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) {
|
2021-01-15 07:43:20 -06:00
|
|
|
annotationsRoute.Post("/", bind(dtos.PostAnnotationsCmd{}), routing.Wrap(PostAnnotation))
|
|
|
|
annotationsRoute.Delete("/:annotationId", routing.Wrap(DeleteAnnotationByID))
|
|
|
|
annotationsRoute.Put("/:annotationId", bind(dtos.UpdateAnnotationsCmd{}), routing.Wrap(UpdateAnnotation))
|
|
|
|
annotationsRoute.Patch("/:annotationId", bind(dtos.PatchAnnotationsCmd{}), routing.Wrap(PatchAnnotation))
|
|
|
|
annotationsRoute.Post("/graphite", reqEditorRole, bind(dtos.PostGraphiteAnnotationsCmd{}), routing.Wrap(PostGraphiteAnnotation))
|
2021-06-30 06:42:54 -05:00
|
|
|
annotationsRoute.Get("/tags", routing.Wrap(GetAnnotationTags))
|
2017-12-20 17:52:21 -06:00
|
|
|
})
|
2016-09-08 04:25:45 -05:00
|
|
|
|
2021-04-01 13:04:02 -05:00
|
|
|
apiRoute.Post("/frontend-metrics", bind(metrics.PostFrontendMetricsCommand{}), routing.Wrap(hs.PostFrontendMetrics))
|
|
|
|
|
2021-05-04 10:44:55 -05:00
|
|
|
apiRoute.Group("/live", func(liveRoute routing.RouteRegister) {
|
|
|
|
// the channel path is in the name
|
|
|
|
liveRoute.Post("/publish", bind(dtos.LivePublishCmd{}), routing.Wrap(hs.Live.HandleHTTPPublish))
|
2021-04-05 11:04:46 -05:00
|
|
|
|
2021-05-04 10:44:55 -05:00
|
|
|
// POST influx line protocol
|
|
|
|
liveRoute.Post("/push/:streamId", hs.LivePushGateway.Handle)
|
2021-04-05 11:04:46 -05:00
|
|
|
|
2021-05-04 10:44:55 -05:00
|
|
|
// List available streams and fields
|
|
|
|
liveRoute.Get("/list", routing.Wrap(hs.Live.HandleListHTTP))
|
2021-04-23 14:55:31 -05:00
|
|
|
|
2021-05-04 10:44:55 -05:00
|
|
|
// Some channels may have info
|
|
|
|
liveRoute.Get("/info/*", routing.Wrap(hs.Live.HandleInfoHTTP))
|
|
|
|
})
|
2021-03-30 05:23:29 -05:00
|
|
|
|
2020-10-14 05:48:48 -05:00
|
|
|
// short urls
|
2021-01-15 07:43:20 -06:00
|
|
|
apiRoute.Post("/short-urls", bind(dtos.CreateShortURLCmd{}), routing.Wrap(hs.createShortURL))
|
2015-01-15 05:16:54 -06:00
|
|
|
}, reqSignedIn)
|
|
|
|
|
|
|
|
// admin api
|
2018-06-25 09:36:47 -05:00
|
|
|
r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
|
2021-06-14 10:36:48 -05:00
|
|
|
adminRoute.Get("/settings", authorize(reqGrafanaAdmin, accesscontrol.ActionSettingsRead), routing.Wrap(hs.AdminGetSettings))
|
|
|
|
adminRoute.Get("/stats", authorize(reqGrafanaAdmin, accesscontrol.ActionServerStatsRead), routing.Wrap(AdminGetStats))
|
2021-04-22 05:19:41 -05:00
|
|
|
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, bind(dtos.PauseAllAlertsCommand{}), routing.Wrap(PauseAllAlerts))
|
|
|
|
|
|
|
|
adminRoute.Post("/provisioning/dashboards/reload", reqGrafanaAdmin, routing.Wrap(hs.AdminProvisioningReloadDashboards))
|
|
|
|
adminRoute.Post("/provisioning/plugins/reload", reqGrafanaAdmin, routing.Wrap(hs.AdminProvisioningReloadPlugins))
|
|
|
|
adminRoute.Post("/provisioning/datasources/reload", reqGrafanaAdmin, routing.Wrap(hs.AdminProvisioningReloadDatasources))
|
|
|
|
adminRoute.Post("/provisioning/notifications/reload", reqGrafanaAdmin, routing.Wrap(hs.AdminProvisioningReloadNotifications))
|
2021-06-11 08:58:18 -05:00
|
|
|
adminRoute.Post("/ldap/reload", authorize(reqGrafanaAdmin, accesscontrol.ActionLDAPConfigReload), routing.Wrap(hs.ReloadLDAPCfg))
|
2021-04-22 05:19:41 -05:00
|
|
|
adminRoute.Post("/ldap/sync/:id", authorize(reqGrafanaAdmin, accesscontrol.ActionLDAPUsersSync), routing.Wrap(hs.PostSyncUserWithLDAP))
|
|
|
|
adminRoute.Get("/ldap/:username", authorize(reqGrafanaAdmin, accesscontrol.ActionLDAPUsersRead), routing.Wrap(hs.GetUserFromLDAP))
|
|
|
|
adminRoute.Get("/ldap/status", authorize(reqGrafanaAdmin, accesscontrol.ActionLDAPStatusRead), routing.Wrap(hs.GetLDAPStatus))
|
|
|
|
})
|
2014-12-15 14:25:02 -06:00
|
|
|
|
2021-04-14 09:31:27 -05:00
|
|
|
// Administering users
|
|
|
|
r.Group("/api/admin/users", func(adminUserRoute routing.RouteRegister) {
|
2021-05-05 09:52:21 -05:00
|
|
|
const userIDScope = `global:users:{{ index . ":id" }}`
|
2021-04-14 09:31:27 -05:00
|
|
|
adminUserRoute.Post("/", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersCreate), bind(dtos.AdminCreateUserForm{}), routing.Wrap(hs.AdminCreateUser))
|
|
|
|
adminUserRoute.Put("/:id/password", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersPasswordUpdate, userIDScope), bind(dtos.AdminUpdateUserPasswordForm{}), routing.Wrap(AdminUpdateUserPassword))
|
|
|
|
adminUserRoute.Put("/:id/permissions", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersPermissionsUpdate, userIDScope), bind(dtos.AdminUpdateUserPermissionsForm{}), routing.Wrap(hs.AdminUpdateUserPermissions))
|
|
|
|
adminUserRoute.Delete("/:id", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersDelete, userIDScope), routing.Wrap(AdminDeleteUser))
|
|
|
|
adminUserRoute.Post("/:id/disable", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersDisable, userIDScope), routing.Wrap(hs.AdminDisableUser))
|
|
|
|
adminUserRoute.Post("/:id/enable", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersEnable, userIDScope), routing.Wrap(AdminEnableUser))
|
|
|
|
adminUserRoute.Get("/:id/quotas", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersQuotasList, userIDScope), routing.Wrap(GetUserQuotas))
|
|
|
|
adminUserRoute.Put("/:id/quotas/:target", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersQuotasUpdate, userIDScope), bind(models.UpdateUserQuotaCmd{}), routing.Wrap(UpdateUserQuota))
|
|
|
|
|
|
|
|
adminUserRoute.Post("/:id/logout", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersLogout, userIDScope), routing.Wrap(hs.AdminLogoutUser))
|
|
|
|
adminUserRoute.Get("/:id/auth-tokens", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersAuthTokenList, userIDScope), routing.Wrap(hs.AdminGetUserAuthTokens))
|
|
|
|
adminUserRoute.Post("/:id/revoke-auth-token", authorize(reqGrafanaAdmin, accesscontrol.ActionUsersAuthTokenUpdate, userIDScope), bind(models.RevokeAuthTokenCmd{}), routing.Wrap(hs.AdminRevokeUserAuthToken))
|
|
|
|
})
|
|
|
|
|
2014-12-15 14:25:02 -06:00
|
|
|
// rendering
|
2018-05-24 08:26:27 -05:00
|
|
|
r.Get("/render/*", reqSignedIn, hs.RenderToPng)
|
2015-01-06 02:11:00 -06:00
|
|
|
|
2016-04-08 15:42:33 -05:00
|
|
|
// grafana.net proxy
|
|
|
|
r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
|
|
|
|
|
2016-02-20 16:51:22 -06:00
|
|
|
// Gravatar service.
|
2021-03-10 05:41:29 -06:00
|
|
|
avatarCacheServer := avatar.NewCacheServer(hs.Cfg)
|
2017-11-17 06:13:58 -06:00
|
|
|
r.Get("/avatar/:hash", avatarCacheServer.Handler)
|
2016-02-20 16:51:22 -06:00
|
|
|
|
2019-09-02 08:15:46 -05:00
|
|
|
// Snapshots
|
|
|
|
r.Post("/api/snapshots/", reqSnapshotPublicModeOrSignedIn, bind(models.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
|
|
|
r.Get("/api/snapshot/shared-options/", reqSignedIn, GetSharingOptions)
|
2021-01-15 07:43:20 -06:00
|
|
|
r.Get("/api/snapshots/:key", routing.Wrap(GetDashboardSnapshot))
|
|
|
|
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, routing.Wrap(DeleteDashboardSnapshotByDeleteKey))
|
|
|
|
r.Delete("/api/snapshots/:key", reqEditorRole, routing.Wrap(DeleteDashboardSnapshot))
|
2020-11-12 05:29:43 -06:00
|
|
|
|
|
|
|
// Frontend logs
|
2021-03-18 07:53:01 -05:00
|
|
|
sourceMapStore := frontendlogging.NewSourceMapStore(hs.Cfg, hs.PluginManager, frontendlogging.ReadSourceMapFromFS)
|
|
|
|
r.Post("/log", middleware.RateLimit(hs.Cfg.Sentry.EndpointRPS, hs.Cfg.Sentry.EndpointBurst, time.Now),
|
|
|
|
bind(frontendlogging.FrontendSentryEvent{}), routing.Wrap(NewFrontendLogMessageHandler(sourceMapStore)))
|
2014-12-15 14:25:02 -06:00
|
|
|
}
|