@ -4,13 +4,10 @@ package api
import (
"time"
"github.com/go-macaron/binding"
"github.com/grafana/grafana/pkg/api/avatar"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/api/frontendlogging"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
@ -35,7 +32,6 @@ func (hs *HTTPServer) registerRoutes() {
authorize := acmiddleware . Middleware ( hs . AccessControl )
authorizeInOrg := acmiddleware . AuthorizeInOrgMiddleware ( hs . AccessControl , hs . SQLStore )
quota := middleware . Quota ( hs . QuotaService )
bind := binding . Bind
r := hs . RouteRegister
@ -116,19 +112,19 @@ func (hs *HTTPServer) registerRoutes() {
r . Get ( "/verify" , hs . Index )
r . Get ( "/signup" , hs . Index )
r . Get ( "/api/user/signup/options" , routing . Wrap ( GetSignUpOptions ) )
r . Post ( "/api/user/signup" , quota ( "user" ) , bind ( dtos . SignUpForm { } ) , routing . Wrap ( SignUp ) )
r . Post ( "/api/user/signup/step2" , bind ( dtos . SignUpStep2Form { } ) , routing . Wrap ( hs . SignUpStep2 ) )
r . Post ( "/api/user/signup" , quota ( "user" ) , routing . Wrap ( SignUp ) )
r . Post ( "/api/user/signup/step2" , routing . Wrap ( hs . SignUpStep2 ) )
// invited
r . Get ( "/api/user/invite/:code" , routing . Wrap ( GetInviteInfoByCode ) )
r . Post ( "/api/user/invite/complete" , bind ( dtos . CompleteInviteForm { } ) , routing . Wrap ( hs . CompleteInvite ) )
r . Post ( "/api/user/invite/complete" , routing . Wrap ( hs . CompleteInvite ) )
// reset password
r . Get ( "/user/password/send-reset-email" , reqNotSignedIn , hs . Index )
r . Get ( "/user/password/reset" , hs . Index )
r . Post ( "/api/user/password/send-reset-email" , bind ( dtos . SendResetPasswordEmailForm { } ) , routing . Wrap ( SendResetPasswordEmail ) )
r . Post ( "/api/user/password/reset" , bind ( dtos . ResetUserPasswordForm { } ) , routing . Wrap ( ResetPassword ) )
r . Post ( "/api/user/password/send-reset-email" , routing . Wrap ( SendResetPasswordEmail ) )
r . Post ( "/api/user/password/reset" , routing . Wrap ( ResetPassword ) )
// dashboard snapshots
r . Get ( "/dashboard/snapshot/*" , reqNoAuth , hs . Index )
@ -145,7 +141,7 @@ func (hs *HTTPServer) registerRoutes() {
// user (signed in)
apiRoute . Group ( "/user" , func ( userRoute routing . RouteRegister ) {
userRoute . Get ( "/" , routing . Wrap ( GetSignedInUser ) )
userRoute . Put ( "/" , bind ( models . UpdateUserCommand { } ) , routing . Wrap ( UpdateSignedInUser ) )
userRoute . Put ( "/" , routing . Wrap ( UpdateSignedInUser ) )
userRoute . Post ( "/using/:id" , routing . Wrap ( UserSetUsingOrg ) )
userRoute . Get ( "/orgs" , routing . Wrap ( GetSignedInUserOrgList ) )
userRoute . Get ( "/teams" , routing . Wrap ( GetSignedInUserTeamList ) )
@ -153,17 +149,17 @@ func (hs *HTTPServer) registerRoutes() {
userRoute . Post ( "/stars/dashboard/:id" , routing . Wrap ( StarDashboard ) )
userRoute . Delete ( "/stars/dashboard/:id" , routing . Wrap ( UnstarDashboard ) )
userRoute . Put ( "/password" , bind ( models . ChangeUserPasswordCommand { } ) , routing . Wrap ( ChangeUserPassword ) )
userRoute . Put ( "/password" , routing . Wrap ( ChangeUserPassword ) )
userRoute . Get ( "/quotas" , routing . Wrap ( GetUserQuotas ) )
userRoute . Put ( "/helpflags/:id" , routing . Wrap ( SetHelpFlag ) )
// For dev purpose
userRoute . Get ( "/helpflags/clear" , routing . Wrap ( ClearHelpFlags ) )
userRoute . Get ( "/preferences" , routing . Wrap ( hs . GetUserPreferences ) )
userRoute . Put ( "/preferences" , bind ( dtos . UpdatePrefsCmd { } ) , routing . Wrap ( hs . UpdateUserPreferences ) )
userRoute . Put ( "/preferences" , routing . Wrap ( hs . UpdateUserPreferences ) )
userRoute . Get ( "/auth-tokens" , routing . Wrap ( hs . GetUserAuthTokens ) )
userRoute . Post ( "/revoke-auth-token" , bind ( models . RevokeAuthTokenCmd { } ) , routing . Wrap ( hs . RevokeUserAuthToken ) )
userRoute . Post ( "/revoke-auth-token" , routing . Wrap ( hs . RevokeUserAuthToken ) )
} , reqSignedInNoAnonymous )
apiRoute . Group ( "/users" , func ( usersRoute routing . RouteRegister ) {
@ -175,21 +171,21 @@ func (hs *HTTPServer) registerRoutes() {
usersRoute . Get ( "/:id/orgs" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersRead , userIDScope ) ) , routing . Wrap ( GetUserOrgList ) )
// query parameters /users/lookup?loginOrEmail=admin@example.com
usersRoute . Get ( "/lookup" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersRead , ac . ScopeGlobalUsersAll ) ) , routing . Wrap ( GetUserByLoginOrEmail ) )
usersRoute . Put ( "/:id" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersWrite , userIDScope ) ) , bind ( models . UpdateUserCommand { } ) , routing . Wrap ( UpdateUser ) )
usersRoute . Put ( "/:id" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersWrite , userIDScope ) ) , routing . Wrap ( UpdateUser ) )
usersRoute . Post ( "/:id/using/:orgId" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersWrite , userIDScope ) ) , routing . Wrap ( UpdateUserActiveOrg ) )
} )
// team (admin permission required)
apiRoute . Group ( "/teams" , func ( teamsRoute routing . RouteRegister ) {
teamsRoute . Post ( "/" , bind ( models . CreateTeamCommand { } ) , routing . Wrap ( hs . CreateTeam ) )
teamsRoute . Put ( "/:teamId" , bind ( models . UpdateTeamCommand { } ) , routing . Wrap ( hs . UpdateTeam ) )
teamsRoute . Post ( "/" , routing . Wrap ( hs . CreateTeam ) )
teamsRoute . Put ( "/:teamId" , routing . Wrap ( hs . UpdateTeam ) )
teamsRoute . Delete ( "/:teamId" , routing . Wrap ( hs . DeleteTeamByID ) )
teamsRoute . Get ( "/:teamId/members" , routing . Wrap ( hs . GetTeamMembers ) )
teamsRoute . Post ( "/:teamId/members" , bind ( models . AddTeamMemberCommand { } ) , routing . Wrap ( hs . AddTeamMember ) )
teamsRoute . Put ( "/:teamId/members/:userId" , bind ( models . UpdateTeamMemberCommand { } ) , routing . Wrap ( hs . UpdateTeamMember ) )
teamsRoute . Post ( "/:teamId/members" , routing . Wrap ( hs . AddTeamMember ) )
teamsRoute . Put ( "/:teamId/members/:userId" , routing . Wrap ( hs . UpdateTeamMember ) )
teamsRoute . Delete ( "/:teamId/members/:userId" , routing . Wrap ( hs . RemoveTeamMember ) )
teamsRoute . Get ( "/:teamId/preferences" , routing . Wrap ( hs . GetTeamPreferences ) )
teamsRoute . Put ( "/:teamId/preferences" , bind ( dtos . UpdatePrefsCmd { } ) , routing . Wrap ( hs . UpdateTeamPreferences ) )
teamsRoute . Put ( "/:teamId/preferences" , routing . Wrap ( hs . UpdateTeamPreferences ) )
} , reqCanAccessTeams )
// team without requirement of user to be org admin
@ -207,22 +203,22 @@ func (hs *HTTPServer) registerRoutes() {
// current org
apiRoute . Group ( "/org" , func ( orgRoute routing . RouteRegister ) {
userIDScope := ac . Scope ( "users" , "id" , ac . Parameter ( ":userId" ) )
orgRoute . Put ( "/" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsWrite ) ) , bind ( dtos . UpdateOrgForm { } ) , routing . Wrap ( UpdateCurrentOrg ) )
orgRoute . Put ( "/address" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsWrite ) ) , bind ( dtos . UpdateOrgAddressForm { } ) , routing . Wrap ( UpdateCurrentOrgAddress ) )
orgRoute . Put ( "/" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsWrite ) ) , routing . Wrap ( UpdateCurrentOrg ) )
orgRoute . Put ( "/address" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsWrite ) ) , routing . Wrap ( UpdateCurrentOrgAddress ) )
orgRoute . Get ( "/users" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersRead , ac . ScopeUsersAll ) ) , routing . Wrap ( hs . GetOrgUsersForCurrentOrg ) )
orgRoute . Get ( "/users/search" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersRead , ac . ScopeUsersAll ) ) , routing . Wrap ( hs . SearchOrgUsersWithPaging ) )
orgRoute . Post ( "/users" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersAdd , ac . ScopeUsersAll ) ) , quota ( "user" ) , bind ( models . AddOrgUserCommand { } ) , routing . Wrap ( hs . AddOrgUserToCurrentOrg ) )
orgRoute . Patch ( "/users/:userId" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersRoleUpdate , userIDScope ) ) , bind ( models . UpdateOrgUserCommand { } ) , routing . Wrap ( hs . UpdateOrgUserForCurrentOrg ) )
orgRoute . Post ( "/users" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersAdd , ac . ScopeUsersAll ) ) , quota ( "user" ) , routing . Wrap ( hs . AddOrgUserToCurrentOrg ) )
orgRoute . Patch ( "/users/:userId" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersRoleUpdate , userIDScope ) ) , routing . Wrap ( hs . UpdateOrgUserForCurrentOrg ) )
orgRoute . Delete ( "/users/:userId" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionOrgUsersRemove , userIDScope ) ) , routing . Wrap ( hs . RemoveOrgUserForCurrentOrg ) )
// invites
orgRoute . Get ( "/invites" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , routing . Wrap ( GetPendingOrgInvites ) )
orgRoute . Post ( "/invites" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , quota ( "user" ) , bind ( dtos . AddInviteForm { } ) , routing . Wrap ( AddOrgInvite ) )
orgRoute . Post ( "/invites" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , quota ( "user" ) , routing . Wrap ( AddOrgInvite ) )
orgRoute . Patch ( "/invites/:code/revoke" , authorize ( reqOrgAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , routing . Wrap ( RevokeInvite ) )
// prefs
orgRoute . Get ( "/preferences" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsPreferencesRead ) ) , routing . Wrap ( hs . GetOrgPreferences ) )
orgRoute . Put ( "/preferences" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsPreferencesWrite ) ) , bind ( dtos . UpdatePrefsCmd { } ) , routing . Wrap ( hs . UpdateOrgPreferences ) )
orgRoute . Put ( "/preferences" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionOrgsPreferencesWrite ) ) , routing . Wrap ( hs . UpdateOrgPreferences ) )
} )
// current org without requirement of user to be org admin
@ -231,7 +227,7 @@ func (hs *HTTPServer) registerRoutes() {
} )
// create new org
apiRoute . Post ( "/orgs" , authorizeInOrg ( reqSignedIn , acmiddleware . UseGlobalOrg , ac . EvalPermission ( ActionOrgsCreate ) ) , quota ( "org" ) , bind ( models . CreateOrgCommand { } ) , routing . Wrap ( hs . CreateOrg ) )
apiRoute . Post ( "/orgs" , authorizeInOrg ( reqSignedIn , acmiddleware . UseGlobalOrg , ac . EvalPermission ( ActionOrgsCreate ) ) , quota ( "org" ) , routing . Wrap ( hs . CreateOrg ) )
// search all orgs
apiRoute . Get ( "/orgs" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseGlobalOrg , ac . EvalPermission ( ActionOrgsRead ) ) , routing . Wrap ( SearchOrgs ) )
@ -240,15 +236,15 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute . Group ( "/orgs/:orgId" , func ( orgsRoute routing . RouteRegister ) {
userIDScope := ac . Scope ( "users" , "id" , ac . Parameter ( ":userId" ) )
orgsRoute . Get ( "/" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsRead ) ) , routing . Wrap ( GetOrgByID ) )
orgsRoute . Put ( "/" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsWrite ) ) , bind ( dtos . UpdateOrgForm { } ) , routing . Wrap ( UpdateOrg ) )
orgsRoute . Put ( "/address" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsWrite ) ) , bind ( dtos . UpdateOrgAddressForm { } ) , routing . Wrap ( UpdateOrgAddress ) )
orgsRoute . Put ( "/" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsWrite ) ) , routing . Wrap ( UpdateOrg ) )
orgsRoute . Put ( "/address" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsWrite ) ) , routing . Wrap ( UpdateOrgAddress ) )
orgsRoute . Delete ( "/" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsDelete ) ) , routing . Wrap ( DeleteOrgByID ) )
orgsRoute . Get ( "/users" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersRead , ac . ScopeUsersAll ) ) , routing . Wrap ( hs . GetOrgUsers ) )
orgsRoute . Post ( "/users" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersAdd , ac . ScopeUsersAll ) ) , bind ( models . AddOrgUserCommand { } ) , routing . Wrap ( hs . AddOrgUser ) )
orgsRoute . Patch ( "/users/:userId" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersRoleUpdate , userIDScope ) ) , bind ( models . UpdateOrgUserCommand { } ) , routing . Wrap ( hs . UpdateOrgUser ) )
orgsRoute . Post ( "/users" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersAdd , ac . ScopeUsersAll ) ) , routing . Wrap ( hs . AddOrgUser ) )
orgsRoute . Patch ( "/users/:userId" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersRoleUpdate , userIDScope ) ) , routing . Wrap ( hs . UpdateOrgUser ) )
orgsRoute . Delete ( "/users/:userId" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ac . ActionOrgUsersRemove , userIDScope ) ) , routing . Wrap ( hs . RemoveOrgUser ) )
orgsRoute . Get ( "/quotas" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsQuotasRead ) ) , routing . Wrap ( hs . GetOrgQuotas ) )
orgsRoute . Put ( "/quotas/:target" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsQuotasWrite ) ) , bind ( models . UpdateOrgQuotaCmd { } ) , routing . Wrap ( hs . UpdateOrgQuota ) )
orgsRoute . Put ( "/quotas/:target" , authorizeInOrg ( reqGrafanaAdmin , acmiddleware . UseOrgFromContextParams , ac . EvalPermission ( ActionOrgsQuotasWrite ) ) , routing . Wrap ( hs . UpdateOrgQuota ) )
} )
// orgs (admin routes)
@ -257,21 +253,21 @@ func (hs *HTTPServer) registerRoutes() {
// auth api keys
apiRoute . Group ( "/auth/keys" , func ( keysRoute routing . RouteRegister ) {
keysRoute . Get ( "/" , routing . Wrap ( GetAPIKeys ) )
keysRoute . Post ( "/" , quota ( "api_key" ) , bind ( models . AddApiKeyCommand { } ) , routing . Wrap ( hs . AddAPIKey ) )
keysRoute . Post ( "/additional" , quota ( "api_key" ) , bind ( models . AddApiKeyCommand { } ) , routing . Wrap ( hs . AdditionalAPIKey ) )
keysRoute . Post ( "/" , quota ( "api_key" ) , routing . Wrap ( hs . AddAPIKey ) )
keysRoute . Post ( "/additional" , quota ( "api_key" ) , routing . Wrap ( hs . AdditionalAPIKey ) )
keysRoute . Delete ( "/:id" , routing . Wrap ( DeleteAPIKey ) )
} , reqOrgAdmin )
// Preferences
apiRoute . Group ( "/preferences" , func ( prefRoute routing . RouteRegister ) {
prefRoute . Post ( "/set-home-dash" , bind ( models . SavePreferencesCommand { } ) , routing . Wrap ( SetHomeDashboard ) )
prefRoute . Post ( "/set-home-dash" , routing . Wrap ( SetHomeDashboard ) )
} )
// Data sources
apiRoute . Group ( "/datasources" , func ( datasourceRoute routing . RouteRegister ) {
datasourceRoute . Get ( "/" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesRead , ScopeDatasourcesAll ) ) , routing . Wrap ( hs . GetDataSources ) )
datasourceRoute . Post ( "/" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesCreate ) ) , quota ( "data_source" ) , bind ( models . AddDataSourceCommand { } ) , routing . Wrap ( AddDataSource ) )
datasourceRoute . Put ( "/:id" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesWrite , ScopeDatasourceID ) ) , bind ( models . UpdateDataSourceCommand { } ) , routing . Wrap ( hs . UpdateDataSource ) )
datasourceRoute . Post ( "/" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesCreate ) ) , quota ( "data_source" ) , routing . Wrap ( AddDataSource ) )
datasourceRoute . Put ( "/:id" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesWrite , ScopeDatasourceID ) ) , routing . Wrap ( hs . UpdateDataSource ) )
datasourceRoute . Delete ( "/:id" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesDelete , ScopeDatasourceID ) ) , routing . Wrap ( hs . DeleteDataSourceById ) )
datasourceRoute . Delete ( "/uid/:uid" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesDelete , ScopeDatasourceUID ) ) , routing . Wrap ( hs . DeleteDataSourceByUID ) )
datasourceRoute . Delete ( "/name/:name" , authorize ( reqOrgAdmin , ac . EvalPermission ( ActionDatasourcesDelete , ScopeDatasourceName ) ) , routing . Wrap ( hs . DeleteDataSourceByName ) )
@ -291,13 +287,13 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute . Get ( "/plugins/errors" , routing . Wrap ( hs . GetPluginErrorsList ) )
apiRoute . Group ( "/plugins" , func ( pluginRoute routing . RouteRegister ) {
pluginRoute . Post ( "/:pluginId/install" , bind ( dtos . InstallPluginCommand { } ) , routing . Wrap ( hs . InstallPlugin ) )
pluginRoute . Post ( "/:pluginId/install" , routing . Wrap ( hs . InstallPlugin ) )
pluginRoute . Post ( "/:pluginId/uninstall" , routing . Wrap ( hs . UninstallPlugin ) )
} , reqGrafanaAdmin )
apiRoute . Group ( "/plugins" , func ( pluginRoute routing . RouteRegister ) {
pluginRoute . Get ( "/:pluginId/dashboards/" , routing . Wrap ( hs . GetPluginDashboards ) )
pluginRoute . Post ( "/:pluginId/settings" , bind ( models . UpdatePluginSettingCmd { } ) , routing . Wrap ( hs . UpdatePluginSetting ) )
pluginRoute . Post ( "/:pluginId/settings" , routing . Wrap ( hs . UpdatePluginSetting ) )
pluginRoute . Get ( "/:pluginId/metrics" , routing . Wrap ( hs . CollectPluginMetrics ) )
} , reqOrgAdmin )
@ -312,16 +308,16 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute . Group ( "/folders" , func ( folderRoute routing . RouteRegister ) {
folderRoute . Get ( "/" , routing . Wrap ( hs . GetFolders ) )
folderRoute . Get ( "/id/:id" , routing . Wrap ( hs . GetFolderByID ) )
folderRoute . Post ( "/" , bind ( models . CreateFolderCommand { } ) , routing . Wrap ( hs . CreateFolder ) )
folderRoute . Post ( "/" , routing . Wrap ( hs . CreateFolder ) )
folderRoute . Group ( "/:uid" , func ( folderUidRoute routing . RouteRegister ) {
folderUidRoute . Get ( "/" , routing . Wrap ( hs . GetFolderByUID ) )
folderUidRoute . Put ( "/" , bind ( models . UpdateFolderCommand { } ) , routing . Wrap ( hs . UpdateFolder ) )
folderUidRoute . Put ( "/" , routing . Wrap ( hs . UpdateFolder ) )
folderUidRoute . Delete ( "/" , routing . Wrap ( hs . DeleteFolder ) )
folderUidRoute . Group ( "/permissions" , func ( folderPermissionRoute routing . RouteRegister ) {
folderPermissionRoute . Get ( "/" , routing . Wrap ( hs . GetFolderPermissionList ) )
folderPermissionRoute . Post ( "/" , bind ( dtos . UpdateDashboardAclCommand { } ) , routing . Wrap ( hs . UpdateFolderPermissions ) )
folderPermissionRoute . Post ( "/" , routing . Wrap ( hs . UpdateFolderPermissions ) )
} )
} )
} )
@ -331,22 +327,22 @@ func (hs *HTTPServer) registerRoutes() {
dashboardRoute . Get ( "/uid/:uid" , routing . Wrap ( hs . GetDashboard ) )
dashboardRoute . Delete ( "/uid/:uid" , routing . Wrap ( hs . DeleteDashboardByUID ) )
dashboardRoute . Post ( "/calculate-diff" , bind ( dtos . CalculateDiffOptions { } ) , routing . Wrap ( CalculateDashboardDiff ) )
dashboardRoute . Post ( "/trim" , bind ( models . TrimDashboardCommand { } ) , routing . Wrap ( hs . TrimDashboard ) )
dashboardRoute . Post ( "/calculate-diff" , routing . Wrap ( CalculateDashboardDiff ) )
dashboardRoute . Post ( "/trim" , routing . Wrap ( hs . TrimDashboard ) )
dashboardRoute . Post ( "/db" , bind ( models . SaveDashboardCommand { } ) , routing . Wrap ( hs . PostDashboard ) )
dashboardRoute . Post ( "/db" , routing . Wrap ( hs . PostDashboard ) )
dashboardRoute . Get ( "/home" , routing . Wrap ( hs . GetHomeDashboard ) )
dashboardRoute . Get ( "/tags" , GetDashboardTags )
dashboardRoute . Post ( "/import" , bind ( dtos . ImportDashboardCommand { } ) , routing . Wrap ( hs . ImportDashboard ) )
dashboardRoute . Post ( "/import" , routing . Wrap ( hs . ImportDashboard ) )
dashboardRoute . Group ( "/id/:dashboardId" , func ( dashIdRoute routing . RouteRegister ) {
dashIdRoute . Get ( "/versions" , routing . Wrap ( GetDashboardVersions ) )
dashIdRoute . Get ( "/versions/:id" , routing . Wrap ( GetDashboardVersion ) )
dashIdRoute . Post ( "/restore" , bind ( dtos . RestoreDashboardVersionCommand { } ) , routing . Wrap ( hs . RestoreDashboardVersion ) )
dashIdRoute . Post ( "/restore" , routing . Wrap ( hs . RestoreDashboardVersion ) )
dashIdRoute . Group ( "/permissions" , func ( dashboardPermissionRoute routing . RouteRegister ) {
dashboardPermissionRoute . Get ( "/" , routing . Wrap ( hs . GetDashboardPermissionList ) )
dashboardPermissionRoute . Post ( "/" , bind ( dtos . UpdateDashboardAclCommand { } ) , routing . Wrap ( hs . UpdateDashboardPermissions ) )
dashboardPermissionRoute . Post ( "/" , routing . Wrap ( hs . UpdateDashboardPermissions ) )
} )
} )
} )
@ -363,8 +359,8 @@ func (hs *HTTPServer) registerRoutes() {
playlistRoute . Get ( "/:id/items" , ValidateOrgPlaylist , routing . Wrap ( GetPlaylistItems ) )
playlistRoute . Get ( "/:id/dashboards" , ValidateOrgPlaylist , routing . Wrap ( GetPlaylistDashboards ) )
playlistRoute . Delete ( "/:id" , reqEditorRole , ValidateOrgPlaylist , routing . Wrap ( DeletePlaylist ) )
playlistRoute . Put ( "/:id" , reqEditorRole , bind ( models . UpdatePlaylistCommand { } ) , ValidateOrgPlaylist , routing . Wrap ( UpdatePlaylist ) )
playlistRoute . Post ( "/" , reqEditorRole , bind ( models . CreatePlaylistCommand { } ) , routing . Wrap ( CreatePlaylist ) )
playlistRoute . Put ( "/:id" , reqEditorRole , ValidateOrgPlaylist , routing . Wrap ( UpdatePlaylist ) )
playlistRoute . Post ( "/" , reqEditorRole , routing . Wrap ( CreatePlaylist ) )
} )
// Search
@ -372,14 +368,14 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute . Get ( "/search/" , routing . Wrap ( Search ) )
// metrics
apiRoute . Post ( "/tsdb/query" , authorize ( reqSignedIn , ac . EvalPermission ( ActionDatasourcesQuery ) ) , bind ( dtos . MetricRequest { } ) , routing . Wrap ( hs . QueryMetrics ) )
apiRoute . Post ( "/tsdb/query" , authorize ( reqSignedIn , ac . EvalPermission ( ActionDatasourcesQuery ) ) , routing . Wrap ( hs . QueryMetrics ) )
// DataSource w/ expressions
apiRoute . Post ( "/ds/query" , authorize ( reqSignedIn , ac . EvalPermission ( ActionDatasourcesQuery ) ) , bind ( dtos . MetricRequest { } ) , routing . Wrap ( hs . QueryMetricsV2 ) )
apiRoute . Post ( "/ds/query" , authorize ( reqSignedIn , ac . EvalPermission ( ActionDatasourcesQuery ) ) , routing . Wrap ( hs . QueryMetricsV2 ) )
apiRoute . Group ( "/alerts" , func ( alertsRoute routing . RouteRegister ) {
alertsRoute . Post ( "/test" , bind ( dtos . AlertTestCommand { } ) , routing . Wrap ( hs . AlertTest ) )
alertsRoute . Post ( "/:alertId/pause" , reqEditorRole , bind ( dtos . PauseAlertCommand { } ) , routing . Wrap ( PauseAlert ) )
alertsRoute . Post ( "/test" , routing . Wrap ( hs . AlertTest ) )
alertsRoute . Post ( "/:alertId/pause" , reqEditorRole , routing . Wrap ( PauseAlert ) )
alertsRoute . Get ( "/:alertId" , ValidateOrgAlert , routing . Wrap ( GetAlert ) )
alertsRoute . Get ( "/" , routing . Wrap ( GetAlerts ) )
alertsRoute . Get ( "/states-for-dashboard" , routing . Wrap ( GetAlertStatesForDashboard ) )
@ -391,13 +387,13 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute . Group ( "/alert-notifications" , func ( alertNotifications routing . RouteRegister ) {
alertNotifications . Get ( "/" , routing . Wrap ( GetAlertNotifications ) )
alertNotifications . Post ( "/test" , bind ( dtos . NotificationTestCommand { } ) , routing . Wrap ( NotificationTest ) )
alertNotifications . Post ( "/" , bind ( models . CreateAlertNotificationCommand { } ) , routing . Wrap ( CreateAlertNotification ) )
alertNotifications . Put ( "/:notificationId" , bind ( models . UpdateAlertNotificationCommand { } ) , routing . Wrap ( hs . UpdateAlertNotification ) )
alertNotifications . Post ( "/test" , routing . Wrap ( NotificationTest ) )
alertNotifications . Post ( "/" , routing . Wrap ( CreateAlertNotification ) )
alertNotifications . Put ( "/:notificationId" , routing . Wrap ( hs . UpdateAlertNotification ) )
alertNotifications . Get ( "/:notificationId" , routing . Wrap ( GetAlertNotificationByID ) )
alertNotifications . Delete ( "/:notificationId" , routing . Wrap ( DeleteAlertNotification ) )
alertNotifications . Get ( "/uid/:uid" , routing . Wrap ( GetAlertNotificationByUID ) )
alertNotifications . Put ( "/uid/:uid" , bind ( models . UpdateAlertNotificationWithUidCommand { } ) , routing . Wrap ( hs . UpdateAlertNotificationByUID ) )
alertNotifications . Put ( "/uid/:uid" , routing . Wrap ( hs . UpdateAlertNotificationByUID ) )
alertNotifications . Delete ( "/uid/:uid" , routing . Wrap ( DeleteAlertNotificationByUID ) )
} , reqEditorRole )
@ -407,22 +403,22 @@ func (hs *HTTPServer) registerRoutes() {
} )
apiRoute . Get ( "/annotations" , routing . Wrap ( GetAnnotations ) )
apiRoute . Post ( "/annotations/mass-delete" , reqOrgAdmin , bind ( dtos . DeleteAnnotationsCmd { } ) , routing . Wrap ( DeleteAnnotations ) )
apiRoute . Post ( "/annotations/mass-delete" , reqOrgAdmin , routing . Wrap ( DeleteAnnotations ) )
apiRoute . Group ( "/annotations" , func ( annotationsRoute routing . RouteRegister ) {
annotationsRoute . Post ( "/" , bind ( dtos . PostAnnotationsCmd { } ) , routing . Wrap ( PostAnnotation ) )
annotationsRoute . Post ( "/" , routing . Wrap ( PostAnnotation ) )
annotationsRoute . Delete ( "/:annotationId" , routing . Wrap ( DeleteAnnotationByID ) )
annotationsRoute . Put ( "/:annotationId" , bind ( dtos . UpdateAnnotationsCmd { } ) , routing . Wrap ( UpdateAnnotation ) )
annotationsRoute . Patch ( "/:annotationId" , bind ( dtos . PatchAnnotationsCmd { } ) , routing . Wrap ( PatchAnnotation ) )
annotationsRoute . Post ( "/graphite" , reqEditorRole , bind ( dtos . PostGraphiteAnnotationsCmd { } ) , routing . Wrap ( PostGraphiteAnnotation ) )
annotationsRoute . Put ( "/:annotationId" , routing . Wrap ( UpdateAnnotation ) )
annotationsRoute . Patch ( "/:annotationId" , routing . Wrap ( PatchAnnotation ) )
annotationsRoute . Post ( "/graphite" , reqEditorRole , routing . Wrap ( PostGraphiteAnnotation ) )
annotationsRoute . Get ( "/tags" , routing . Wrap ( GetAnnotationTags ) )
} )
apiRoute . Post ( "/frontend-metrics" , bind ( metrics . PostFrontendMetricsCommand { } ) , routing . Wrap ( hs . PostFrontendMetrics ) )
apiRoute . Post ( "/frontend-metrics" , routing . Wrap ( hs . PostFrontendMetrics ) )
apiRoute . Group ( "/live" , func ( liveRoute routing . RouteRegister ) {
// the channel path is in the name
liveRoute . Post ( "/publish" , bind ( dtos . LivePublishCmd { } ) , routing . Wrap ( hs . Live . HandleHTTPPublish ) )
liveRoute . Post ( "/publish" , routing . Wrap ( hs . Live . HandleHTTPPublish ) )
// POST influx line protocol.
liveRoute . Post ( "/push/:streamId" , hs . LivePushGateway . Handle )
@ -450,14 +446,14 @@ func (hs *HTTPServer) registerRoutes() {
} )
// short urls
apiRoute . Post ( "/short-urls" , bind ( dtos . CreateShortURLCmd { } ) , routing . Wrap ( hs . createShortURL ) )
apiRoute . Post ( "/short-urls" , routing . Wrap ( hs . createShortURL ) )
} , reqSignedIn )
// admin api
r . Group ( "/api/admin" , func ( adminRoute routing . RouteRegister ) {
adminRoute . Get ( "/settings" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionSettingsRead ) ) , routing . Wrap ( hs . AdminGetSettings ) )
adminRoute . Get ( "/stats" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionServerStatsRead ) ) , routing . Wrap ( AdminGetStats ) )
adminRoute . Post ( "/pause-all-alerts" , reqGrafanaAdmin , bind ( dtos . PauseAllAlertsCommand { } ) , routing . Wrap ( PauseAllAlerts ) )
adminRoute . Post ( "/pause-all-alerts" , reqGrafanaAdmin , routing . Wrap ( PauseAllAlerts ) )
adminRoute . Post ( "/provisioning/dashboards/reload" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ActionProvisioningReload , ScopeProvisionersDashboards ) ) , routing . Wrap ( hs . AdminProvisioningReloadDashboards ) )
adminRoute . Post ( "/provisioning/plugins/reload" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ActionProvisioningReload , ScopeProvisionersPlugins ) ) , routing . Wrap ( hs . AdminProvisioningReloadPlugins ) )
@ -474,18 +470,18 @@ func (hs *HTTPServer) registerRoutes() {
r . Group ( "/api/admin/users" , func ( adminUserRoute routing . RouteRegister ) {
userIDScope := ac . Scope ( "global" , "users" , "id" , ac . Parameter ( ":id" ) )
adminUserRoute . Post ( "/" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , bind ( dtos . AdminCreateUserForm { } ) , routing . Wrap ( hs . AdminCreateUser ) )
adminUserRoute . Put ( "/:id/password" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersPasswordUpdate , userIDScope ) ) , bind ( dtos . AdminUpdateUserPasswordForm { } ) , routing . Wrap ( AdminUpdateUserPassword ) )
adminUserRoute . Put ( "/:id/permissions" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersPermissionsUpdate , userIDScope ) ) , bind ( dtos . AdminUpdateUserPermissionsForm { } ) , routing . Wrap ( hs . AdminUpdateUserPermissions ) )
adminUserRoute . Post ( "/" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersCreate ) ) , routing . Wrap ( hs . AdminCreateUser ) )
adminUserRoute . Put ( "/:id/password" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersPasswordUpdate , userIDScope ) ) , routing . Wrap ( AdminUpdateUserPassword ) )
adminUserRoute . Put ( "/:id/permissions" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersPermissionsUpdate , userIDScope ) ) , routing . Wrap ( hs . AdminUpdateUserPermissions ) )
adminUserRoute . Delete ( "/:id" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersDelete , userIDScope ) ) , routing . Wrap ( AdminDeleteUser ) )
adminUserRoute . Post ( "/:id/disable" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersDisable , userIDScope ) ) , routing . Wrap ( hs . AdminDisableUser ) )
adminUserRoute . Post ( "/:id/enable" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersEnable , userIDScope ) ) , routing . Wrap ( AdminEnableUser ) )
adminUserRoute . Get ( "/:id/quotas" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersQuotasList , userIDScope ) ) , routing . Wrap ( GetUserQuotas ) )
adminUserRoute . Put ( "/:id/quotas/:target" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersQuotasUpdate , userIDScope ) ) , bind ( models . UpdateUserQuotaCmd { } ) , routing . Wrap ( UpdateUserQuota ) )
adminUserRoute . Put ( "/:id/quotas/:target" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersQuotasUpdate , userIDScope ) ) , routing . Wrap ( UpdateUserQuota ) )
adminUserRoute . Post ( "/:id/logout" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersLogout , userIDScope ) ) , routing . Wrap ( hs . AdminLogoutUser ) )
adminUserRoute . Get ( "/:id/auth-tokens" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersAuthTokenList , userIDScope ) ) , routing . Wrap ( hs . AdminGetUserAuthTokens ) )
adminUserRoute . Post ( "/:id/revoke-auth-token" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersAuthTokenUpdate , userIDScope ) ) , bind ( models . RevokeAuthTokenCmd { } ) , routing . Wrap ( hs . AdminRevokeUserAuthToken ) )
adminUserRoute . Post ( "/:id/revoke-auth-token" , authorize ( reqGrafanaAdmin , ac . EvalPermission ( ac . ActionUsersAuthTokenUpdate , userIDScope ) ) , routing . Wrap ( hs . AdminRevokeUserAuthToken ) )
} )
// rendering
@ -499,7 +495,7 @@ func (hs *HTTPServer) registerRoutes() {
r . Get ( "/avatar/:hash" , avatarCacheServer . Handler )
// Snapshots
r . Post ( "/api/snapshots/" , reqSnapshotPublicModeOrSignedIn , bind ( models . CreateDashboardSnapshotCommand { } ) , CreateDashboardSnapshot )
r . Post ( "/api/snapshots/" , reqSnapshotPublicModeOrSignedIn , CreateDashboardSnapshot )
r . Get ( "/api/snapshot/shared-options/" , reqSignedIn , GetSharingOptions )
r . Get ( "/api/snapshots/:key" , routing . Wrap ( GetDashboardSnapshot ) )
r . Get ( "/api/snapshots-delete/:deleteKey" , reqSnapshotPublicModeOrSignedIn , routing . Wrap ( DeleteDashboardSnapshotByDeleteKey ) )
@ -508,5 +504,5 @@ func (hs *HTTPServer) registerRoutes() {
// Frontend logs
sourceMapStore := frontendlogging . NewSourceMapStore ( hs . Cfg , hs . pluginStaticRouteResolver , frontendlogging . ReadSourceMapFromFS )
r . Post ( "/log" , middleware . RateLimit ( hs . Cfg . Sentry . EndpointRPS , hs . Cfg . Sentry . EndpointBurst , time . Now ) ,
bind ( frontendlogging . FrontendSentryEvent { } ) , routing . Wrap ( NewFrontendLogMessageHandler ( sourceMapStore ) ) )
routing . Wrap ( NewFrontendLogMessageHandler ( sourceMapStore ) ) )
}