api.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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
  18. bind := binding.Bind
  19. r := hs.RouteRegister
  20. // not logged in views
  21. r.Get("/", reqSignedIn, hs.Index)
  22. r.Get("/logout", Logout)
  23. r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), Wrap(LoginPost))
  24. r.Get("/login/:name", quota("session"), 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(SignUpStep2))
  77. // invited
  78. r.Get("/api/user/invite/:code", Wrap(GetInviteInfoByCode))
  79. r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), Wrap(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 remember cookie
  95. r.Get("/api/login/ping", quota("session"), 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/orgs", Wrap(GetUserOrgList))
  121. // query parameters /users/lookup?loginOrEmail=admin@example.com
  122. usersRoute.Get("/lookup", Wrap(GetUserByLoginOrEmail))
  123. usersRoute.Put("/:id", bind(m.UpdateUserCommand{}), Wrap(UpdateUser))
  124. usersRoute.Post("/:id/using/:orgId", Wrap(UpdateUserActiveOrg))
  125. }, reqGrafanaAdmin)
  126. // team (admin permission required)
  127. apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
  128. teamsRoute.Post("/", bind(m.CreateTeamCommand{}), Wrap(CreateTeam))
  129. teamsRoute.Put("/:teamId", bind(m.UpdateTeamCommand{}), Wrap(UpdateTeam))
  130. teamsRoute.Delete("/:teamId", Wrap(DeleteTeamByID))
  131. teamsRoute.Get("/:teamId/members", Wrap(GetTeamMembers))
  132. teamsRoute.Post("/:teamId/members", bind(m.AddTeamMemberCommand{}), Wrap(AddTeamMember))
  133. teamsRoute.Delete("/:teamId/members/:userId", Wrap(RemoveTeamMember))
  134. teamsRoute.Get("/:teamId/preferences", Wrap(GetTeamPreferences))
  135. teamsRoute.Put("/:teamId/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateTeamPreferences))
  136. }, reqOrgAdmin)
  137. // team without requirement of user to be org admin
  138. apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
  139. teamsRoute.Get("/:teamId", Wrap(GetTeamByID))
  140. teamsRoute.Get("/search", Wrap(SearchTeams))
  141. })
  142. // org information available to all users.
  143. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  144. orgRoute.Get("/", Wrap(GetOrgCurrent))
  145. orgRoute.Get("/quotas", Wrap(GetOrgQuotas))
  146. })
  147. // current org
  148. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  149. orgRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrgCurrent))
  150. orgRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddressCurrent))
  151. orgRoute.Post("/users", quota("user"), bind(m.AddOrgUserCommand{}), Wrap(AddOrgUserToCurrentOrg))
  152. orgRoute.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), Wrap(UpdateOrgUserForCurrentOrg))
  153. orgRoute.Delete("/users/:userId", Wrap(RemoveOrgUserForCurrentOrg))
  154. // invites
  155. orgRoute.Get("/invites", Wrap(GetPendingOrgInvites))
  156. orgRoute.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), Wrap(AddOrgInvite))
  157. orgRoute.Patch("/invites/:code/revoke", Wrap(RevokeInvite))
  158. // prefs
  159. orgRoute.Get("/preferences", Wrap(GetOrgPreferences))
  160. orgRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateOrgPreferences))
  161. }, reqOrgAdmin)
  162. // current org without requirement of user to be org admin
  163. apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
  164. orgRoute.Get("/users", Wrap(GetOrgUsersForCurrentOrg))
  165. })
  166. // create new org
  167. apiRoute.Post("/orgs", quota("org"), bind(m.CreateOrgCommand{}), Wrap(CreateOrg))
  168. // search all orgs
  169. apiRoute.Get("/orgs", reqGrafanaAdmin, Wrap(SearchOrgs))
  170. // orgs (admin routes)
  171. apiRoute.Group("/orgs/:orgId", func(orgsRoute routing.RouteRegister) {
  172. orgsRoute.Get("/", Wrap(GetOrgByID))
  173. orgsRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrg))
  174. orgsRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddress))
  175. orgsRoute.Delete("/", Wrap(DeleteOrgByID))
  176. orgsRoute.Get("/users", Wrap(GetOrgUsers))
  177. orgsRoute.Post("/users", bind(m.AddOrgUserCommand{}), Wrap(AddOrgUser))
  178. orgsRoute.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), Wrap(UpdateOrgUser))
  179. orgsRoute.Delete("/users/:userId", Wrap(RemoveOrgUser))
  180. orgsRoute.Get("/quotas", Wrap(GetOrgQuotas))
  181. orgsRoute.Put("/quotas/:target", bind(m.UpdateOrgQuotaCmd{}), Wrap(UpdateOrgQuota))
  182. }, reqGrafanaAdmin)
  183. // orgs (admin routes)
  184. apiRoute.Group("/orgs/name/:name", func(orgsRoute routing.RouteRegister) {
  185. orgsRoute.Get("/", Wrap(GetOrgByName))
  186. }, reqGrafanaAdmin)
  187. // auth api keys
  188. apiRoute.Group("/auth/keys", func(keysRoute routing.RouteRegister) {
  189. keysRoute.Get("/", Wrap(GetAPIKeys))
  190. keysRoute.Post("/", quota("api_key"), bind(m.AddApiKeyCommand{}), Wrap(AddAPIKey))
  191. keysRoute.Delete("/:id", Wrap(DeleteAPIKey))
  192. }, reqOrgAdmin)
  193. // Preferences
  194. apiRoute.Group("/preferences", func(prefRoute routing.RouteRegister) {
  195. prefRoute.Post("/set-home-dash", bind(m.SavePreferencesCommand{}), Wrap(SetHomeDashboard))
  196. })
  197. // Data sources
  198. apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) {
  199. datasourceRoute.Get("/", Wrap(GetDataSources))
  200. datasourceRoute.Post("/", quota("data_source"), bind(m.AddDataSourceCommand{}), Wrap(AddDataSource))
  201. datasourceRoute.Put("/:id", bind(m.UpdateDataSourceCommand{}), Wrap(UpdateDataSource))
  202. datasourceRoute.Delete("/:id", Wrap(DeleteDataSourceById))
  203. datasourceRoute.Delete("/name/:name", Wrap(DeleteDataSourceByName))
  204. datasourceRoute.Get("/:id", Wrap(GetDataSourceById))
  205. datasourceRoute.Get("/name/:name", Wrap(GetDataSourceByName))
  206. }, reqOrgAdmin)
  207. apiRoute.Get("/datasources/id/:name", Wrap(GetDataSourceIdByName), reqSignedIn)
  208. apiRoute.Get("/plugins", Wrap(GetPluginList))
  209. apiRoute.Get("/plugins/:pluginId/settings", Wrap(GetPluginSettingByID))
  210. apiRoute.Get("/plugins/:pluginId/markdown/:name", Wrap(GetPluginMarkdown))
  211. apiRoute.Group("/plugins", func(pluginRoute routing.RouteRegister) {
  212. pluginRoute.Get("/:pluginId/dashboards/", Wrap(GetPluginDashboards))
  213. pluginRoute.Post("/:pluginId/settings", bind(m.UpdatePluginSettingCmd{}), Wrap(UpdatePluginSetting))
  214. }, reqOrgAdmin)
  215. apiRoute.Get("/frontend/settings/", hs.GetFrontendSettings)
  216. apiRoute.Any("/datasources/proxy/:id/*", reqSignedIn, hs.ProxyDataSourceRequest)
  217. apiRoute.Any("/datasources/proxy/:id", reqSignedIn, hs.ProxyDataSourceRequest)
  218. // Folders
  219. apiRoute.Group("/folders", func(folderRoute routing.RouteRegister) {
  220. folderRoute.Get("/", Wrap(GetFolders))
  221. folderRoute.Get("/id/:id", Wrap(GetFolderByID))
  222. folderRoute.Post("/", bind(m.CreateFolderCommand{}), Wrap(CreateFolder))
  223. folderRoute.Group("/:uid", func(folderUidRoute routing.RouteRegister) {
  224. folderUidRoute.Get("/", Wrap(GetFolderByUID))
  225. folderUidRoute.Put("/", bind(m.UpdateFolderCommand{}), Wrap(UpdateFolder))
  226. folderUidRoute.Delete("/", Wrap(DeleteFolder))
  227. folderUidRoute.Group("/permissions", func(folderPermissionRoute routing.RouteRegister) {
  228. folderPermissionRoute.Get("/", Wrap(GetFolderPermissionList))
  229. folderPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateFolderPermissions))
  230. })
  231. })
  232. })
  233. // Dashboard
  234. apiRoute.Group("/dashboards", func(dashboardRoute routing.RouteRegister) {
  235. dashboardRoute.Get("/uid/:uid", Wrap(GetDashboard))
  236. dashboardRoute.Delete("/uid/:uid", Wrap(DeleteDashboardByUID))
  237. dashboardRoute.Get("/db/:slug", Wrap(GetDashboard))
  238. dashboardRoute.Delete("/db/:slug", Wrap(DeleteDashboard))
  239. dashboardRoute.Post("/calculate-diff", bind(dtos.CalculateDiffOptions{}), Wrap(CalculateDashboardDiff))
  240. dashboardRoute.Post("/db", bind(m.SaveDashboardCommand{}), Wrap(PostDashboard))
  241. dashboardRoute.Get("/home", Wrap(GetHomeDashboard))
  242. dashboardRoute.Get("/tags", GetDashboardTags)
  243. dashboardRoute.Post("/import", bind(dtos.ImportDashboardCommand{}), Wrap(ImportDashboard))
  244. dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
  245. dashIdRoute.Get("/versions", Wrap(GetDashboardVersions))
  246. dashIdRoute.Get("/versions/:id", Wrap(GetDashboardVersion))
  247. dashIdRoute.Post("/restore", bind(dtos.RestoreDashboardVersionCommand{}), Wrap(RestoreDashboardVersion))
  248. dashIdRoute.Group("/permissions", func(dashboardPermissionRoute routing.RouteRegister) {
  249. dashboardPermissionRoute.Get("/", Wrap(GetDashboardPermissionList))
  250. dashboardPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateDashboardPermissions))
  251. })
  252. })
  253. })
  254. // Dashboard snapshots
  255. apiRoute.Group("/dashboard/snapshots", func(dashboardRoute routing.RouteRegister) {
  256. dashboardRoute.Get("/", Wrap(SearchDashboardSnapshots))
  257. })
  258. // Playlist
  259. apiRoute.Group("/playlists", func(playlistRoute routing.RouteRegister) {
  260. playlistRoute.Get("/", Wrap(SearchPlaylists))
  261. playlistRoute.Get("/:id", ValidateOrgPlaylist, Wrap(GetPlaylist))
  262. playlistRoute.Get("/:id/items", ValidateOrgPlaylist, Wrap(GetPlaylistItems))
  263. playlistRoute.Get("/:id/dashboards", ValidateOrgPlaylist, Wrap(GetPlaylistDashboards))
  264. playlistRoute.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, Wrap(DeletePlaylist))
  265. playlistRoute.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistCommand{}), ValidateOrgPlaylist, Wrap(UpdatePlaylist))
  266. playlistRoute.Post("/", reqEditorRole, bind(m.CreatePlaylistCommand{}), Wrap(CreatePlaylist))
  267. })
  268. // Search
  269. apiRoute.Get("/search/", Search)
  270. // metrics
  271. apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetrics))
  272. apiRoute.Get("/tsdb/testdata/scenarios", Wrap(GetTestDataScenarios))
  273. apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData))
  274. apiRoute.Get("/tsdb/testdata/random-walk", Wrap(GetTestDataRandomWalk))
  275. apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
  276. alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest))
  277. alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert))
  278. alertsRoute.Get("/:alertId", ValidateOrgAlert, Wrap(GetAlert))
  279. alertsRoute.Get("/", Wrap(GetAlerts))
  280. alertsRoute.Get("/states-for-dashboard", Wrap(GetAlertStatesForDashboard))
  281. })
  282. apiRoute.Get("/alert-notifications", Wrap(GetAlertNotifications))
  283. apiRoute.Get("/alert-notifiers", Wrap(GetAlertNotifiers))
  284. apiRoute.Group("/alert-notifications", func(alertNotifications routing.RouteRegister) {
  285. alertNotifications.Post("/test", bind(dtos.NotificationTestCommand{}), Wrap(NotificationTest))
  286. alertNotifications.Post("/", bind(m.CreateAlertNotificationCommand{}), Wrap(CreateAlertNotification))
  287. alertNotifications.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), Wrap(UpdateAlertNotification))
  288. alertNotifications.Get("/:notificationId", Wrap(GetAlertNotificationByID))
  289. alertNotifications.Delete("/:notificationId", Wrap(DeleteAlertNotification))
  290. }, reqEditorRole)
  291. apiRoute.Get("/annotations", Wrap(GetAnnotations))
  292. apiRoute.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), Wrap(DeleteAnnotations))
  293. apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) {
  294. annotationsRoute.Post("/", bind(dtos.PostAnnotationsCmd{}), Wrap(PostAnnotation))
  295. annotationsRoute.Delete("/:annotationId", Wrap(DeleteAnnotationByID))
  296. annotationsRoute.Put("/:annotationId", bind(dtos.UpdateAnnotationsCmd{}), Wrap(UpdateAnnotation))
  297. annotationsRoute.Delete("/region/:regionId", Wrap(DeleteAnnotationRegion))
  298. annotationsRoute.Post("/graphite", reqEditorRole, bind(dtos.PostGraphiteAnnotationsCmd{}), Wrap(PostGraphiteAnnotation))
  299. })
  300. // error test
  301. r.Get("/metrics/error", Wrap(GenerateError))
  302. }, reqSignedIn)
  303. // admin api
  304. r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
  305. adminRoute.Get("/settings", AdminGetSettings)
  306. adminRoute.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser)
  307. adminRoute.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword)
  308. adminRoute.Put("/users/:id/permissions", bind(dtos.AdminUpdateUserPermissionsForm{}), AdminUpdateUserPermissions)
  309. adminRoute.Delete("/users/:id", AdminDeleteUser)
  310. adminRoute.Get("/users/:id/quotas", Wrap(GetUserQuotas))
  311. adminRoute.Put("/users/:id/quotas/:target", bind(m.UpdateUserQuotaCmd{}), Wrap(UpdateUserQuota))
  312. adminRoute.Get("/stats", AdminGetStats)
  313. adminRoute.Post("/pause-all-alerts", bind(dtos.PauseAllAlertsCommand{}), Wrap(PauseAllAlerts))
  314. }, reqGrafanaAdmin)
  315. // rendering
  316. r.Get("/render/*", reqSignedIn, hs.RenderToPng)
  317. // grafana.net proxy
  318. r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
  319. // Gravatar service.
  320. avatarCacheServer := avatar.NewCacheServer()
  321. r.Get("/avatar/:hash", avatarCacheServer.Handler)
  322. // Websocket
  323. r.Any("/ws", hs.streamManager.Serve)
  324. // streams
  325. //r.Post("/api/streams/push", reqSignedIn, bind(dtos.StreamMessage{}), liveConn.PushToStream)
  326. }