api.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package api
  2. import (
  3. "github.com/go-macaron/binding"
  4. "github.com/grafana/grafana/pkg/api/avatar"
  5. "github.com/grafana/grafana/pkg/api/dtos"
  6. "github.com/grafana/grafana/pkg/api/routing"
  7. "github.com/grafana/grafana/pkg/middleware"
  8. m "github.com/grafana/grafana/pkg/models"
  9. )
  10. func (hs *HTTPServer) registerRoutes() {
  11. reqSignedIn := middleware.ReqSignedIn
  12. reqGrafanaAdmin := middleware.ReqGrafanaAdmin
  13. reqEditorRole := middleware.ReqEditorRole
  14. reqOrgAdmin := middleware.ReqOrgAdmin
  15. redirectFromLegacyDashboardURL := middleware.RedirectFromLegacyDashboardURL()
  16. redirectFromLegacyDashboardSoloURL := middleware.RedirectFromLegacyDashboardSoloURL()
  17. quota := middleware.Quota(hs.QuotaService)
  18. bind := binding.Bind
  19. r := hs.RouteRegister
  20. // not logged in views
  21. r.Get("/", reqSignedIn, hs.Index)
  22. r.Get("/logout", hs.Logout)
  23. r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), Wrap(hs.LoginPost))
  24. r.Get("/login/:name", quota("session"), hs.OAuthLogin)
  25. r.Get("/login", hs.LoginView)
  26. r.Get("/invite/:code", hs.Index)
  27. // authed views
  28. r.Get("/profile/", reqSignedIn, hs.Index)
  29. r.Get("/profile/password", reqSignedIn, hs.Index)
  30. r.Get("/profile/switch-org/:id", reqSignedIn, hs.ChangeActiveOrgAndRedirectToHome)
  31. r.Get("/org/", reqSignedIn, hs.Index)
  32. r.Get("/org/new", reqSignedIn, hs.Index)
  33. r.Get("/datasources/", reqSignedIn, hs.Index)
  34. r.Get("/datasources/new", reqSignedIn, hs.Index)
  35. r.Get("/datasources/edit/*", reqSignedIn, hs.Index)
  36. r.Get("/org/users", reqSignedIn, hs.Index)
  37. r.Get("/org/users/new", reqSignedIn, hs.Index)
  38. r.Get("/org/users/invite", reqSignedIn, hs.Index)
  39. r.Get("/org/teams", reqSignedIn, hs.Index)
  40. r.Get("/org/teams/*", reqSignedIn, hs.Index)
  41. r.Get("/org/apikeys/", reqSignedIn, hs.Index)
  42. r.Get("/dashboard/import/", reqSignedIn, hs.Index)
  43. r.Get("/configuration", reqGrafanaAdmin, hs.Index)
  44. r.Get("/admin", reqGrafanaAdmin, hs.Index)
  45. r.Get("/admin/settings", reqGrafanaAdmin, hs.Index)
  46. r.Get("/admin/users", reqGrafanaAdmin, hs.Index)
  47. r.Get("/admin/users/create", reqGrafanaAdmin, hs.Index)
  48. r.Get("/admin/users/edit/:id", reqGrafanaAdmin, hs.Index)
  49. r.Get("/admin/orgs", reqGrafanaAdmin, hs.Index)
  50. r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, hs.Index)
  51. r.Get("/admin/stats", reqGrafanaAdmin, hs.Index)
  52. r.Get("/styleguide", reqSignedIn, hs.Index)
  53. r.Get("/plugins", reqSignedIn, hs.Index)
  54. r.Get("/plugins/:id/edit", reqSignedIn, hs.Index)
  55. r.Get("/plugins/:id/page/:page", reqSignedIn, hs.Index)
  56. r.Get("/d/:uid/:slug", reqSignedIn, hs.Index)
  57. r.Get("/d/:uid", reqSignedIn, hs.Index)
  58. r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardURL, hs.Index)
  59. r.Get("/dashboard/script/*", reqSignedIn, hs.Index)
  60. r.Get("/dashboard-solo/snapshot/*", hs.Index)
  61. r.Get("/d-solo/:uid/:slug", reqSignedIn, hs.Index)
  62. r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloURL, hs.Index)
  63. r.Get("/dashboard-solo/script/*", reqSignedIn, hs.Index)
  64. r.Get("/import/dashboard", reqSignedIn, hs.Index)
  65. r.Get("/dashboards/", reqSignedIn, hs.Index)
  66. r.Get("/dashboards/*", reqSignedIn, hs.Index)
  67. r.Get("/explore", reqEditorRole, hs.Index)
  68. r.Get("/playlists/", reqSignedIn, hs.Index)
  69. r.Get("/playlists/*", reqSignedIn, hs.Index)
  70. r.Get("/alerting/", reqSignedIn, hs.Index)
  71. r.Get("/alerting/*", reqSignedIn, hs.Index)
  72. // sign up
  73. r.Get("/signup", hs.Index)
  74. r.Get("/api/user/signup/options", Wrap(GetSignUpOptions))
  75. r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), Wrap(SignUp))
  76. r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), Wrap(hs.SignUpStep2))
  77. // invited
  78. r.Get("/api/user/invite/:code", Wrap(GetInviteInfoByCode))
  79. r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), Wrap(hs.CompleteInvite))
  80. // reset password
  81. r.Get("/user/password/send-reset-email", hs.Index)
  82. r.Get("/user/password/reset", hs.Index)
  83. r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), Wrap(SendResetPasswordEmail))
  84. r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), Wrap(ResetPassword))
  85. // dashboard snapshots
  86. r.Get("/dashboard/snapshot/*", hs.Index)
  87. r.Get("/dashboard/snapshots/", reqSignedIn, hs.Index)
  88. // api for dashboard snapshots
  89. r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
  90. r.Get("/api/snapshot/shared-options/", GetSharingOptions)
  91. r.Get("/api/snapshots/:key", GetDashboardSnapshot)
  92. r.Get("/api/snapshots-delete/:deleteKey", Wrap(DeleteDashboardSnapshotByDeleteKey))
  93. r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
  94. // api renew session based on cookie
  95. r.Get("/api/login/ping", quota("session"), Wrap(hs.LoginAPIPing))
  96. // authed api
  97. r.Group("/api", func(apiRoute routing.RouteRegister) {
  98. // user (signed in)
  99. apiRoute.Group("/user", func(userRoute routing.RouteRegister) {
  100. userRoute.Get("/", Wrap(GetSignedInUser))
  101. userRoute.Put("/", bind(m.UpdateUserCommand{}), Wrap(UpdateSignedInUser))
  102. userRoute.Post("/using/:id", Wrap(UserSetUsingOrg))
  103. userRoute.Get("/orgs", Wrap(GetSignedInUserOrgList))
  104. userRoute.Get("/teams", Wrap(GetSignedInUserTeamList))
  105. userRoute.Post("/stars/dashboard/:id", Wrap(StarDashboard))
  106. userRoute.Delete("/stars/dashboard/:id", Wrap(UnstarDashboard))
  107. userRoute.Put("/password", bind(m.ChangeUserPasswordCommand{}), Wrap(ChangeUserPassword))
  108. userRoute.Get("/quotas", Wrap(GetUserQuotas))
  109. userRoute.Put("/helpflags/:id", Wrap(SetHelpFlag))
  110. // For dev purpose
  111. userRoute.Get("/helpflags/clear", Wrap(ClearHelpFlags))
  112. userRoute.Get("/preferences", Wrap(GetUserPreferences))
  113. userRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateUserPreferences))
  114. })
  115. // users (admin permission required)
  116. apiRoute.Group("/users", func(usersRoute routing.RouteRegister) {
  117. usersRoute.Get("/", Wrap(SearchUsers))
  118. usersRoute.Get("/search", Wrap(SearchUsersWithPaging))
  119. usersRoute.Get("/:id", Wrap(GetUserByID))
  120. usersRoute.Get("/:id/teams", Wrap(GetUserTeams))
  121. usersRoute.Get("/:id/orgs", Wrap(GetUserOrgList))
  122. // query parameters /users/lookup?loginOrEmail=admin@example.com
  123. usersRoute.Get("/lookup", Wrap(GetUserByLoginOrEmail))
  124. usersRoute.Put("/:id", bind(m.UpdateUserCommand{}), Wrap(UpdateUser))
  125. usersRoute.Post("/:id/using/:orgId", Wrap(UpdateUserActiveOrg))
  126. }, reqGrafanaAdmin)
  127. // team (admin permission required)
  128. apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
  129. teamsRoute.Post("/", bind(m.CreateTeamCommand{}), Wrap(CreateTeam))
  130. teamsRoute.Put("/:teamId", bind(m.UpdateTeamCommand{}), Wrap(UpdateTeam))
  131. teamsRoute.Delete("/:teamId", Wrap(DeleteTeamByID))
  132. teamsRoute.Get("/:teamId/members", Wrap(GetTeamMembers))
  133. teamsRoute.Post("/:teamId/members", bind(m.AddTeamMemberCommand{}), Wrap(AddTeamMember))
  134. teamsRoute.Delete("/:teamId/members/:userId", Wrap(RemoveTeamMember))
  135. teamsRoute.Get("/:teamId/preferences", Wrap(GetTeamPreferences))
  136. teamsRoute.Put("/:teamId/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateTeamPreferences))
  137. }, reqOrgAdmin)
  138. // team without requirement of user to be org admin
  139. apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
  140. teamsRoute.Get("/:teamId", Wrap(GetTeamByID))
  141. teamsRoute.Get("/search", Wrap(SearchTeams))
  142. })
  143. // org information available to all users.
  144. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  145. orgRoute.Get("/", Wrap(GetOrgCurrent))
  146. orgRoute.Get("/quotas", Wrap(GetOrgQuotas))
  147. })
  148. // current org
  149. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  150. orgRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrgCurrent))
  151. orgRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddressCurrent))
  152. orgRoute.Post("/users", quota("user"), bind(m.AddOrgUserCommand{}), Wrap(AddOrgUserToCurrentOrg))
  153. orgRoute.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), Wrap(UpdateOrgUserForCurrentOrg))
  154. orgRoute.Delete("/users/:userId", Wrap(RemoveOrgUserForCurrentOrg))
  155. // invites
  156. orgRoute.Get("/invites", Wrap(GetPendingOrgInvites))
  157. orgRoute.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), Wrap(AddOrgInvite))
  158. orgRoute.Patch("/invites/:code/revoke", Wrap(RevokeInvite))
  159. // prefs
  160. orgRoute.Get("/preferences", Wrap(GetOrgPreferences))
  161. orgRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateOrgPreferences))
  162. }, reqOrgAdmin)
  163. // current org without requirement of user to be org admin
  164. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  165. orgRoute.Get("/users", Wrap(GetOrgUsersForCurrentOrg))
  166. })
  167. // create new org
  168. apiRoute.Post("/orgs", quota("org"), bind(m.CreateOrgCommand{}), Wrap(CreateOrg))
  169. // search all orgs
  170. apiRoute.Get("/orgs", reqGrafanaAdmin, Wrap(SearchOrgs))
  171. // orgs (admin routes)
  172. apiRoute.Group("/orgs/:orgId", func(orgsRoute routing.RouteRegister) {
  173. orgsRoute.Get("/", Wrap(GetOrgByID))
  174. orgsRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrg))
  175. orgsRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddress))
  176. orgsRoute.Delete("/", Wrap(DeleteOrgByID))
  177. orgsRoute.Get("/users", Wrap(GetOrgUsers))
  178. orgsRoute.Post("/users", bind(m.AddOrgUserCommand{}), Wrap(AddOrgUser))
  179. orgsRoute.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), Wrap(UpdateOrgUser))
  180. orgsRoute.Delete("/users/:userId", Wrap(RemoveOrgUser))
  181. orgsRoute.Get("/quotas", Wrap(GetOrgQuotas))
  182. orgsRoute.Put("/quotas/:target", bind(m.UpdateOrgQuotaCmd{}), Wrap(UpdateOrgQuota))
  183. }, reqGrafanaAdmin)
  184. // orgs (admin routes)
  185. apiRoute.Group("/orgs/name/:name", func(orgsRoute routing.RouteRegister) {
  186. orgsRoute.Get("/", Wrap(GetOrgByName))
  187. }, reqGrafanaAdmin)
  188. // auth api keys
  189. apiRoute.Group("/auth/keys", func(keysRoute routing.RouteRegister) {
  190. keysRoute.Get("/", Wrap(GetAPIKeys))
  191. keysRoute.Post("/", quota("api_key"), bind(m.AddApiKeyCommand{}), Wrap(AddAPIKey))
  192. keysRoute.Delete("/:id", Wrap(DeleteAPIKey))
  193. }, reqOrgAdmin)
  194. // Preferences
  195. apiRoute.Group("/preferences", func(prefRoute routing.RouteRegister) {
  196. prefRoute.Post("/set-home-dash", bind(m.SavePreferencesCommand{}), Wrap(SetHomeDashboard))
  197. })
  198. // Data sources
  199. apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) {
  200. datasourceRoute.Get("/", Wrap(GetDataSources))
  201. datasourceRoute.Post("/", quota("data_source"), bind(m.AddDataSourceCommand{}), Wrap(AddDataSource))
  202. datasourceRoute.Put("/:id", bind(m.UpdateDataSourceCommand{}), Wrap(UpdateDataSource))
  203. datasourceRoute.Delete("/:id", Wrap(DeleteDataSourceById))
  204. datasourceRoute.Delete("/name/:name", Wrap(DeleteDataSourceByName))
  205. datasourceRoute.Get("/:id", Wrap(GetDataSourceById))
  206. datasourceRoute.Get("/name/:name", Wrap(GetDataSourceByName))
  207. }, reqOrgAdmin)
  208. apiRoute.Get("/datasources/id/:name", Wrap(GetDataSourceIdByName), reqSignedIn)
  209. apiRoute.Get("/plugins", Wrap(hs.GetPluginList))
  210. apiRoute.Get("/plugins/:pluginId/settings", Wrap(GetPluginSettingByID))
  211. apiRoute.Get("/plugins/:pluginId/markdown/:name", Wrap(GetPluginMarkdown))
  212. apiRoute.Group("/plugins", func(pluginRoute routing.RouteRegister) {
  213. pluginRoute.Get("/:pluginId/dashboards/", Wrap(GetPluginDashboards))
  214. pluginRoute.Post("/:pluginId/settings", bind(m.UpdatePluginSettingCmd{}), Wrap(UpdatePluginSetting))
  215. }, reqOrgAdmin)
  216. apiRoute.Get("/frontend/settings/", hs.GetFrontendSettings)
  217. apiRoute.Any("/datasources/proxy/:id/*", reqSignedIn, hs.ProxyDataSourceRequest)
  218. apiRoute.Any("/datasources/proxy/:id", reqSignedIn, hs.ProxyDataSourceRequest)
  219. // Folders
  220. apiRoute.Group("/folders", func(folderRoute routing.RouteRegister) {
  221. folderRoute.Get("/", Wrap(GetFolders))
  222. folderRoute.Get("/id/:id", Wrap(GetFolderByID))
  223. folderRoute.Post("/", bind(m.CreateFolderCommand{}), Wrap(CreateFolder))
  224. folderRoute.Group("/:uid", func(folderUidRoute routing.RouteRegister) {
  225. folderUidRoute.Get("/", Wrap(GetFolderByUID))
  226. folderUidRoute.Put("/", bind(m.UpdateFolderCommand{}), Wrap(UpdateFolder))
  227. folderUidRoute.Delete("/", Wrap(DeleteFolder))
  228. folderUidRoute.Group("/permissions", func(folderPermissionRoute routing.RouteRegister) {
  229. folderPermissionRoute.Get("/", Wrap(GetFolderPermissionList))
  230. folderPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateFolderPermissions))
  231. })
  232. })
  233. })
  234. // Dashboard
  235. apiRoute.Group("/dashboards", func(dashboardRoute routing.RouteRegister) {
  236. dashboardRoute.Get("/uid/:uid", Wrap(GetDashboard))
  237. dashboardRoute.Delete("/uid/:uid", Wrap(DeleteDashboardByUID))
  238. dashboardRoute.Get("/db/:slug", Wrap(GetDashboard))
  239. dashboardRoute.Delete("/db/:slug", Wrap(DeleteDashboard))
  240. dashboardRoute.Post("/calculate-diff", bind(dtos.CalculateDiffOptions{}), Wrap(CalculateDashboardDiff))
  241. dashboardRoute.Post("/db", bind(m.SaveDashboardCommand{}), Wrap(hs.PostDashboard))
  242. dashboardRoute.Get("/home", Wrap(GetHomeDashboard))
  243. dashboardRoute.Get("/tags", GetDashboardTags)
  244. dashboardRoute.Post("/import", bind(dtos.ImportDashboardCommand{}), Wrap(ImportDashboard))
  245. dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
  246. dashIdRoute.Get("/versions", Wrap(GetDashboardVersions))
  247. dashIdRoute.Get("/versions/:id", Wrap(GetDashboardVersion))
  248. dashIdRoute.Post("/restore", bind(dtos.RestoreDashboardVersionCommand{}), Wrap(hs.RestoreDashboardVersion))
  249. dashIdRoute.Group("/permissions", func(dashboardPermissionRoute routing.RouteRegister) {
  250. dashboardPermissionRoute.Get("/", Wrap(GetDashboardPermissionList))
  251. dashboardPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateDashboardPermissions))
  252. })
  253. })
  254. })
  255. // Dashboard snapshots
  256. apiRoute.Group("/dashboard/snapshots", func(dashboardRoute routing.RouteRegister) {
  257. dashboardRoute.Get("/", Wrap(SearchDashboardSnapshots))
  258. })
  259. // Playlist
  260. apiRoute.Group("/playlists", func(playlistRoute routing.RouteRegister) {
  261. playlistRoute.Get("/", Wrap(SearchPlaylists))
  262. playlistRoute.Get("/:id", ValidateOrgPlaylist, Wrap(GetPlaylist))
  263. playlistRoute.Get("/:id/items", ValidateOrgPlaylist, Wrap(GetPlaylistItems))
  264. playlistRoute.Get("/:id/dashboards", ValidateOrgPlaylist, Wrap(GetPlaylistDashboards))
  265. playlistRoute.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, Wrap(DeletePlaylist))
  266. playlistRoute.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistCommand{}), ValidateOrgPlaylist, Wrap(UpdatePlaylist))
  267. playlistRoute.Post("/", reqEditorRole, bind(m.CreatePlaylistCommand{}), Wrap(CreatePlaylist))
  268. })
  269. // Search
  270. apiRoute.Get("/search/", Search)
  271. // metrics
  272. apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetrics))
  273. apiRoute.Get("/tsdb/testdata/scenarios", Wrap(GetTestDataScenarios))
  274. apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData))
  275. apiRoute.Get("/tsdb/testdata/random-walk", Wrap(GetTestDataRandomWalk))
  276. apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
  277. alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest))
  278. alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert))
  279. alertsRoute.Get("/:alertId", ValidateOrgAlert, Wrap(GetAlert))
  280. alertsRoute.Get("/", Wrap(GetAlerts))
  281. alertsRoute.Get("/states-for-dashboard", Wrap(GetAlertStatesForDashboard))
  282. })
  283. apiRoute.Get("/alert-notifications", Wrap(GetAlertNotifications))
  284. apiRoute.Get("/alert-notifiers", Wrap(GetAlertNotifiers))
  285. apiRoute.Group("/alert-notifications", func(alertNotifications routing.RouteRegister) {
  286. alertNotifications.Post("/test", bind(dtos.NotificationTestCommand{}), Wrap(NotificationTest))
  287. alertNotifications.Post("/", bind(m.CreateAlertNotificationCommand{}), Wrap(CreateAlertNotification))
  288. alertNotifications.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), Wrap(UpdateAlertNotification))
  289. alertNotifications.Get("/:notificationId", Wrap(GetAlertNotificationByID))
  290. alertNotifications.Delete("/:notificationId", Wrap(DeleteAlertNotification))
  291. }, reqEditorRole)
  292. apiRoute.Get("/annotations", Wrap(GetAnnotations))
  293. apiRoute.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), Wrap(DeleteAnnotations))
  294. apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) {
  295. annotationsRoute.Post("/", bind(dtos.PostAnnotationsCmd{}), Wrap(PostAnnotation))
  296. annotationsRoute.Delete("/:annotationId", Wrap(DeleteAnnotationByID))
  297. annotationsRoute.Put("/:annotationId", bind(dtos.UpdateAnnotationsCmd{}), Wrap(UpdateAnnotation))
  298. annotationsRoute.Patch("/:annotationId", bind(dtos.PatchAnnotationsCmd{}), Wrap(PatchAnnotation))
  299. annotationsRoute.Delete("/region/:regionId", Wrap(DeleteAnnotationRegion))
  300. annotationsRoute.Post("/graphite", reqEditorRole, bind(dtos.PostGraphiteAnnotationsCmd{}), Wrap(PostGraphiteAnnotation))
  301. })
  302. // error test
  303. r.Get("/metrics/error", Wrap(GenerateError))
  304. }, reqSignedIn)
  305. // admin api
  306. r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
  307. adminRoute.Get("/settings", AdminGetSettings)
  308. adminRoute.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
  309. adminRoute.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
  310. adminRoute.Put("/users/:id/permissions", bind(dtos.AdminUpdateUserPermissionsForm{}), AdminUpdateUserPermissions)
  311. adminRoute.Delete("/users/:id", AdminDeleteUser)
  312. adminRoute.Get("/users/:id/quotas", Wrap(GetUserQuotas))
  313. adminRoute.Put("/users/:id/quotas/:target", bind(m.UpdateUserQuotaCmd{}), Wrap(UpdateUserQuota))
  314. adminRoute.Get("/stats", AdminGetStats)
  315. adminRoute.Post("/pause-all-alerts", bind(dtos.PauseAllAlertsCommand{}), Wrap(PauseAllAlerts))
  316. }, reqGrafanaAdmin)
  317. // rendering
  318. r.Get("/render/*", reqSignedIn, hs.RenderToPng)
  319. // grafana.net proxy
  320. r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
  321. // Gravatar service.
  322. avatarCacheServer := avatar.NewCacheServer()
  323. r.Get("/avatar/:hash", avatarCacheServer.Handler)
  324. // Websocket
  325. r.Any("/ws", hs.streamManager.Serve)
  326. // streams
  327. //r.Post("/api/streams/push", reqSignedIn, bind(dtos.StreamMessage{}), liveConn.PushToStream)
  328. }