| 
									
										
										
										
											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" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/middleware" | 
					
						
							|  |  |  | 	m "github.com/grafana/grafana/pkg/models" | 
					
						
							| 
									
										
										
										
											2016-01-13 22:38:54 +08:00
										 |  |  | 	"gopkg.in/macaron.v1" | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | // Register adds http routes
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | func Register(r *macaron.Macaron) { | 
					
						
							| 
									
										
										
										
											2015-01-15 19:16:54 +08:00
										 |  |  | 	reqSignedIn := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true}) | 
					
						
							| 
									
										
										
										
											2015-01-16 21:32:18 +08:00
										 |  |  | 	reqGrafanaAdmin := middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true}) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	reqEditorRole := middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN) | 
					
						
							| 
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 |  |  | 	reqOrgAdmin := middleware.RoleAuth(m.ROLE_ADMIN) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 	quota := middleware.Quota | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	bind := binding.Bind | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 	// not logged in views
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	r.Get("/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-01-29 22:46:54 +08:00
										 |  |  | 	r.Get("/logout", Logout) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 	r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), wrap(LoginPost)) | 
					
						
							|  |  |  | 	r.Get("/login/:name", quota("session"), OAuthLogin) | 
					
						
							| 
									
										
										
										
											2015-01-27 17:09:54 +08:00
										 |  |  | 	r.Get("/login", LoginView) | 
					
						
							| 
									
										
										
										
											2015-08-10 19:46:59 +08:00
										 |  |  | 	r.Get("/invite/:code", Index) | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 	// authed views
 | 
					
						
							| 
									
										
										
										
											2015-01-20 02:10:29 +08:00
										 |  |  | 	r.Get("/profile/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-02-25 21:27:34 +08:00
										 |  |  | 	r.Get("/org/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-06-11 14:16:09 +08:00
										 |  |  | 	r.Get("/org/new", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-02-25 21:27:34 +08:00
										 |  |  | 	r.Get("/datasources/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-02-28 15:25:13 +08:00
										 |  |  | 	r.Get("/datasources/edit/*", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-02-25 21:27:34 +08:00
										 |  |  | 	r.Get("/org/users/", reqSignedIn, Index) | 
					
						
							|  |  |  | 	r.Get("/org/apikeys/", reqSignedIn, Index) | 
					
						
							|  |  |  | 	r.Get("/dashboard/import/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-02-12 22:46:14 +08:00
										 |  |  | 	r.Get("/admin/settings", reqGrafanaAdmin, Index) | 
					
						
							| 
									
										
										
										
											2015-01-28 18:33:50 +08:00
										 |  |  | 	r.Get("/admin/users", reqGrafanaAdmin, Index) | 
					
						
							| 
									
										
										
										
											2015-02-10 23:26:23 +08:00
										 |  |  | 	r.Get("/admin/users/create", reqGrafanaAdmin, Index) | 
					
						
							|  |  |  | 	r.Get("/admin/users/edit/:id", reqGrafanaAdmin, Index) | 
					
						
							| 
									
										
										
										
											2015-08-11 21:20:50 +08:00
										 |  |  | 	r.Get("/admin/orgs", reqGrafanaAdmin, Index) | 
					
						
							|  |  |  | 	r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index) | 
					
						
							| 
									
										
										
										
											2016-01-25 13:18:17 +08:00
										 |  |  | 	r.Get("/admin/stats", reqGrafanaAdmin, Index) | 
					
						
							| 
									
										
										
										
											2015-10-20 22:02:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 19:54:36 +08:00
										 |  |  | 	r.Get("/plugins", reqSignedIn, Index) | 
					
						
							|  |  |  | 	r.Get("/plugins/:id/edit", reqSignedIn, Index) | 
					
						
							|  |  |  | 	r.Get("/plugins/:id/page/:page", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-12-04 19:21:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	r.Get("/dashboard/*", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-10-20 22:02:56 +08:00
										 |  |  | 	r.Get("/dashboard-solo/*", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2014-12-16 19:04:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 |  |  | 	r.Get("/playlists/", reqSignedIn, Index) | 
					
						
							|  |  |  | 	r.Get("/playlists/*", reqSignedIn, Index) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 	// sign up
 | 
					
						
							| 
									
										
										
										
											2015-07-19 18:34:03 +08:00
										 |  |  | 	r.Get("/signup", Index) | 
					
						
							| 
									
										
										
										
											2015-08-31 17:35:07 +08:00
										 |  |  | 	r.Get("/api/user/signup/options", wrap(GetSignUpOptions)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 	r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), wrap(SignUp)) | 
					
						
							| 
									
										
										
										
											2015-08-28 15:24:30 +08:00
										 |  |  | 	r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), wrap(SignUpStep2)) | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 21:52:49 +08:00
										 |  |  | 	// invited
 | 
					
						
							|  |  |  | 	r.Get("/api/user/invite/:code", wrap(GetInviteInfoByCode)) | 
					
						
							| 
									
										
										
										
											2015-07-20 23:46:48 +08:00
										 |  |  | 	r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), wrap(CompleteInvite)) | 
					
						
							| 
									
										
										
										
											2015-07-20 21:52:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 16:57:01 +08:00
										 |  |  | 	// reset password
 | 
					
						
							|  |  |  | 	r.Get("/user/password/send-reset-email", Index) | 
					
						
							|  |  |  | 	r.Get("/user/password/reset", Index) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), wrap(SendResetPasswordEmail)) | 
					
						
							| 
									
										
										
										
											2015-06-08 19:39:02 +08:00
										 |  |  | 	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
 | 
					
						
							| 
									
										
										
										
											2015-04-15 16:39:03 +08:00
										 |  |  | 	r.Get("/dashboard/snapshot/*", Index) | 
					
						
							| 
									
										
										
										
											2016-01-19 21:05:24 +08:00
										 |  |  | 	r.Get("/dashboard/snapshots/", reqSignedIn, Index) | 
					
						
							| 
									
										
										
										
											2015-03-27 03:34:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-19 21:05:24 +08:00
										 |  |  | 	// api for dashboard snapshots
 | 
					
						
							|  |  |  | 	r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot) | 
					
						
							| 
									
										
										
										
											2015-10-14 22:39:57 +08:00
										 |  |  | 	r.Get("/api/snapshot/shared-options/", GetSharingOptions) | 
					
						
							| 
									
										
										
										
											2015-03-21 20:53:16 +08:00
										 |  |  | 	r.Get("/api/snapshots/:key", GetDashboardSnapshot) | 
					
						
							| 
									
										
										
										
											2015-03-27 03:34:58 +08:00
										 |  |  | 	r.Get("/api/snapshots-delete/:key", DeleteDashboardSnapshot) | 
					
						
							| 
									
										
										
										
											2015-03-21 20:53:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-07 15:25:00 +08:00
										 |  |  | 	// api renew session based on remember cookie
 | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 	r.Get("/api/login/ping", quota("session"), LoginApiPing) | 
					
						
							| 
									
										
										
										
											2015-04-07 15:25:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 	// authed api
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	r.Group("/api", func() { | 
					
						
							| 
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// user (signed in)
 | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 		r.Group("/user", func() { | 
					
						
							| 
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 |  |  | 			r.Get("/", wrap(GetSignedInUser)) | 
					
						
							| 
									
										
										
										
											2015-05-19 01:06:19 +08:00
										 |  |  | 			r.Put("/", bind(m.UpdateUserCommand{}), wrap(UpdateSignedInUser)) | 
					
						
							| 
									
										
										
										
											2015-05-20 20:59:38 +08:00
										 |  |  | 			r.Post("/using/:id", wrap(UserSetUsingOrg)) | 
					
						
							| 
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 |  |  | 			r.Get("/orgs", wrap(GetSignedInUserOrgList)) | 
					
						
							| 
									
										
										
										
											2015-05-20 20:59:38 +08:00
										 |  |  | 			r.Post("/stars/dashboard/:id", wrap(StarDashboard)) | 
					
						
							|  |  |  | 			r.Delete("/stars/dashboard/:id", wrap(UnstarDashboard)) | 
					
						
							|  |  |  | 			r.Put("/password", bind(m.ChangeUserPasswordCommand{}), wrap(ChangeUserPassword)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Get("/quotas", wrap(GetUserQuotas)) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 |  |  | 		// users (admin permission required)
 | 
					
						
							| 
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 |  |  | 		r.Group("/users", func() { | 
					
						
							| 
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 |  |  | 			r.Get("/", wrap(SearchUsers)) | 
					
						
							| 
									
										
										
										
											2015-05-19 01:06:19 +08:00
										 |  |  | 			r.Get("/:id", wrap(GetUserById)) | 
					
						
							| 
									
										
										
										
											2015-05-19 15:09:21 +08:00
										 |  |  | 			r.Get("/:id/orgs", wrap(GetUserOrgList)) | 
					
						
							| 
									
										
										
										
											2015-05-19 01:06:19 +08:00
										 |  |  | 			r.Put("/:id", bind(m.UpdateUserCommand{}), wrap(UpdateUser)) | 
					
						
							| 
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 |  |  | 		}, reqGrafanaAdmin) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 01:18:36 +08:00
										 |  |  | 		// org information available to all users.
 | 
					
						
							| 
									
										
										
										
											2015-02-24 01:29:01 +08:00
										 |  |  | 		r.Group("/org", func() { | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 			r.Get("/", wrap(GetOrgCurrent)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Get("/quotas", wrap(GetOrgQuotas)) | 
					
						
							| 
									
										
										
										
											2015-09-11 01:18:36 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// current org
 | 
					
						
							|  |  |  | 		r.Group("/org", func() { | 
					
						
							| 
									
										
										
										
											2015-09-08 20:22:44 +08:00
										 |  |  | 			r.Put("/", bind(dtos.UpdateOrgForm{}), wrap(UpdateOrgCurrent)) | 
					
						
							|  |  |  | 			r.Put("/address", bind(dtos.UpdateOrgAddressForm{}), wrap(UpdateOrgAddressCurrent)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Post("/users", quota("user"), bind(m.AddOrgUserCommand{}), wrap(AddOrgUserToCurrentOrg)) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 			r.Get("/users", wrap(GetOrgUsersForCurrentOrg)) | 
					
						
							|  |  |  | 			r.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), wrap(UpdateOrgUserForCurrentOrg)) | 
					
						
							|  |  |  | 			r.Delete("/users/:userId", wrap(RemoveOrgUserForCurrentOrg)) | 
					
						
							| 
									
										
										
										
											2015-07-17 15:51:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// invites
 | 
					
						
							|  |  |  | 			r.Get("/invites", wrap(GetPendingOrgInvites)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Post("/invites", quota("user"), bind(dtos.AddInviteForm{}), wrap(AddOrgInvite)) | 
					
						
							| 
									
										
										
										
											2015-07-20 23:46:48 +08:00
										 |  |  | 			r.Patch("/invites/:code/revoke", wrap(RevokeInvite)) | 
					
						
							| 
									
										
										
										
											2015-12-18 13:46:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 |  |  | 		}, reqOrgAdmin) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// create new org
 | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 		r.Post("/orgs", quota("org"), bind(m.CreateOrgCommand{}), wrap(CreateOrg)) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 |  |  | 		// search all orgs
 | 
					
						
							|  |  |  | 		r.Get("/orgs", reqGrafanaAdmin, wrap(SearchOrgs)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 		// orgs (admin routes)
 | 
					
						
							|  |  |  | 		r.Group("/orgs/:orgId", func() { | 
					
						
							| 
									
										
										
										
											2015-08-11 21:20:50 +08:00
										 |  |  | 			r.Get("/", wrap(GetOrgById)) | 
					
						
							| 
									
										
										
										
											2015-09-08 20:22:44 +08:00
										 |  |  | 			r.Put("/", bind(dtos.UpdateOrgForm{}), wrap(UpdateOrg)) | 
					
						
							|  |  |  | 			r.Put("/address", bind(dtos.UpdateOrgAddressForm{}), wrap(UpdateOrgAddress)) | 
					
						
							| 
									
										
										
										
											2015-08-12 14:59:25 +08:00
										 |  |  | 			r.Delete("/", wrap(DeleteOrgById)) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 			r.Get("/users", wrap(GetOrgUsers)) | 
					
						
							|  |  |  | 			r.Post("/users", bind(m.AddOrgUserCommand{}), wrap(AddOrgUser)) | 
					
						
							|  |  |  | 			r.Patch("/users/:userId", bind(m.UpdateOrgUserCommand{}), wrap(UpdateOrgUser)) | 
					
						
							|  |  |  | 			r.Delete("/users/:userId", wrap(RemoveOrgUser)) | 
					
						
							| 
									
										
										
										
											2015-07-20 20:51:27 +08:00
										 |  |  | 			r.Get("/quotas", wrap(GetOrgQuotas)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Put("/quotas/:target", bind(m.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)
 | 
					
						
							|  |  |  | 		r.Group("/orgs/name/:name", func() { | 
					
						
							|  |  |  | 			r.Get("/", wrap(GetOrgByName)) | 
					
						
							|  |  |  | 		}, reqGrafanaAdmin) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-27 15:26:11 +08:00
										 |  |  | 		// auth api keys
 | 
					
						
							|  |  |  | 		r.Group("/auth/keys", func() { | 
					
						
							| 
									
										
										
										
											2015-05-19 03:23:40 +08:00
										 |  |  | 			r.Get("/", wrap(GetApiKeys)) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Post("/", quota("api_key"), bind(m.AddApiKeyCommand{}), wrap(AddApiKey)) | 
					
						
							| 
									
										
										
										
											2015-05-19 03:23:40 +08:00
										 |  |  | 			r.Delete("/:id", wrap(DeleteApiKey)) | 
					
						
							| 
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 |  |  | 		}, reqOrgAdmin) | 
					
						
							| 
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 		// Data sources
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 		r.Group("/datasources", func() { | 
					
						
							| 
									
										
										
										
											2015-06-01 18:15:49 +08:00
										 |  |  | 			r.Get("/", GetDataSources) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 			r.Post("/", quota("data_source"), bind(m.AddDataSourceCommand{}), AddDataSource) | 
					
						
							| 
									
										
										
										
											2015-06-01 18:15:49 +08:00
										 |  |  | 			r.Put("/:id", bind(m.UpdateDataSourceCommand{}), UpdateDataSource) | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 			r.Delete("/:id", DeleteDataSource) | 
					
						
							| 
									
										
										
										
											2015-11-13 16:43:25 +08:00
										 |  |  | 			r.Get("/:id", wrap(GetDataSourceById)) | 
					
						
							| 
									
										
										
										
											2016-03-10 17:31:10 +08:00
										 |  |  | 			r.Get("/name/:name", wrap(GetDataSourceByName)) | 
					
						
							| 
									
										
										
										
											2015-12-03 23:43:55 +08:00
										 |  |  | 		}, reqOrgAdmin) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 17:31:10 +08:00
										 |  |  | 		r.Get("/datasources/id/:name", wrap(GetDataSourceIdByName), reqSignedIn) | 
					
						
							| 
									
										
										
										
											2016-03-08 04:25:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:57:20 +08:00
										 |  |  | 		r.Group("/plugins", func() { | 
					
						
							|  |  |  | 			r.Get("/", wrap(GetPluginList)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			r.Get("/dashboards/:pluginId", wrap(GetPluginDashboards)) | 
					
						
							|  |  |  | 			r.Post("/dashboards/install", bind(dtos.InstallPluginDashboardCmd{}), wrap(InstallPluginDashboard)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			r.Get("/:pluginId/settings", wrap(GetPluginSettingById)) | 
					
						
							|  |  |  | 			r.Post("/:pluginId/settings", bind(m.UpdatePluginSettingCmd{}), wrap(UpdatePluginSetting)) | 
					
						
							|  |  |  | 		}, reqOrgAdmin) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 21:06:44 +08:00
										 |  |  | 		r.Get("/frontend/settings/", GetFrontendSettings) | 
					
						
							| 
									
										
										
										
											2015-02-10 17:19:43 +08:00
										 |  |  | 		r.Any("/datasources/proxy/:id/*", reqSignedIn, ProxyDataSourceRequest) | 
					
						
							| 
									
										
										
										
											2015-05-20 05:47:39 +08:00
										 |  |  | 		r.Any("/datasources/proxy/:id", reqSignedIn, ProxyDataSourceRequest) | 
					
						
							| 
									
										
										
										
											2015-02-10 17:19:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 		// Dashboard
 | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 		r.Group("/dashboards", func() { | 
					
						
							|  |  |  | 			r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard) | 
					
						
							|  |  |  | 			r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard) | 
					
						
							| 
									
										
										
										
											2015-05-12 20:11:30 +08:00
										 |  |  | 			r.Get("/file/:file", GetDashboardFromJsonFile) | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 			r.Get("/home", GetHomeDashboard) | 
					
						
							| 
									
										
										
										
											2015-05-13 16:45:53 +08:00
										 |  |  | 			r.Get("/tags", GetDashboardTags) | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 		r.Group("/dashboard/snapshots", func() { | 
					
						
							|  |  |  | 			r.Get("/", wrap(SearchDashboardSnapshots)) | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2016-01-19 17:37:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 |  |  | 		// Playlist
 | 
					
						
							|  |  |  | 		r.Group("/playlists", func() { | 
					
						
							| 
									
										
										
										
											2016-01-08 21:21:30 +08:00
										 |  |  | 			r.Get("/", wrap(SearchPlaylists)) | 
					
						
							|  |  |  | 			r.Get("/:id", ValidateOrgPlaylist, wrap(GetPlaylist)) | 
					
						
							| 
									
										
										
										
											2016-01-12 21:36:04 +08:00
										 |  |  | 			r.Get("/:id/items", ValidateOrgPlaylist, wrap(GetPlaylistItems)) | 
					
						
							|  |  |  | 			r.Get("/:id/dashboards", ValidateOrgPlaylist, wrap(GetPlaylistDashboards)) | 
					
						
							| 
									
										
										
										
											2016-01-08 21:21:30 +08:00
										 |  |  | 			r.Delete("/:id", reqEditorRole, ValidateOrgPlaylist, wrap(DeletePlaylist)) | 
					
						
							| 
									
										
										
										
											2016-01-18 23:00:11 +08:00
										 |  |  | 			r.Put("/:id", reqEditorRole, bind(m.UpdatePlaylistCommand{}), ValidateOrgPlaylist, wrap(UpdatePlaylist)) | 
					
						
							|  |  |  | 			r.Post("/", reqEditorRole, bind(m.CreatePlaylistCommand{}), wrap(CreatePlaylist)) | 
					
						
							| 
									
										
										
										
											2015-12-22 18:07:15 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 		// Search
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 		r.Get("/search/", Search) | 
					
						
							| 
									
										
										
										
											2015-01-27 03:26:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 21:25:12 +08:00
										 |  |  | 		// metrics
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 		r.Get("/metrics/test", GetTestMetrics) | 
					
						
							| 
									
										
										
										
											2015-07-20 22:38:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-15 19:16:54 +08:00
										 |  |  | 	}, reqSignedIn) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// admin api
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	r.Group("/api/admin", func() { | 
					
						
							| 
									
										
										
										
											2015-02-12 22:46:14 +08:00
										 |  |  | 		r.Get("/settings", AdminGetSettings) | 
					
						
							| 
									
										
										
										
											2015-02-10 22:36:51 +08:00
										 |  |  | 		r.Post("/users", bind(dtos.AdminCreateUserForm{}), AdminCreateUser) | 
					
						
							| 
									
										
										
										
											2015-02-23 18:24:22 +08:00
										 |  |  | 		r.Put("/users/:id/password", bind(dtos.AdminUpdateUserPasswordForm{}), AdminUpdateUserPassword) | 
					
						
							| 
									
										
										
										
											2015-02-26 22:43:48 +08:00
										 |  |  | 		r.Put("/users/:id/permissions", bind(dtos.AdminUpdateUserPermissionsForm{}), AdminUpdateUserPermissions) | 
					
						
							| 
									
										
										
										
											2015-02-11 23:47:22 +08:00
										 |  |  | 		r.Delete("/users/:id", AdminDeleteUser) | 
					
						
							| 
									
										
										
										
											2015-09-11 23:17:10 +08:00
										 |  |  | 		r.Get("/users/:id/quotas", wrap(GetUserQuotas)) | 
					
						
							|  |  |  | 		r.Put("/users/:id/quotas/:target", bind(m.UpdateUserQuotaCmd{}), wrap(UpdateUserQuota)) | 
					
						
							| 
									
										
										
										
											2016-01-25 13:18:17 +08:00
										 |  |  | 		r.Get("/stats", AdminGetStats) | 
					
						
							| 
									
										
										
										
											2015-01-16 21:32:18 +08:00
										 |  |  | 	}, reqGrafanaAdmin) | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// rendering
 | 
					
						
							| 
									
										
										
										
											2015-01-16 18:54:19 +08:00
										 |  |  | 	r.Get("/render/*", reqSignedIn, RenderToPng) | 
					
						
							| 
									
										
										
										
											2015-01-06 16:11:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-21 06:51:22 +08:00
										 |  |  | 	// Gravatar service.
 | 
					
						
							|  |  |  | 	avt := avatar.CacheServer() | 
					
						
							|  |  |  | 	r.Get("/avatar/:hash", avt.ServeHTTP) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-22 01:15:04 +08:00
										 |  |  | 	InitAppPluginRoutes(r) | 
					
						
							| 
									
										
										
										
											2015-10-06 17:20:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-18 23:28:15 +08:00
										 |  |  | 	r.NotFound(NotFoundHandler) | 
					
						
							| 
									
										
										
										
											2014-12-16 04:25:02 +08:00
										 |  |  | } |