2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package api
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import (
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-13 22:38:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/go-macaron/binding"
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-21 06:51:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/api/avatar"
							 | 
						
					
						
							
								
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/api/dtos"
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/api/routing"
							 | 
						
					
						
							
								
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/middleware"
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"github.com/grafana/grafana/pkg/models"
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-28 16:36:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// registerRoutes registers all API HTTP routes.
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-23 05:13:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (hs *HTTPServer) registerRoutes() {
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-11 18:36:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									reqSignedIn := middleware.ReqSignedIn
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									reqGrafanaAdmin := middleware.ReqGrafanaAdmin
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									reqEditorRole := middleware.ReqEditorRole
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									reqOrgAdmin := middleware.ReqOrgAdmin
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-14 17:02:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									reqCanAccessTeams := middleware.AdminOrFeatureEnabled(hs.Cfg.EditorsCanAdmin)
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-02 21:15:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									reqSnapshotPublicModeOrSignedIn := middleware.SnapshotPublicModeOrSignedIn()
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-23 05:13:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									redirectFromLegacyDashboardURL := middleware.RedirectFromLegacyDashboardURL()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									redirectFromLegacyDashboardSoloURL := middleware.RedirectFromLegacyDashboardSoloURL()
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 18:51:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									redirectFromLegacyPanelEditURL := middleware.RedirectFromLegacyPanelEditURL()
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-12 04:12:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									quota := middleware.Quota(hs.QuotaService)
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									bind := binding.Bind
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-27 19:41:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r := hs.RouteRegister
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-29 20:45:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// not logged in views
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-15 22:15:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/logout", hs.Logout)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), Wrap(hs.LoginPost))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/login/:name", quota("session"), hs.OAuthLogin)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/login", hs.LoginView)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/invite/:code", hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// authed views
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/profile/", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/profile/password", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/profile/switch-org/:id", reqSignedIn, hs.ChangeActiveOrgAndRedirectToHome)
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-04 22:51:18 +08: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)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/users", reqOrgAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/users/new", reqOrgAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/users/invite", reqOrgAdmin, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-14 17:02:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/teams", reqCanAccessTeams, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/teams/*", reqCanAccessTeams, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-04 22:51:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/org/apikeys/", reqOrgAdmin, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard/import/", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/configuration", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/settings", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/users", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/users/create", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/users/edit/:id", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/orgs", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/stats", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-17 16:27:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/admin/ldap", reqGrafanaAdmin, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/styleguide", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/plugins", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-03 01:15:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/plugins/:id/", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/plugins/:id/edit", reqSignedIn, hs.Index) // deprecated
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/plugins/:id/page/:page", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-03 01:15:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/a/:id/*", reqSignedIn, hs.Index) // App Root Page
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 18:51:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/d/:uid/:slug", reqSignedIn, redirectFromLegacyPanelEditURL, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/d/:uid", reqSignedIn, redirectFromLegacyPanelEditURL, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardURL, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard/script/*", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard-solo/snapshot/*", hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/d-solo/:uid/:slug", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-15 00:21:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/d-solo/:uid", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloURL, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									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 18:48:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/goto/:uid", reqSignedIn, hs.redirectFromShortURL, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-05 19:41:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/explore", reqSignedIn, middleware.EnsureEditorOrViewerCanEdit, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/playlists/", reqSignedIn, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/playlists/*", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-04 22:48:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/alerting/", reqEditorRole, hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/alerting/*", reqEditorRole, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// sign up
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-07 23:24:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/verify", hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/signup", hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/user/signup/options", Wrap(GetSignUpOptions))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), Wrap(SignUp))
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-15 22:15:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), Wrap(hs.SignUpStep2))
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-20 21:52:49 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// invited
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/user/invite/:code", Wrap(GetInviteInfoByCode))
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-15 22:15:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), Wrap(hs.CompleteInvite))
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-20 21:52:49 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-08 16:57:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// reset password
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/user/password/send-reset-email", hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/user/password/reset", hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-08 16:57:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), Wrap(SendResetPasswordEmail))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), Wrap(ResetPassword))
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-21 20:53:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// dashboard snapshots
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard/snapshot/*", hs.Index)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/dashboard/snapshots/", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2015-03-27 03:34:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-05 00:37:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// api renew session based on cookie
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/login/ping", quota("session"), Wrap(hs.LoginAPIPing))
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-07 15:25:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// authed api
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Group("/api", func(apiRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// user (signed in)
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/user", func(userRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/", Wrap(GetSignedInUser))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Put("/", bind(models.UpdateUserCommand{}), Wrap(UpdateSignedInUser))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Post("/using/:id", Wrap(UserSetUsingOrg))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/orgs", Wrap(GetSignedInUserOrgList))
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-08 16:26:05 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/teams", Wrap(GetSignedInUserTeamList))
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 20:53:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Post("/stars/dashboard/:id", Wrap(StarDashboard))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											userRoute.Delete("/stars/dashboard/:id", Wrap(UnstarDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 20:53:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Put("/password", bind(models.ChangeUserPasswordCommand{}), Wrap(ChangeUserPassword))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/quotas", Wrap(GetUserQuotas))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											userRoute.Put("/helpflags/:id", Wrap(SetHelpFlag))
							 | 
						
					
						
							
								
									
										
										
										
											2016-11-09 17:41:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											// For dev purpose
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/helpflags/clear", Wrap(ClearHelpFlags))
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-03 04:54:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/preferences", Wrap(GetUserPreferences))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											userRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateUserPreferences))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											userRoute.Get("/auth-tokens", Wrap(hs.GetUserAuthTokens))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											userRoute.Post("/revoke-auth-token", bind(models.RevokeAuthTokenCmd{}), Wrap(hs.RevokeUserAuthToken))
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// users (admin permission required)
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/users", func(usersRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/", Wrap(SearchUsers))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/search", Wrap(SearchUsersWithPaging))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/:id", Wrap(GetUserByID))
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-19 17:08:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/:id/teams", Wrap(GetUserTeams))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/:id/orgs", Wrap(GetUserOrgList))
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-31 13:25:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											// query parameters /users/lookup?loginOrEmail=admin@example.com
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Get("/lookup", Wrap(GetUserByLoginOrEmail))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Put("/:id", bind(models.UpdateUserCommand{}), Wrap(UpdateUser))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											usersRoute.Post("/:id/using/:orgId", Wrap(UpdateUserActiveOrg))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqGrafanaAdmin)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-08 23:25:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// team (admin permission required)
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Post("/", bind(models.CreateTeamCommand{}), Wrap(hs.CreateTeam))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Put("/:teamId", bind(models.UpdateTeamCommand{}), Wrap(hs.UpdateTeam))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-14 19:10:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Delete("/:teamId", Wrap(hs.DeleteTeamByID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-01 21:56:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Get("/:teamId/members", Wrap(hs.GetTeamMembers))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Post("/:teamId/members", bind(models.AddTeamMemberCommand{}), Wrap(hs.AddTeamMember))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Put("/:teamId/members/:userId", bind(models.UpdateTeamMemberCommand{}), Wrap(hs.UpdateTeamMember))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-12 23:59:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Delete("/:teamId/members/:userId", Wrap(hs.RemoveTeamMember))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-14 19:10:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Get("/:teamId/preferences", Wrap(hs.GetTeamPreferences))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Put("/:teamId/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(hs.UpdateTeamPreferences))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-14 17:02:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqCanAccessTeams)
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-10 07:24:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 20:08:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// team without requirement of user to be org admin
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/teams", func(teamsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Get("/:teamId", Wrap(GetTeamByID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-13 21:05:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											teamsRoute.Get("/search", Wrap(hs.SearchTeams))
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 20:08:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 01:18:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// org information available to all users.
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/", Wrap(GetOrgCurrent))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/quotas", Wrap(GetOrgQuotas))
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-11 01:18:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// current org
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrgCurrent))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddressCurrent))
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/users", Wrap(GetOrgUsersForCurrentOrg))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Post("/users", quota("user"), bind(models.AddOrgUserCommand{}), Wrap(AddOrgUserToCurrentOrg))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Patch("/users/:userId", bind(models.UpdateOrgUserCommand{}), Wrap(UpdateOrgUserForCurrentOrg))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Delete("/users/:userId", Wrap(RemoveOrgUserForCurrentOrg))
							 | 
						
					
						
							
								
									
										
										
										
											2015-07-17 15:51:34 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											// invites
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/invites", Wrap(GetPendingOrgInvites))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), Wrap(AddOrgInvite))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Patch("/invites/:code/revoke", Wrap(RevokeInvite))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-18 13:46:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-03 04:54:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											// prefs
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/preferences", Wrap(GetOrgPreferences))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Put("/preferences", bind(dtos.UpdatePrefsCmd{}), Wrap(UpdateOrgPreferences))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqOrgAdmin)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 20:08:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// current org without requirement of user to be org admin
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/org", func(orgRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/users/lookup", Wrap(GetOrgUsersForCurrentOrgLookup))
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-06 20:08:23 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// create new org
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Post("/orgs", quota("org"), bind(models.CreateOrgCommand{}), Wrap(CreateOrg))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// search all orgs
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/orgs", reqGrafanaAdmin, Wrap(SearchOrgs))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// orgs (admin routes)
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/orgs/:orgId", func(orgsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Get("/", Wrap(GetOrgByID))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Put("/", bind(dtos.UpdateOrgForm{}), Wrap(UpdateOrg))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Put("/address", bind(dtos.UpdateOrgAddressForm{}), Wrap(UpdateOrgAddress))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Delete("/", Wrap(DeleteOrgByID))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Get("/users", Wrap(GetOrgUsers))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Post("/users", bind(models.AddOrgUserCommand{}), Wrap(AddOrgUser))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Patch("/users/:userId", bind(models.UpdateOrgUserCommand{}), Wrap(UpdateOrgUser))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Delete("/users/:userId", Wrap(RemoveOrgUser))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Get("/quotas", Wrap(GetOrgQuotas))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Put("/quotas/:target", bind(models.UpdateOrgQuotaCmd{}), Wrap(UpdateOrgQuota))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqGrafanaAdmin)
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// orgs (admin routes)
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/orgs/name/:name", func(orgsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											orgsRoute.Get("/", Wrap(GetOrgByName))
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqGrafanaAdmin)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-27 15:26:11 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// auth api keys
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/auth/keys", func(keysRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											keysRoute.Get("/", Wrap(GetAPIKeys))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											keysRoute.Post("/", quota("api_key"), bind(models.AddApiKeyCommand{}), Wrap(hs.AddAPIKey))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											keysRoute.Delete("/:id", Wrap(DeleteAPIKey))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqOrgAdmin)
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-17 14:35:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Preferences
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/preferences", func(prefRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											prefRoute.Post("/set-home-dash", bind(models.SavePreferencesCommand{}), Wrap(SetHomeDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-17 14:35:06 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-11 22:30:05 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Data sources
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Get("/", Wrap(GetDataSources))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Post("/", quota("data_source"), bind(models.AddDataSourceCommand{}), Wrap(AddDataSource))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Put("/:id", bind(models.UpdateDataSourceCommand{}), Wrap(UpdateDataSource))
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-01 21:38:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Delete("/:id", Wrap(DeleteDataSourceById))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Delete("/name/:name", Wrap(DeleteDataSourceByName))
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-01 21:38:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Get("/:id", Wrap(GetDataSourceById))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											datasourceRoute.Get("/name/:name", Wrap(GetDataSourceByName))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqOrgAdmin)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-01 21:38:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/datasources/id/:name", Wrap(GetDataSourceIdByName), reqSignedIn)
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-08 04:25:26 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-15 18:10:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/plugins", Wrap(hs.GetPluginList))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/plugins/:pluginId/settings", Wrap(GetPluginSettingByID))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/plugins/:pluginId/markdown/:name", Wrap(GetPluginMarkdown))
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-31 18:15:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/plugins/:pluginId/health", Wrap(hs.CheckHealth))
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-03 18:45:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/plugins/:pluginId/resources", hs.CallResource)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/plugins/:pluginId/resources/*", hs.CallResource)
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-23 22:45:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/plugins/errors", Wrap(hs.GetPluginErrorsList))
							 | 
						
					
						
							
								
									
										
										
										
											2016-03-11 16:57:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/plugins", func(pluginRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											pluginRoute.Get("/:pluginId/dashboards/", Wrap(GetPluginDashboards))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											pluginRoute.Post("/:pluginId/settings", bind(models.UpdatePluginSettingCmd{}), Wrap(UpdatePluginSetting))
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-18 19:08:20 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											pluginRoute.Get("/:pluginId/metrics", Wrap(hs.CollectPluginMetrics))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqOrgAdmin)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/frontend/settings/", hs.GetFrontendSettings)
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 20:53:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/datasources/proxy/:id/*", reqSignedIn, hs.ProxyDataSourceRequest)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/datasources/proxy/:id", reqSignedIn, hs.ProxyDataSourceRequest)
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-03 18:45:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/datasources/:id/resources", hs.CallDatasourceResource)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/datasources/:id/resources/*", hs.CallDatasourceResource)
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-11 22:14:05 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Any("/datasources/:id/health", Wrap(hs.CheckDatasourceHealth))
							 | 
						
					
						
							
								
									
										
										
										
											2015-02-10 17:19:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-29 20:51:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Folders
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/folders", func(folderRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											folderRoute.Get("/", Wrap(GetFolders))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											folderRoute.Get("/id/:id", Wrap(GetFolderByID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											folderRoute.Post("/", bind(models.CreateFolderCommand{}), Wrap(hs.CreateFolder))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 22:25:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											folderRoute.Group("/:uid", func(folderUidRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												folderUidRoute.Get("/", Wrap(GetFolderByUID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												folderUidRoute.Put("/", bind(models.UpdateFolderCommand{}), Wrap(UpdateFolder))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												folderUidRoute.Delete("/", Wrap(DeleteFolder))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 22:25:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												folderUidRoute.Group("/permissions", func(folderPermissionRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													folderPermissionRoute.Get("/", Wrap(GetFolderPermissionList))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													folderPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateFolderPermissions))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 22:25:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											})
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-29 20:51:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Dashboard
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/dashboards", func(dashboardRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Get("/uid/:uid", Wrap(hs.GetDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Delete("/uid/:uid", Wrap(DeleteDashboardByUID))
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-30 04:23:07 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Get("/db/:slug", Wrap(hs.GetDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-10 19:29:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Delete("/db/:slug", Wrap(DeleteDashboardBySlug))
							 | 
						
					
						
							
								
									
										
											 
										 
										
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
										
											2017-05-25 07:14:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Post("/calculate-diff", bind(dtos.CalculateDiffOptions{}), Wrap(CalculateDashboardDiff))
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-07 17:50:09 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Post("/db", bind(models.SaveDashboardCommand{}), Wrap(hs.PostDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-23 00:00:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Get("/home", Wrap(hs.GetHomeDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 20:53:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Get("/tags", GetDashboardTags)
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Post("/import", bind(dtos.ImportDashboardCommand{}), Wrap(ImportDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-12 23:38:49 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												dashIdRoute.Get("/versions", Wrap(GetDashboardVersions))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												dashIdRoute.Get("/versions/:id", Wrap(GetDashboardVersion))
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-12 04:12:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												dashIdRoute.Post("/restore", bind(dtos.RestoreDashboardVersionCommand{}), Wrap(hs.RestoreDashboardVersion))
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-12 23:38:49 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												dashIdRoute.Group("/permissions", func(dashboardPermissionRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													dashboardPermissionRoute.Get("/", Wrap(GetDashboardPermissionList))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													dashboardPermissionRoute.Post("/", bind(dtos.UpdateDashboardAclCommand{}), Wrap(UpdateDashboardPermissions))
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-12 23:38:49 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											})
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-19 21:05:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Dashboard snapshots
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/dashboard/snapshots", func(dashboardRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											dashboardRoute.Get("/", Wrap(SearchDashboardSnapshots))
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-19 21:05:24 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							
								
									
										
										
										
											2016-01-19 17:37:36 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Playlist
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/playlists", func(playlistRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Get("/", Wrap(SearchPlaylists))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Get("/:id", ValidateOrgPlaylist, Wrap(GetPlaylist))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Get("/:id/items", ValidateOrgPlaylist, Wrap(GetPlaylistItems))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Get("/:id/dashboards", ValidateOrgPlaylist, Wrap(GetPlaylistDashboards))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, Wrap(DeletePlaylist))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Put("/:id", reqEditorRole, bind(models.UpdatePlaylistCommand{}), ValidateOrgPlaylist, Wrap(UpdatePlaylist))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											playlistRoute.Post("/", reqEditorRole, bind(models.CreatePlaylistCommand{}), Wrap(CreatePlaylist))
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// Search
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-20 22:20:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/search/sorting", Wrap(hs.ListSortOptions))
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-17 19:07:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/search/", Wrap(Search))
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// metrics
							 | 
						
					
						
							
								
									
										
										
										
											2018-09-14 15:30:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Post("/tsdb/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetrics))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/tsdb/testdata/scenarios", Wrap(GetTestDataScenarios))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, Wrap(GenerateSQLTestData))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/tsdb/testdata/random-walk", Wrap(GetTestDataRandomWalk))
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-13 20:53:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-01 07:22:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// DataSource w/ expressions
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Post("/ds/query", bind(dtos.MetricRequest{}), Wrap(hs.QueryMetricsV2))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/alerts", func(alertsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertsRoute.Post("/test", bind(dtos.AlertTestCommand{}), Wrap(AlertTest))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertsRoute.Post("/:alertId/pause", reqEditorRole, bind(dtos.PauseAlertCommand{}), Wrap(PauseAlert))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertsRoute.Get("/:alertId", ValidateOrgAlert, Wrap(GetAlert))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertsRoute.Get("/", Wrap(GetAlerts))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertsRoute.Get("/states-for-dashboard", Wrap(GetAlertStatesForDashboard))
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-26 23:36:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-13 02:51:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										if hs.Cfg.IsNgAlertEnabled() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											apiRoute.Group("/alert-definitions", func(alertDefinitions routing.RouteRegister) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												alertDefinitions.Get("/eval/:dashboardID/:panelID/:refID", reqEditorRole, Wrap(hs.AlertDefinitionEval))
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-17 00:33:57 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												alertDefinitions.Post("/eval", reqEditorRole, bind(dtos.EvalAlertConditionCommand{}), Wrap(hs.ConditionEval))
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-13 02:51:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/alert-notifiers", reqEditorRole, Wrap(GetAlertNotifiers))
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-14 19:32:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/alert-notifications", func(alertNotifications routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Get("/", Wrap(GetAlertNotifications))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Post("/test", bind(dtos.NotificationTestCommand{}), Wrap(NotificationTest))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Post("/", bind(models.CreateAlertNotificationCommand{}), Wrap(CreateAlertNotification))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Put("/:notificationId", bind(models.UpdateAlertNotificationCommand{}), Wrap(UpdateAlertNotification))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Get("/:notificationId", Wrap(GetAlertNotificationByID))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Delete("/:notificationId", Wrap(DeleteAlertNotification))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Get("/uid/:uid", Wrap(GetAlertNotificationByUID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Put("/uid/:uid", bind(models.UpdateAlertNotificationWithUidCommand{}), Wrap(UpdateAlertNotificationByUID))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-26 19:37:02 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											alertNotifications.Delete("/uid/:uid", Wrap(DeleteAlertNotificationByUID))
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-19 14:01:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										}, reqEditorRole)
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-14 19:32:16 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// alert notifications without requirement of user to be org editor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/alert-notifications", func(orgRoute routing.RouteRegister) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											orgRoute.Get("/lookup", Wrap(GetAlertNotificationLookup))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Get("/annotations", Wrap(GetAnnotations))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), Wrap(DeleteAnnotations))
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-12 21:46:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										apiRoute.Group("/annotations", func(annotationsRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											annotationsRoute.Post("/", bind(dtos.PostAnnotationsCmd{}), Wrap(PostAnnotation))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											annotationsRoute.Delete("/:annotationId", Wrap(DeleteAnnotationByID))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											annotationsRoute.Put("/:annotationId", bind(dtos.UpdateAnnotationsCmd{}), Wrap(UpdateAnnotation))
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-27 19:49:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											annotationsRoute.Patch("/:annotationId", bind(dtos.PatchAnnotationsCmd{}), Wrap(PatchAnnotation))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											annotationsRoute.Post("/graphite", reqEditorRole, bind(dtos.PostGraphiteAnnotationsCmd{}), Wrap(PostGraphiteAnnotation))
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-21 07:52:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-08 17:25:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-06-07 16:05:10 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										// error test
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										r.Get("/metrics/error", Wrap(GenerateError))
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-14 18:48:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// short urls
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										apiRoute.Post("/short-urls", bind(dtos.CreateShortURLCmd{}), Wrap(hs.createShortURL))
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-15 19:16:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}, reqSignedIn)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// admin api
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-25 22:36:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Group("/api/admin", func(adminRoute routing.RouteRegister) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-30 00:00:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/settings", Wrap(AdminGetSettings))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/users", bind(dtos.AdminCreateUserForm{}), Wrap(AdminCreateUser))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), Wrap(AdminUpdateUserPassword))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Put("/users/:id/permissions", bind(dtos.AdminUpdateUserPermissionsForm{}), Wrap(AdminUpdateUserPermissions))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Delete("/users/:id", Wrap(AdminDeleteUser))
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-23 20:54:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/users/:id/disable", Wrap(hs.AdminDisableUser))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/users/:id/enable", Wrap(AdminEnableUser))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/users/:id/quotas", Wrap(GetUserQuotas))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Put("/users/:id/quotas/:target", bind(models.UpdateUserQuotaCmd{}), Wrap(UpdateUserQuota))
							 | 
						
					
						
							
								
									
										
										
										
											2020-07-30 00:00:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/stats", Wrap(AdminGetStats))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 20:10:39 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/pause-all-alerts", bind(dtos.PauseAllAlertsCommand{}), Wrap(PauseAllAlerts))
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-08 22:15:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/users/:id/logout", Wrap(hs.AdminLogoutUser))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/users/:id/auth-tokens", Wrap(hs.AdminGetUserAuthTokens))
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/users/:id/revoke-auth-token", bind(models.RevokeAuthTokenCmd{}), Wrap(hs.AdminRevokeUserAuthToken))
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-01 23:11:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/provisioning/dashboards/reload", Wrap(hs.AdminProvisioningReloadDashboards))
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-22 23:49:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/provisioning/plugins/reload", Wrap(hs.AdminProvisioningReloadPlugins))
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-25 15:06:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/provisioning/datasources/reload", Wrap(hs.AdminProvisioningReloadDatasources))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/provisioning/notifications/reload", Wrap(hs.AdminProvisioningReloadNotifications))
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-22 20:30:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/ldap/reload", Wrap(hs.ReloadLDAPCfg))
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-13 23:26:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Post("/ldap/sync/:id", Wrap(hs.PostSyncUserWithLDAP))
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-04 01:34:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/ldap/:username", Wrap(hs.GetUserFromLDAP))
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-04 22:29:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										adminRoute.Get("/ldap/status", Wrap(hs.GetLDAPStatus))
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-16 21:32:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									}, reqGrafanaAdmin)
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// rendering
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-24 21:26:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/render/*", reqSignedIn, hs.RenderToPng)
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-06 16:11:00 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-04-09 04:42:33 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// grafana.net proxy
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Any("/api/gnet/*", reqSignedIn, ProxyGnetRequest)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-21 06:51:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// Gravatar service.
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-17 20:13:58 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									avatarCacheServer := avatar.NewCacheServer()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/avatar/:hash", avatarCacheServer.Handler)
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-21 06:51:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-02 21:15:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// Snapshots
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Post("/api/snapshots/", reqSnapshotPublicModeOrSignedIn, bind(models.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/snapshot/shared-options/", reqSignedIn, GetSharingOptions)
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-13 16:19:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/snapshots/:key", Wrap(GetDashboardSnapshot))
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-02 21:15:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-16 20:06:50 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									r.Get("/*", reqSignedIn, hs.Index)
							 | 
						
					
						
							
								
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |