Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service * Rename package to contextmodel * Generate ngalert files * Remove unused imports
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -100,8 +100,8 @@ type User struct {
|
||||
}
|
||||
|
||||
// HasGlobalAccess checks user access with globally assigned permissions only
|
||||
func HasGlobalAccess(ac AccessControl, service Service, c *models.ReqContext) func(fallback func(*models.ReqContext) bool, evaluator Evaluator) bool {
|
||||
return func(fallback func(*models.ReqContext) bool, evaluator Evaluator) bool {
|
||||
func HasGlobalAccess(ac AccessControl, service Service, c *contextmodel.ReqContext) func(fallback func(*contextmodel.ReqContext) bool, evaluator Evaluator) bool {
|
||||
return func(fallback func(*contextmodel.ReqContext) bool, evaluator Evaluator) bool {
|
||||
if ac.IsDisabled() {
|
||||
return fallback(c)
|
||||
}
|
||||
@@ -131,8 +131,8 @@ func HasGlobalAccess(ac AccessControl, service Service, c *models.ReqContext) fu
|
||||
}
|
||||
}
|
||||
|
||||
func HasAccess(ac AccessControl, c *models.ReqContext) func(fallback func(*models.ReqContext) bool, evaluator Evaluator) bool {
|
||||
return func(fallback func(*models.ReqContext) bool, evaluator Evaluator) bool {
|
||||
func HasAccess(ac AccessControl, c *contextmodel.ReqContext) func(fallback func(*contextmodel.ReqContext) bool, evaluator Evaluator) bool {
|
||||
return func(fallback func(*contextmodel.ReqContext) bool, evaluator Evaluator) bool {
|
||||
if ac.IsDisabled() {
|
||||
return fallback(c)
|
||||
}
|
||||
@@ -147,31 +147,31 @@ func HasAccess(ac AccessControl, c *models.ReqContext) func(fallback func(*model
|
||||
}
|
||||
}
|
||||
|
||||
var ReqSignedIn = func(c *models.ReqContext) bool {
|
||||
var ReqSignedIn = func(c *contextmodel.ReqContext) bool {
|
||||
return c.IsSignedIn
|
||||
}
|
||||
|
||||
var ReqGrafanaAdmin = func(c *models.ReqContext) bool {
|
||||
var ReqGrafanaAdmin = func(c *contextmodel.ReqContext) bool {
|
||||
return c.IsGrafanaAdmin
|
||||
}
|
||||
|
||||
// ReqViewer returns true if the current user has org.RoleViewer. Note: this can be anonymous user as well
|
||||
var ReqViewer = func(c *models.ReqContext) bool {
|
||||
var ReqViewer = func(c *contextmodel.ReqContext) bool {
|
||||
return c.OrgRole.Includes(org.RoleViewer)
|
||||
}
|
||||
|
||||
var ReqOrgAdmin = func(c *models.ReqContext) bool {
|
||||
var ReqOrgAdmin = func(c *contextmodel.ReqContext) bool {
|
||||
return c.OrgRole == org.RoleAdmin
|
||||
}
|
||||
|
||||
var ReqOrgAdminOrEditor = func(c *models.ReqContext) bool {
|
||||
var ReqOrgAdminOrEditor = func(c *contextmodel.ReqContext) bool {
|
||||
return c.OrgRole == org.RoleAdmin || c.OrgRole == org.RoleEditor
|
||||
}
|
||||
|
||||
// ReqHasRole generates a fallback to check whether the user has a role
|
||||
// Note that while ReqOrgAdmin returns false for a Grafana Admin / Viewer, ReqHasRole(org.RoleAdmin) will return true
|
||||
func ReqHasRole(role org.RoleType) func(c *models.ReqContext) bool {
|
||||
return func(c *models.ReqContext) bool { return c.HasRole(role) }
|
||||
func ReqHasRole(role org.RoleType) func(c *contextmodel.ReqContext) bool {
|
||||
return func(c *contextmodel.ReqContext) bool { return c.HasRole(role) }
|
||||
}
|
||||
|
||||
func BuildPermissionsMap(permissions []Permission) map[string]bool {
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -47,7 +47,7 @@ func (api *AccessControlAPI) RegisterAPIEndpoints() {
|
||||
}
|
||||
|
||||
// GET /api/access-control/user/actions
|
||||
func (api *AccessControlAPI) getUserActions(c *models.ReqContext) response.Response {
|
||||
func (api *AccessControlAPI) getUserActions(c *contextmodel.ReqContext) response.Response {
|
||||
reloadCache := c.QueryBool("reloadcache")
|
||||
permissions, err := api.Service.GetUserPermissions(c.Req.Context(),
|
||||
c.SignedInUser, ac.Options{ReloadCache: reloadCache})
|
||||
@@ -59,7 +59,7 @@ func (api *AccessControlAPI) getUserActions(c *models.ReqContext) response.Respo
|
||||
}
|
||||
|
||||
// GET /api/access-control/user/permissions
|
||||
func (api *AccessControlAPI) getUserPermissions(c *models.ReqContext) response.Response {
|
||||
func (api *AccessControlAPI) getUserPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
reloadCache := c.QueryBool("reloadcache")
|
||||
permissions, err := api.Service.GetUserPermissions(c.Req.Context(),
|
||||
c.SignedInUser, ac.Options{ReloadCache: reloadCache})
|
||||
@@ -71,7 +71,7 @@ func (api *AccessControlAPI) getUserPermissions(c *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// GET /api/access-control/users/permissions
|
||||
func (api *AccessControlAPI) searchUsersPermissions(c *models.ReqContext) response.Response {
|
||||
func (api *AccessControlAPI) searchUsersPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
searchOptions := ac.SearchOptions{
|
||||
ActionPrefix: c.Query("actionPrefix"),
|
||||
Action: c.Query("action"),
|
||||
@@ -98,7 +98,7 @@ func (api *AccessControlAPI) searchUsersPermissions(c *models.ReqContext) respon
|
||||
}
|
||||
|
||||
// GET /api/access-control/user/:userID/permissions/search
|
||||
func (api *AccessControlAPI) searchUserPermissions(c *models.ReqContext) response.Response {
|
||||
func (api *AccessControlAPI) searchUserPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
userIDString := web.Params(c.Req)[":userID"]
|
||||
userID, err := strconv.ParseInt(userIDString, 10, 64)
|
||||
if err != nil {
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/middleware/cookies"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/usertoken"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -29,7 +29,7 @@ func Middleware(ac AccessControl) func(web.Handler, Evaluator) web.Handler {
|
||||
return fallback
|
||||
}
|
||||
|
||||
return func(c *models.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
if c.AllowAnonymous {
|
||||
forceLogin, _ := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin")) // ignoring error, assuming false for non-true values is ok.
|
||||
orgID, err := strconv.ParseInt(c.Req.URL.Query().Get("orgId"), 10, 64)
|
||||
@@ -53,7 +53,7 @@ func Middleware(ac AccessControl) func(web.Handler, Evaluator) web.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func authorize(c *models.ReqContext, ac AccessControl, user *user.SignedInUser, evaluator Evaluator) {
|
||||
func authorize(c *contextmodel.ReqContext, ac AccessControl, user *user.SignedInUser, evaluator Evaluator) {
|
||||
injected, err := evaluator.MutateScopes(c.Req.Context(), scopeInjector(scopeParams{
|
||||
OrgID: c.OrgID,
|
||||
URLParams: web.Params(c.Req),
|
||||
@@ -70,7 +70,7 @@ func authorize(c *models.ReqContext, ac AccessControl, user *user.SignedInUser,
|
||||
}
|
||||
}
|
||||
|
||||
func deny(c *models.ReqContext, evaluator Evaluator, err error) {
|
||||
func deny(c *contextmodel.ReqContext, evaluator Evaluator, err error) {
|
||||
id := newID()
|
||||
if err != nil {
|
||||
c.Logger.Error("Error from access control system", "error", err, "accessErrorID", id)
|
||||
@@ -106,7 +106,7 @@ func deny(c *models.ReqContext, evaluator Evaluator, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
func unauthorized(c *models.ReqContext, err error) {
|
||||
func unauthorized(c *contextmodel.ReqContext, err error) {
|
||||
if c.IsApiRequest() {
|
||||
response := map[string]interface{}{
|
||||
"message": "Unauthorized",
|
||||
@@ -129,7 +129,7 @@ func unauthorized(c *models.ReqContext, err error) {
|
||||
c.Redirect(setting.AppSubUrl + "/login")
|
||||
}
|
||||
|
||||
func writeRedirectCookie(c *models.ReqContext) {
|
||||
func writeRedirectCookie(c *contextmodel.ReqContext) {
|
||||
redirectTo := c.Req.RequestURI
|
||||
if setting.AppSubUrl != "" && !strings.HasPrefix(redirectTo, setting.AppSubUrl) {
|
||||
redirectTo = setting.AppSubUrl + c.Req.RequestURI
|
||||
@@ -159,7 +159,7 @@ func newID() string {
|
||||
return "ACE" + id
|
||||
}
|
||||
|
||||
type OrgIDGetter func(c *models.ReqContext) (int64, error)
|
||||
type OrgIDGetter func(c *contextmodel.ReqContext) (int64, error)
|
||||
|
||||
type userCache interface {
|
||||
GetSignedInUserWithCacheCtx(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error)
|
||||
@@ -171,7 +171,7 @@ func AuthorizeInOrgMiddleware(ac AccessControl, service Service, cache userCache
|
||||
return fallback
|
||||
}
|
||||
|
||||
return func(c *models.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
// using a copy of the user not to modify the signedInUser, yet perform the permission evaluation in another org
|
||||
userCopy := *(c.SignedInUser)
|
||||
orgID, err := getTargetOrg(c)
|
||||
@@ -211,7 +211,7 @@ func AuthorizeInOrgMiddleware(ac AccessControl, service Service, cache userCache
|
||||
}
|
||||
}
|
||||
|
||||
func UseOrgFromContextParams(c *models.ReqContext) (int64, error) {
|
||||
func UseOrgFromContextParams(c *contextmodel.ReqContext) (int64, error) {
|
||||
orgID, err := strconv.ParseInt(web.Params(c.Req)[":orgId"], 10, 64)
|
||||
|
||||
// Special case of macaron handling invalid params
|
||||
@@ -222,12 +222,12 @@ func UseOrgFromContextParams(c *models.ReqContext) (int64, error) {
|
||||
return orgID, nil
|
||||
}
|
||||
|
||||
func UseGlobalOrg(c *models.ReqContext) (int64, error) {
|
||||
func UseGlobalOrg(c *contextmodel.ReqContext) (int64, error) {
|
||||
return GlobalOrgID, nil
|
||||
}
|
||||
|
||||
func LoadPermissionsMiddleware(service Service) web.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
if service.IsDisabled() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -55,7 +55,7 @@ func TestMiddleware(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
fallbackCalled := false
|
||||
fallback := func(c *models.ReqContext) {
|
||||
fallback := func(c *contextmodel.ReqContext) {
|
||||
fallbackCalled = true
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestMiddleware(t *testing.T) {
|
||||
server.Use(accesscontrol.Middleware(test.ac)(fallback, test.evaluator))
|
||||
|
||||
endpointCalled := false
|
||||
server.Get("/", func(c *models.ReqContext) {
|
||||
server.Get("/", func(c *contextmodel.ReqContext) {
|
||||
endpointCalled = true
|
||||
c.Resp.WriteHeader(http.StatusOK)
|
||||
})
|
||||
@@ -99,13 +99,13 @@ func TestMiddleware_forceLogin(t *testing.T) {
|
||||
server := web.New()
|
||||
server.UseMiddleware(web.Renderer("../../public/views", "[[", "]]"))
|
||||
|
||||
server.Get("/endpoint", func(c *models.ReqContext) {
|
||||
server.Get("/endpoint", func(c *contextmodel.ReqContext) {
|
||||
endpointCalled = true
|
||||
c.Resp.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
ac := mock.New().WithPermissions([]accesscontrol.Permission{{Action: "endpoint:read", Scope: "endpoint:1"}})
|
||||
server.Use(contextProvider(func(c *models.ReqContext) {
|
||||
server.Use(contextProvider(func(c *contextmodel.ReqContext) {
|
||||
c.AllowAnonymous = true
|
||||
c.SignedInUser.IsAnonymous = true
|
||||
c.IsSignedIn = false
|
||||
@@ -129,9 +129,9 @@ func TestMiddleware_forceLogin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func contextProvider(modifiers ...func(c *models.ReqContext)) web.Handler {
|
||||
func contextProvider(modifiers ...func(c *contextmodel.ReqContext)) web.Handler {
|
||||
return func(c *web.Context) {
|
||||
reqCtx := &models.ReqContext{
|
||||
reqCtx := &contextmodel.ReqContext{
|
||||
Context: c,
|
||||
Logger: log.New(""),
|
||||
SignedInUser: &user.SignedInUser{},
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -68,7 +68,7 @@ type Description struct {
|
||||
Permissions []string `json:"permissions"`
|
||||
}
|
||||
|
||||
func (a *api) getDescription(c *models.ReqContext) response.Response {
|
||||
func (a *api) getDescription(c *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, &Description{
|
||||
Permissions: a.permissions,
|
||||
Assignments: a.service.options.Assignments,
|
||||
@@ -91,7 +91,7 @@ type resourcePermissionDTO struct {
|
||||
Permission string `json:"permission"`
|
||||
}
|
||||
|
||||
func (a *api) getPermissions(c *models.ReqContext) response.Response {
|
||||
func (a *api) getPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
|
||||
permissions, err := a.service.GetPermissions(c.Req.Context(), c.SignedInUser, resourceID)
|
||||
@@ -144,7 +144,7 @@ type setPermissionsCommand struct {
|
||||
Permissions []accesscontrol.SetResourcePermissionCommand `json:"permissions"`
|
||||
}
|
||||
|
||||
func (a *api) setUserPermission(c *models.ReqContext) response.Response {
|
||||
func (a *api) setUserPermission(c *contextmodel.ReqContext) response.Response {
|
||||
userID, err := strconv.ParseInt(web.Params(c.Req)[":userID"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "userID is invalid", err)
|
||||
@@ -164,7 +164,7 @@ func (a *api) setUserPermission(c *models.ReqContext) response.Response {
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
func (a *api) setTeamPermission(c *models.ReqContext) response.Response {
|
||||
func (a *api) setTeamPermission(c *contextmodel.ReqContext) response.Response {
|
||||
teamID, err := strconv.ParseInt(web.Params(c.Req)[":teamID"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "teamID is invalid", err)
|
||||
@@ -184,7 +184,7 @@ func (a *api) setTeamPermission(c *models.ReqContext) response.Response {
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
func (a *api) setBuiltinRolePermission(c *models.ReqContext) response.Response {
|
||||
func (a *api) setBuiltinRolePermission(c *contextmodel.ReqContext) response.Response {
|
||||
builtInRole := web.Params(c.Req)[":builtInRole"]
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
|
||||
@@ -201,7 +201,7 @@ func (a *api) setBuiltinRolePermission(c *models.ReqContext) response.Response {
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
func (a *api) setPermissions(c *models.ReqContext) response.Response {
|
||||
func (a *api) setPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
|
||||
cmd := setPermissionsCommand{}
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
@@ -444,7 +444,7 @@ type testContext struct {
|
||||
func contextProvider(tc *testContext) web.Handler {
|
||||
return func(c *web.Context) {
|
||||
signedIn := tc.user != nil
|
||||
reqCtx := &models.ReqContext{
|
||||
reqCtx := &contextmodel.ReqContext{
|
||||
Context: c,
|
||||
SignedInUser: tc.user,
|
||||
IsSignedIn: signedIn,
|
||||
|
||||
@@ -3,12 +3,12 @@ package resourcepermissions
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
func disableMiddleware(shouldDisable bool) web.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
if shouldDisable {
|
||||
c.Resp.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
@@ -16,4 +16,4 @@ func disableMiddleware(shouldDisable bool) web.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
func nopMiddleware(c *models.ReqContext) {}
|
||||
func nopMiddleware(c *contextmodel.ReqContext) {}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/roletype"
|
||||
authJWT "github.com/grafana/grafana/pkg/services/auth/jwt"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
@@ -22,7 +23,7 @@ const (
|
||||
UserNotFound = "User not found"
|
||||
)
|
||||
|
||||
func (h *ContextHandler) initContextWithJWT(ctx *models.ReqContext, orgId int64) bool {
|
||||
func (h *ContextHandler) initContextWithJWT(ctx *contextmodel.ReqContext, orgId int64) bool {
|
||||
if !h.Cfg.JWTAuthEnabled || h.Cfg.JWTAuthHeaderName == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/auth/jwt"
|
||||
"github.com/grafana/grafana/pkg/services/authn/authntest"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/login/loginservice"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
@@ -42,7 +43,7 @@ func TestInitContextWithAuthProxy_CachedInvalidUserID(t *testing.T) {
|
||||
|
||||
req, err := http.NewRequest("POST", "http://example.com", nil)
|
||||
require.NoError(t, err)
|
||||
ctx := &models.ReqContext{
|
||||
ctx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{Req: req},
|
||||
Logger: log.New("Test"),
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/remotecache"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ldap"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/multildap"
|
||||
@@ -98,7 +99,7 @@ func (auth *AuthProxy) IsEnabled() bool {
|
||||
}
|
||||
|
||||
// HasHeader checks if we have specified header
|
||||
func (auth *AuthProxy) HasHeader(reqCtx *models.ReqContext) bool {
|
||||
func (auth *AuthProxy) HasHeader(reqCtx *contextmodel.ReqContext) bool {
|
||||
header := auth.getDecodedHeader(reqCtx, auth.cfg.AuthProxyHeaderName)
|
||||
return len(header) != 0
|
||||
}
|
||||
@@ -149,7 +150,7 @@ func HashCacheKey(key string) (string, error) {
|
||||
// getKey forms a key for the cache based on the headers received as part of the authentication flow.
|
||||
// Our configuration supports multiple headers. The main header contains the email or username.
|
||||
// And the additional ones that allow us to specify extra attributes: Name, Email, Role, or Groups.
|
||||
func (auth *AuthProxy) getKey(reqCtx *models.ReqContext) (string, error) {
|
||||
func (auth *AuthProxy) getKey(reqCtx *contextmodel.ReqContext) (string, error) {
|
||||
header := auth.getDecodedHeader(reqCtx, auth.cfg.AuthProxyHeaderName)
|
||||
key := strings.TrimSpace(header) // start the key with the main header
|
||||
|
||||
@@ -165,7 +166,7 @@ func (auth *AuthProxy) getKey(reqCtx *models.ReqContext) (string, error) {
|
||||
}
|
||||
|
||||
// Login logs in user ID by whatever means possible.
|
||||
func (auth *AuthProxy) Login(reqCtx *models.ReqContext, ignoreCache bool) (int64, error) {
|
||||
func (auth *AuthProxy) Login(reqCtx *contextmodel.ReqContext, ignoreCache bool) (int64, error) {
|
||||
if !ignoreCache {
|
||||
// Error here means absent cache - we don't need to handle that
|
||||
id, err := auth.getUserViaCache(reqCtx)
|
||||
@@ -195,7 +196,7 @@ func (auth *AuthProxy) Login(reqCtx *models.ReqContext, ignoreCache bool) (int64
|
||||
}
|
||||
|
||||
// getUserViaCache gets user ID from cache.
|
||||
func (auth *AuthProxy) getUserViaCache(reqCtx *models.ReqContext) (int64, error) {
|
||||
func (auth *AuthProxy) getUserViaCache(reqCtx *contextmodel.ReqContext) (int64, error) {
|
||||
cacheKey, err := auth.getKey(reqCtx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -212,7 +213,7 @@ func (auth *AuthProxy) getUserViaCache(reqCtx *models.ReqContext) (int64, error)
|
||||
}
|
||||
|
||||
// RemoveUserFromCache removes user from cache.
|
||||
func (auth *AuthProxy) RemoveUserFromCache(reqCtx *models.ReqContext) error {
|
||||
func (auth *AuthProxy) RemoveUserFromCache(reqCtx *contextmodel.ReqContext) error {
|
||||
cacheKey, err := auth.getKey(reqCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -227,7 +228,7 @@ func (auth *AuthProxy) RemoveUserFromCache(reqCtx *models.ReqContext) error {
|
||||
}
|
||||
|
||||
// LoginViaLDAP logs in user via LDAP request
|
||||
func (auth *AuthProxy) LoginViaLDAP(reqCtx *models.ReqContext) (int64, error) {
|
||||
func (auth *AuthProxy) LoginViaLDAP(reqCtx *contextmodel.ReqContext) (int64, error) {
|
||||
config, err := getLDAPConfig(auth.cfg)
|
||||
if err != nil {
|
||||
return 0, newError("failed to get LDAP config", err)
|
||||
@@ -259,7 +260,7 @@ func (auth *AuthProxy) LoginViaLDAP(reqCtx *models.ReqContext) (int64, error) {
|
||||
}
|
||||
|
||||
// loginViaHeader logs in user from the header only
|
||||
func (auth *AuthProxy) loginViaHeader(reqCtx *models.ReqContext) (int64, error) {
|
||||
func (auth *AuthProxy) loginViaHeader(reqCtx *contextmodel.ReqContext) (int64, error) {
|
||||
header := auth.getDecodedHeader(reqCtx, auth.cfg.AuthProxyHeaderName)
|
||||
extUser := &models.ExternalUserInfo{
|
||||
AuthModule: login.AuthProxyAuthModule,
|
||||
@@ -323,7 +324,7 @@ func (auth *AuthProxy) loginViaHeader(reqCtx *models.ReqContext) (int64, error)
|
||||
}
|
||||
|
||||
// getDecodedHeader gets decoded value of a header with given headerName
|
||||
func (auth *AuthProxy) getDecodedHeader(reqCtx *models.ReqContext, headerName string) string {
|
||||
func (auth *AuthProxy) getDecodedHeader(reqCtx *contextmodel.ReqContext, headerName string) string {
|
||||
headerValue := reqCtx.Req.Header.Get(headerName)
|
||||
|
||||
if auth.cfg.AuthProxyHeadersEncoded {
|
||||
@@ -334,7 +335,7 @@ func (auth *AuthProxy) getDecodedHeader(reqCtx *models.ReqContext, headerName st
|
||||
}
|
||||
|
||||
// headersIterator iterates over all non-empty supported additional headers
|
||||
func (auth *AuthProxy) headersIterator(reqCtx *models.ReqContext, fn func(field string, header string)) {
|
||||
func (auth *AuthProxy) headersIterator(reqCtx *contextmodel.ReqContext, fn func(field string, header string)) {
|
||||
for _, field := range supportedHeaderFields {
|
||||
h := auth.cfg.AuthProxyHeaders[field]
|
||||
if h == "" {
|
||||
@@ -356,7 +357,7 @@ func (auth *AuthProxy) GetSignedInUser(userID int64, orgID int64) (*user.SignedI
|
||||
}
|
||||
|
||||
// Remember user in cache
|
||||
func (auth *AuthProxy) Remember(reqCtx *models.ReqContext, id int64) error {
|
||||
func (auth *AuthProxy) Remember(reqCtx *contextmodel.ReqContext, id int64) error {
|
||||
key, err := auth.getKey(reqCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/remotecache"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ldap"
|
||||
"github.com/grafana/grafana/pkg/services/login/loginservice"
|
||||
"github.com/grafana/grafana/pkg/services/multildap"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
const hdrName = "markelog"
|
||||
const id int64 = 42
|
||||
|
||||
func prepareMiddleware(t *testing.T, remoteCache *remotecache.RemoteCache, configureReq func(*http.Request, *setting.Cfg)) (*AuthProxy, *models.ReqContext) {
|
||||
func prepareMiddleware(t *testing.T, remoteCache *remotecache.RemoteCache, configureReq func(*http.Request, *setting.Cfg)) (*AuthProxy, *contextmodel.ReqContext) {
|
||||
t.Helper()
|
||||
|
||||
req, err := http.NewRequest("POST", "http://example.com", nil)
|
||||
@@ -38,7 +38,7 @@ func prepareMiddleware(t *testing.T, remoteCache *remotecache.RemoteCache, confi
|
||||
req.Header.Set(cfg.AuthProxyHeaderName, hdrName)
|
||||
}
|
||||
|
||||
ctx := &models.ReqContext{
|
||||
ctx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{Req: req},
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
||||
@@ -99,8 +100,8 @@ type ContextHandler struct {
|
||||
type reqContextKey = ctxkey.Key
|
||||
|
||||
// FromContext returns the ReqContext value stored in a context.Context, if any.
|
||||
func FromContext(c context.Context) *models.ReqContext {
|
||||
if reqCtx, ok := c.Value(reqContextKey{}).(*models.ReqContext); ok {
|
||||
func FromContext(c context.Context) *contextmodel.ReqContext {
|
||||
if reqCtx, ok := c.Value(reqContextKey{}).(*contextmodel.ReqContext); ok {
|
||||
return reqCtx
|
||||
}
|
||||
return nil
|
||||
@@ -114,7 +115,7 @@ func (h *ContextHandler) Middleware(next http.Handler) http.Handler {
|
||||
_, span := h.tracer.Start(ctx, "Auth - Middleware")
|
||||
defer span.End()
|
||||
|
||||
reqContext := &models.ReqContext{
|
||||
reqContext := &contextmodel.ReqContext{
|
||||
Context: mContext,
|
||||
SignedInUser: &user.SignedInUser{},
|
||||
IsSignedIn: false,
|
||||
@@ -218,7 +219,7 @@ func (h *ContextHandler) Middleware(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithAnonymousUser(reqContext *models.ReqContext) bool {
|
||||
func (h *ContextHandler) initContextWithAnonymousUser(reqContext *contextmodel.ReqContext) bool {
|
||||
_, span := h.tracer.Start(reqContext.Req.Context(), "initContextWithAnonymousUser")
|
||||
defer span.End()
|
||||
|
||||
@@ -282,7 +283,7 @@ func (h *ContextHandler) getAPIKey(ctx context.Context, keyString string) (*apik
|
||||
return keyQuery.Result, nil
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bool {
|
||||
func (h *ContextHandler) initContextWithAPIKey(reqContext *contextmodel.ReqContext) bool {
|
||||
header := reqContext.Req.Header.Get("Authorization")
|
||||
parts := strings.SplitN(header, " ", 2)
|
||||
var keyString string
|
||||
@@ -396,7 +397,7 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext, orgID int64) bool {
|
||||
func (h *ContextHandler) initContextWithBasicAuth(reqContext *contextmodel.ReqContext, orgID int64) bool {
|
||||
if !h.Cfg.BasicAuthEnabled {
|
||||
return false
|
||||
}
|
||||
@@ -456,7 +457,7 @@ func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext,
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, orgID int64) bool {
|
||||
func (h *ContextHandler) initContextWithToken(reqContext *contextmodel.ReqContext, orgID int64) bool {
|
||||
if h.Cfg.LoginCookieName == "" {
|
||||
return false
|
||||
}
|
||||
@@ -528,7 +529,7 @@ func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, org
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *ContextHandler) deleteInvalidCookieEndOfRequestFunc(reqContext *models.ReqContext) web.BeforeFunc {
|
||||
func (h *ContextHandler) deleteInvalidCookieEndOfRequestFunc(reqContext *contextmodel.ReqContext) web.BeforeFunc {
|
||||
return func(w web.ResponseWriter) {
|
||||
if w.Written() {
|
||||
reqContext.Logger.Debug("Response written, skipping invalid cookie delete")
|
||||
@@ -540,7 +541,7 @@ func (h *ContextHandler) deleteInvalidCookieEndOfRequestFunc(reqContext *models.
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ContextHandler) rotateEndOfRequestFunc(reqContext *models.ReqContext) web.BeforeFunc {
|
||||
func (h *ContextHandler) rotateEndOfRequestFunc(reqContext *contextmodel.ReqContext) web.BeforeFunc {
|
||||
return func(w web.ResponseWriter) {
|
||||
// if response has already been written, skip.
|
||||
if w.Written() {
|
||||
@@ -581,7 +582,7 @@ func (h *ContextHandler) rotateEndOfRequestFunc(reqContext *models.ReqContext) w
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithRenderAuth(reqContext *models.ReqContext) bool {
|
||||
func (h *ContextHandler) initContextWithRenderAuth(reqContext *contextmodel.ReqContext) bool {
|
||||
key := reqContext.GetCookie("renderKey")
|
||||
if key == "" {
|
||||
return false
|
||||
@@ -617,7 +618,7 @@ func (h *ContextHandler) initContextWithRenderAuth(reqContext *models.ReqContext
|
||||
return true
|
||||
}
|
||||
|
||||
func logUserIn(reqContext *models.ReqContext, auth *authproxy.AuthProxy, username string, logger log.Logger, ignoreCache bool) (int64, error) {
|
||||
func logUserIn(reqContext *contextmodel.ReqContext, auth *authproxy.AuthProxy, username string, logger log.Logger, ignoreCache bool) (int64, error) {
|
||||
logger.Debug("Trying to log user in", "username", username, "ignoreCache", ignoreCache)
|
||||
// Try to log in user via various providers
|
||||
id, err := auth.Login(reqContext, ignoreCache)
|
||||
@@ -634,7 +635,7 @@ func logUserIn(reqContext *models.ReqContext, auth *authproxy.AuthProxy, usernam
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (h *ContextHandler) handleError(ctx *models.ReqContext, err error, statusCode int, cb func(error)) {
|
||||
func (h *ContextHandler) handleError(ctx *contextmodel.ReqContext, err error, statusCode int, cb func(error)) {
|
||||
details := err
|
||||
var e authproxy.Error
|
||||
if errors.As(err, &e) {
|
||||
@@ -647,7 +648,7 @@ func (h *ContextHandler) handleError(ctx *models.ReqContext, err error, statusCo
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ContextHandler) initContextWithAuthProxy(reqContext *models.ReqContext, orgID int64) bool {
|
||||
func (h *ContextHandler) initContextWithAuthProxy(reqContext *contextmodel.ReqContext, orgID int64) bool {
|
||||
username := reqContext.Req.Header.Get(h.Cfg.AuthProxyHeaderName)
|
||||
|
||||
logger := log.New("auth.proxy")
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
"github.com/grafana/grafana/pkg/services/auth/authtest"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -77,7 +77,7 @@ func TestTokenRotationAtEndOfRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func initTokenRotationScenario(ctx context.Context, t *testing.T, ctxHdlr *ContextHandler) (
|
||||
*models.ReqContext, *httptest.ResponseRecorder, error) {
|
||||
*contextmodel.ReqContext, *httptest.ResponseRecorder, error) {
|
||||
t.Helper()
|
||||
|
||||
ctxHdlr.Cfg.LoginCookieName = "login_token"
|
||||
@@ -92,7 +92,7 @@ func initTokenRotationScenario(ctx context.Context, t *testing.T, ctxHdlr *Conte
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reqContext := &models.ReqContext{
|
||||
reqContext := &contextmodel.ReqContext{
|
||||
Context: &web.Context{Req: req},
|
||||
Logger: log.New("testlogger"),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
package contextmodel
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models/usertoken"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type ReqContext struct {
|
||||
*web.Context
|
||||
*user.SignedInUser
|
||||
UserToken *usertoken.UserToken
|
||||
|
||||
IsSignedIn bool
|
||||
IsRenderCall bool
|
||||
AllowAnonymous bool
|
||||
SkipCache bool
|
||||
Logger log.Logger
|
||||
// RequestNonce is a cryptographic request identifier for use with Content Security Policy.
|
||||
RequestNonce string
|
||||
IsPublicDashboardView bool
|
||||
|
||||
PerfmonTimer prometheus.Summary
|
||||
LookupTokenErr error
|
||||
}
|
||||
|
||||
// Handle handles and logs error by given status.
|
||||
func (ctx *ReqContext) Handle(cfg *setting.Cfg, status int, title string, err error) {
|
||||
data := struct {
|
||||
Title string
|
||||
AppTitle string
|
||||
AppSubUrl string
|
||||
Theme string
|
||||
ErrorMsg error
|
||||
}{title, "Grafana", cfg.AppSubURL, "dark", nil}
|
||||
if err != nil {
|
||||
ctx.Logger.Error(title, "error", err)
|
||||
if setting.Env != setting.Prod {
|
||||
data.ErrorMsg = err
|
||||
}
|
||||
}
|
||||
|
||||
ctx.HTML(status, cfg.ErrTemplateName, data)
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) IsApiRequest() bool {
|
||||
return strings.HasPrefix(ctx.Req.URL.Path, "/api")
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) JsonApiErr(status int, message string, err error) {
|
||||
resp := make(map[string]interface{})
|
||||
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
|
||||
|
||||
if err != nil {
|
||||
resp["traceID"] = traceID
|
||||
if status == http.StatusInternalServerError {
|
||||
ctx.Logger.Error(message, "error", err, "traceID", traceID)
|
||||
} else {
|
||||
ctx.Logger.Warn(message, "error", err, "traceID", traceID)
|
||||
}
|
||||
|
||||
if setting.Env != setting.Prod {
|
||||
resp["error"] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
switch status {
|
||||
case http.StatusNotFound:
|
||||
resp["message"] = "Not Found"
|
||||
case http.StatusInternalServerError:
|
||||
resp["message"] = "Internal Server Error"
|
||||
}
|
||||
|
||||
if message != "" {
|
||||
resp["message"] = message
|
||||
}
|
||||
|
||||
ctx.JSON(status, resp)
|
||||
}
|
||||
|
||||
// WriteErr writes an error response based on errutil.Error.
|
||||
// If provided error is not errutil.Error a 500 response is written.
|
||||
func (ctx *ReqContext) WriteErr(err error) {
|
||||
ctx.writeErrOrFallback(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), err)
|
||||
}
|
||||
|
||||
// WriteErrOrFallback uses the information in an errutil.Error if available
|
||||
// and otherwise falls back to the status and message provided as arguments.
|
||||
func (ctx *ReqContext) WriteErrOrFallback(status int, message string, err error) {
|
||||
ctx.writeErrOrFallback(status, message, err)
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) writeErrOrFallback(status int, message string, err error) {
|
||||
data := make(map[string]interface{})
|
||||
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
|
||||
|
||||
if err != nil {
|
||||
data["traceID"] = traceID
|
||||
|
||||
var logMessage string
|
||||
logger := ctx.Logger.Warn
|
||||
|
||||
gfErr := errutil.Error{}
|
||||
if errors.As(err, &gfErr) {
|
||||
logger = gfErr.LogLevel.LogFunc(ctx.Logger)
|
||||
publicErr := gfErr.Public()
|
||||
|
||||
// need to manually set these fields because we want to include the trace id
|
||||
data["extra"] = publicErr.Extra
|
||||
data["message"] = publicErr.Message
|
||||
data["messageId"] = publicErr.MessageID
|
||||
data["statusCode"] = publicErr.StatusCode
|
||||
} else {
|
||||
if message != "" {
|
||||
logMessage = message
|
||||
} else {
|
||||
logMessage = http.StatusText(status)
|
||||
data["message"] = logMessage
|
||||
}
|
||||
|
||||
if status == http.StatusInternalServerError {
|
||||
logger = ctx.Logger.Error
|
||||
}
|
||||
}
|
||||
|
||||
logger(logMessage, "error", err, "remote_addr", ctx.RemoteAddr(), "traceID", traceID)
|
||||
}
|
||||
|
||||
if _, ok := data["message"]; !ok && message != "" {
|
||||
data["message"] = message
|
||||
}
|
||||
|
||||
ctx.JSON(status, data)
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) HasUserRole(role org.RoleType) bool {
|
||||
return ctx.OrgRole.Includes(role)
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) HasHelpFlag(flag user.HelpFlags1) bool {
|
||||
return ctx.HelpFlags1.HasFlag(flag)
|
||||
}
|
||||
|
||||
func (ctx *ReqContext) TimeRequest(timer prometheus.Summary) {
|
||||
ctx.PerfmonTimer = timer
|
||||
}
|
||||
|
||||
// QueryBoolWithDefault extracts a value from the request query params and applies a bool default if not present.
|
||||
func (ctx *ReqContext) QueryBoolWithDefault(field string, d bool) bool {
|
||||
f := ctx.Query(field)
|
||||
if f == "" {
|
||||
return d
|
||||
}
|
||||
|
||||
return ctx.QueryBool(field)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package contextmodel
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestQueryBoolWithDefault(t *testing.T) {
|
||||
tc := map[string]struct {
|
||||
url string
|
||||
defaultValue bool
|
||||
expected bool
|
||||
}{
|
||||
"with no value specified, the default value is returned": {
|
||||
url: "http://localhost/api/v2/alerts",
|
||||
defaultValue: true,
|
||||
expected: true,
|
||||
},
|
||||
"with a value specified, the default value is overridden": {
|
||||
url: "http://localhost/api/v2/alerts?silenced=false",
|
||||
defaultValue: true,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range tc {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", tt.url, nil)
|
||||
require.NoError(t, err)
|
||||
r := ReqContext{
|
||||
Context: &web.Context{Req: req},
|
||||
}
|
||||
require.Equal(t, tt.expected, r.QueryBoolWithDefault("silenced", tt.defaultValue))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -43,7 +43,7 @@ func (s *CorrelationsService) registerAPIEndpoints() {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) createHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) createHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := CreateCorrelationCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -93,7 +93,7 @@ type CreateCorrelationResponse struct {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) deleteHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) deleteHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := DeleteCorrelationCommand{
|
||||
UID: web.Params(c.Req)[":correlationUID"],
|
||||
SourceUID: web.Params(c.Req)[":uid"],
|
||||
@@ -147,7 +147,7 @@ type DeleteCorrelationResponse struct {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) updateHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) updateHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := UpdateCorrelationCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
if errors.Is(err, ErrUpdateCorrelationEmptyParams) {
|
||||
@@ -208,7 +208,7 @@ type UpdateCorrelationResponse struct {
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) getCorrelationHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) getCorrelationHandler(c *contextmodel.ReqContext) response.Response {
|
||||
query := GetCorrelationQuery{
|
||||
UID: web.Params(c.Req)[":correlationUID"],
|
||||
SourceUID: web.Params(c.Req)[":uid"],
|
||||
@@ -255,7 +255,7 @@ type GetCorrelationResponse struct {
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) getCorrelationsBySourceUIDHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) getCorrelationsBySourceUIDHandler(c *contextmodel.ReqContext) response.Response {
|
||||
query := GetCorrelationsBySourceUIDQuery{
|
||||
SourceUID: web.Params(c.Req)[":uid"],
|
||||
OrgId: c.OrgID,
|
||||
@@ -298,7 +298,7 @@ type GetCorrelationsBySourceUIDResponse struct {
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *CorrelationsService) getCorrelationsHandler(c *models.ReqContext) response.Response {
|
||||
func (s *CorrelationsService) getCorrelationsHandler(c *contextmodel.ReqContext) response.Response {
|
||||
query := GetCorrelationsQuery{
|
||||
OrgId: c.OrgID,
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
@@ -55,7 +55,7 @@ func (api *ImportDashboardAPI) RegisterAPIEndpoints(routeRegister routing.RouteR
|
||||
// 412: preconditionFailedError
|
||||
// 422: unprocessableEntityError
|
||||
// 500: internalServerError
|
||||
func (api *ImportDashboardAPI) ImportDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *ImportDashboardAPI) ImportDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
req := dashboardimport.ImportDashboardRequest{}
|
||||
if err := web.Bind(c.Req, &req); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -84,12 +84,12 @@ func (api *ImportDashboardAPI) ImportDashboard(c *models.ReqContext) response.Re
|
||||
}
|
||||
|
||||
type QuotaService interface {
|
||||
QuotaReached(c *models.ReqContext, target quota.TargetSrv) (bool, error)
|
||||
QuotaReached(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error)
|
||||
}
|
||||
|
||||
type quotaServiceFunc func(c *models.ReqContext, target quota.TargetSrv) (bool, error)
|
||||
type quotaServiceFunc func(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error)
|
||||
|
||||
func (fn quotaServiceFunc) QuotaReached(c *models.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
func (fn quotaServiceFunc) QuotaReached(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
return fn(c, target)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -166,10 +166,10 @@ func (s *serviceMock) ImportDashboard(ctx context.Context, req *dashboardimport.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func quotaReached(c *models.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
func quotaReached(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func quotaNotReached(c *models.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
func quotaNotReached(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
@@ -52,7 +52,7 @@ type DataSourceProxyService struct {
|
||||
secretsService secrets.Service
|
||||
}
|
||||
|
||||
func (p *DataSourceProxyService) ProxyDataSourceRequest(c *models.ReqContext) {
|
||||
func (p *DataSourceProxyService) ProxyDataSourceRequest(c *contextmodel.ReqContext) {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
c.JsonApiErr(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -61,7 +61,7 @@ func (p *DataSourceProxyService) ProxyDataSourceRequest(c *models.ReqContext) {
|
||||
p.ProxyDatasourceRequestWithID(c, id)
|
||||
}
|
||||
|
||||
func (p *DataSourceProxyService) ProxyDatasourceRequestWithUID(c *models.ReqContext, dsUID string) {
|
||||
func (p *DataSourceProxyService) ProxyDatasourceRequestWithUID(c *contextmodel.ReqContext, dsUID string) {
|
||||
c.TimeRequest(metrics.MDataSourceProxyReqTimer)
|
||||
|
||||
if dsUID == "" { // if datasource UID is not provided, fetch it from the uid path parameter
|
||||
@@ -81,7 +81,7 @@ func (p *DataSourceProxyService) ProxyDatasourceRequestWithUID(c *models.ReqCont
|
||||
p.proxyDatasourceRequest(c, ds)
|
||||
}
|
||||
|
||||
func (p *DataSourceProxyService) ProxyDatasourceRequestWithID(c *models.ReqContext, dsID int64) {
|
||||
func (p *DataSourceProxyService) ProxyDatasourceRequestWithID(c *contextmodel.ReqContext, dsID int64) {
|
||||
c.TimeRequest(metrics.MDataSourceProxyReqTimer)
|
||||
|
||||
ds, err := p.DataSourceCache.GetDatasource(c.Req.Context(), dsID, c.SignedInUser, c.SkipCache)
|
||||
@@ -92,7 +92,7 @@ func (p *DataSourceProxyService) ProxyDatasourceRequestWithID(c *models.ReqConte
|
||||
p.proxyDatasourceRequest(c, ds)
|
||||
}
|
||||
|
||||
func toAPIError(c *models.ReqContext, err error) {
|
||||
func toAPIError(c *contextmodel.ReqContext, err error) {
|
||||
if errors.Is(err, datasources.ErrDataSourceAccessDenied) {
|
||||
c.JsonApiErr(http.StatusForbidden, "Access denied to datasource", err)
|
||||
return
|
||||
@@ -104,7 +104,7 @@ func toAPIError(c *models.ReqContext, err error) {
|
||||
c.JsonApiErr(http.StatusInternalServerError, "Unable to load datasource meta data", err)
|
||||
}
|
||||
|
||||
func (p *DataSourceProxyService) proxyDatasourceRequest(c *models.ReqContext, ds *datasources.DataSource) {
|
||||
func (p *DataSourceProxyService) proxyDatasourceRequest(c *contextmodel.ReqContext, ds *datasources.DataSource) {
|
||||
err := p.PluginRequestValidator.Validate(ds.Url, c.Req)
|
||||
if err != nil {
|
||||
c.JsonApiErr(http.StatusForbidden, "Access denied", err)
|
||||
@@ -138,6 +138,6 @@ func extractProxyPath(originalRawPath string) string {
|
||||
return proxyPathRegexp.ReplaceAllString(originalRawPath, "")
|
||||
}
|
||||
|
||||
func getProxyPath(c *models.ReqContext) string {
|
||||
func getProxyPath(c *contextmodel.ReqContext) string {
|
||||
return extractProxyPath(c.Req.URL.EscapedPath())
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -27,16 +27,16 @@ import (
|
||||
|
||||
type ExportService interface {
|
||||
// List folder contents
|
||||
HandleGetStatus(c *models.ReqContext) response.Response
|
||||
HandleGetStatus(c *contextmodel.ReqContext) response.Response
|
||||
|
||||
// List Get Options
|
||||
HandleGetOptions(c *models.ReqContext) response.Response
|
||||
HandleGetOptions(c *contextmodel.ReqContext) response.Response
|
||||
|
||||
// Read raw file contents out of the store
|
||||
HandleRequestExport(c *models.ReqContext) response.Response
|
||||
HandleRequestExport(c *contextmodel.ReqContext) response.Response
|
||||
|
||||
// Cancel any running export
|
||||
HandleRequestStop(c *models.ReqContext) response.Response
|
||||
HandleRequestStop(c *contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
var exporters = []Exporter{
|
||||
@@ -186,21 +186,21 @@ func ProvideService(db db.DB, features featuremgmt.FeatureToggles, gl *live.Graf
|
||||
}
|
||||
}
|
||||
|
||||
func (ex *StandardExport) HandleGetOptions(c *models.ReqContext) response.Response {
|
||||
func (ex *StandardExport) HandleGetOptions(c *contextmodel.ReqContext) response.Response {
|
||||
info := map[string]interface{}{
|
||||
"exporters": exporters,
|
||||
}
|
||||
return response.JSON(http.StatusOK, info)
|
||||
}
|
||||
|
||||
func (ex *StandardExport) HandleGetStatus(c *models.ReqContext) response.Response {
|
||||
func (ex *StandardExport) HandleGetStatus(c *contextmodel.ReqContext) response.Response {
|
||||
ex.mutex.Lock()
|
||||
defer ex.mutex.Unlock()
|
||||
|
||||
return response.JSON(http.StatusOK, ex.exportJob.getStatus())
|
||||
}
|
||||
|
||||
func (ex *StandardExport) HandleRequestStop(c *models.ReqContext) response.Response {
|
||||
func (ex *StandardExport) HandleRequestStop(c *contextmodel.ReqContext) response.Response {
|
||||
ex.mutex.Lock()
|
||||
defer ex.mutex.Unlock()
|
||||
|
||||
@@ -209,7 +209,7 @@ func (ex *StandardExport) HandleRequestStop(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, ex.exportJob.getStatus())
|
||||
}
|
||||
|
||||
func (ex *StandardExport) HandleRequestExport(c *models.ReqContext) response.Response {
|
||||
func (ex *StandardExport) HandleRequestExport(c *contextmodel.ReqContext) response.Response {
|
||||
var cfg ExportConfig
|
||||
err := json.NewDecoder(c.Req.Body).Decode(&cfg)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,25 +4,25 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
var _ ExportService = new(StubExport)
|
||||
|
||||
type StubExport struct{}
|
||||
|
||||
func (ex *StubExport) HandleGetStatus(c *models.ReqContext) response.Response {
|
||||
func (ex *StubExport) HandleGetStatus(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusForbidden, "feature not enabled", nil)
|
||||
}
|
||||
|
||||
func (ex *StubExport) HandleGetOptions(c *models.ReqContext) response.Response {
|
||||
func (ex *StubExport) HandleGetOptions(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusForbidden, "feature not enabled", nil)
|
||||
}
|
||||
|
||||
func (ex *StubExport) HandleRequestExport(c *models.ReqContext) response.Response {
|
||||
func (ex *StubExport) HandleRequestExport(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusForbidden, "feature not enabled", nil)
|
||||
}
|
||||
|
||||
func (ex *StubExport) HandleRequestStop(c *models.ReqContext) response.Response {
|
||||
func (ex *StubExport) HandleRequestStop(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusForbidden, "feature not enabled", nil)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
)
|
||||
|
||||
@@ -151,7 +151,7 @@ func (fm *FeatureManager) GetFlags() []FeatureFlag {
|
||||
return v
|
||||
}
|
||||
|
||||
func (fm *FeatureManager) HandleGetSettings(c *models.ReqContext) {
|
||||
func (fm *FeatureManager) HandleGetSettings(c *contextmodel.ReqContext) {
|
||||
res := make(map[string]interface{}, 3)
|
||||
res["enabled"] = fm.GetEnabled(c.Req.Context())
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@ package hooks
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
type IndexDataHook func(indexData *dtos.IndexViewData, req *models.ReqContext)
|
||||
type IndexDataHook func(indexData *dtos.IndexViewData, req *contextmodel.ReqContext)
|
||||
|
||||
type LoginHook func(loginInfo *models.LoginInfo, req *models.ReqContext)
|
||||
type LoginHook func(loginInfo *models.LoginInfo, req *contextmodel.ReqContext)
|
||||
|
||||
type HooksService struct {
|
||||
indexDataHooks []IndexDataHook
|
||||
@@ -22,7 +23,7 @@ func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
|
||||
srv.indexDataHooks = append(srv.indexDataHooks, hook)
|
||||
}
|
||||
|
||||
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData, req *models.ReqContext) {
|
||||
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData, req *contextmodel.ReqContext) {
|
||||
for _, hook := range srv.indexDataHooks {
|
||||
hook(indexData, req)
|
||||
}
|
||||
@@ -32,7 +33,7 @@ func (srv *HooksService) AddLoginHook(hook LoginHook) {
|
||||
srv.loginHooks = append(srv.loginHooks, hook)
|
||||
}
|
||||
|
||||
func (srv *HooksService) RunLoginHook(loginInfo *models.LoginInfo, req *models.ReqContext) {
|
||||
func (srv *HooksService) RunLoginHook(loginInfo *models.LoginInfo, req *contextmodel.ReqContext) {
|
||||
for _, hook := range srv.loginHooks {
|
||||
hook(loginInfo, req)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -38,7 +38,7 @@ func (l *LibraryElementService) registerAPIEndpoints() {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) createHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := CreateLibraryElementCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -88,7 +88,7 @@ func (l *LibraryElementService) createHandler(c *models.ReqContext) response.Res
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) deleteHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) deleteHandler(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := l.deleteLibraryElement(c.Req.Context(), c.SignedInUser, web.Params(c.Req)[":uid"])
|
||||
if err != nil {
|
||||
return toLibraryElementError(err, "Failed to delete library element")
|
||||
@@ -111,7 +111,7 @@ func (l *LibraryElementService) deleteHandler(c *models.ReqContext) response.Res
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) getHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) getHandler(c *contextmodel.ReqContext) response.Response {
|
||||
element, err := l.getLibraryElementByUid(c.Req.Context(), c.SignedInUser, web.Params(c.Req)[":uid"])
|
||||
if err != nil {
|
||||
return toLibraryElementError(err, "Failed to get library element")
|
||||
@@ -132,7 +132,7 @@ func (l *LibraryElementService) getHandler(c *models.ReqContext) response.Respon
|
||||
// 200: getLibraryElementsResponse
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) getAllHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) getAllHandler(c *contextmodel.ReqContext) response.Response {
|
||||
query := searchLibraryElementsQuery{
|
||||
perPage: c.QueryInt("perPage"),
|
||||
page: c.QueryInt("page"),
|
||||
@@ -166,7 +166,7 @@ func (l *LibraryElementService) getAllHandler(c *models.ReqContext) response.Res
|
||||
// 404: notFoundError
|
||||
// 412: preconditionFailedError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) patchHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) patchHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := PatchLibraryElementCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -213,7 +213,7 @@ func (l *LibraryElementService) patchHandler(c *models.ReqContext) response.Resp
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) getConnectionsHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) getConnectionsHandler(c *contextmodel.ReqContext) response.Response {
|
||||
connections, err := l.getConnections(c.Req.Context(), c.SignedInUser, web.Params(c.Req)[":uid"])
|
||||
if err != nil {
|
||||
return toLibraryElementError(err, "Failed to get connections")
|
||||
@@ -233,7 +233,7 @@ func (l *LibraryElementService) getConnectionsHandler(c *models.ReqContext) resp
|
||||
// 401: unauthorisedError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (l *LibraryElementService) getByNameHandler(c *models.ReqContext) response.Response {
|
||||
func (l *LibraryElementService) getByNameHandler(c *contextmodel.ReqContext) response.Response {
|
||||
elements, err := l.getLibraryElementsByName(c.Req.Context(), c.SignedInUser, web.Params(c.Req)[":name"])
|
||||
if err != nil {
|
||||
return toLibraryElementError(err, "Failed to get library element")
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||
dashboardservice "github.com/grafana/grafana/pkg/services/dashboards/service"
|
||||
@@ -258,7 +259,7 @@ func getCreateCommandWithModel(folderID int64, name string, kind models.LibraryE
|
||||
type scenarioContext struct {
|
||||
ctx *web.Context
|
||||
service *LibraryElementService
|
||||
reqContext *models.ReqContext
|
||||
reqContext *contextmodel.ReqContext
|
||||
user user.SignedInUser
|
||||
folder *folder.Folder
|
||||
initialResult libraryElementResult
|
||||
@@ -468,7 +469,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
ctx: &webCtx,
|
||||
service: &service,
|
||||
sqlStore: sqlStore,
|
||||
reqContext: &models.ReqContext{
|
||||
reqContext: &contextmodel.ReqContext{
|
||||
Context: &webCtx,
|
||||
SignedInUser: &usr,
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ package licensing
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/hooks"
|
||||
"github.com/grafana/grafana/pkg/services/navtree"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -54,7 +54,7 @@ func ProvideService(cfg *setting.Cfg, hooksService *hooks.HooksService) *OSSLice
|
||||
Cfg: cfg,
|
||||
HooksService: hooksService,
|
||||
}
|
||||
l.HooksService.AddIndexDataHook(func(indexData *dtos.IndexViewData, req *models.ReqContext) {
|
||||
l.HooksService.AddIndexDataHook(func(indexData *dtos.IndexViewData, req *contextmodel.ReqContext) {
|
||||
if !req.IsGrafanaAdmin {
|
||||
return
|
||||
}
|
||||
|
||||
+17
-17
@@ -22,12 +22,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/plugincontext"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/comments/commentmodel"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -350,7 +350,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
CheckOrigin: checkOrigin,
|
||||
})
|
||||
|
||||
g.websocketHandler = func(ctx *models.ReqContext) {
|
||||
g.websocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
|
||||
// Centrifuge expects Credentials in context with a current user ID.
|
||||
@@ -363,7 +363,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
wsHandler.ServeHTTP(ctx.Resp, r)
|
||||
}
|
||||
|
||||
g.pushWebsocketHandler = func(ctx *models.ReqContext) {
|
||||
g.pushWebsocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
newCtx := livecontext.SetContextSignedUser(ctx.Req.Context(), user)
|
||||
newCtx = livecontext.SetContextStreamID(newCtx, web.Params(ctx.Req)[":streamId"])
|
||||
@@ -371,7 +371,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
pushWSHandler.ServeHTTP(ctx.Resp, r)
|
||||
}
|
||||
|
||||
g.pushPipelineWebsocketHandler = func(ctx *models.ReqContext) {
|
||||
g.pushPipelineWebsocketHandler = func(ctx *contextmodel.ReqContext) {
|
||||
user := ctx.SignedInUser
|
||||
newCtx := livecontext.SetContextSignedUser(ctx.Req.Context(), user)
|
||||
newCtx = livecontext.SetContextChannelID(newCtx, web.Params(ctx.Req)["*"])
|
||||
@@ -971,7 +971,7 @@ func (g *GrafanaLive) ClientCount(orgID int64, channel string) (int, error) {
|
||||
return len(p.Presence), nil
|
||||
}
|
||||
|
||||
func (g *GrafanaLive) HandleHTTPPublish(ctx *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleHTTPPublish(ctx *contextmodel.ReqContext) response.Response {
|
||||
cmd := dtos.LivePublishCmd{}
|
||||
if err := web.Bind(ctx.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -1047,7 +1047,7 @@ type streamChannelListResponse struct {
|
||||
}
|
||||
|
||||
// HandleListHTTP returns metadata so the UI can build a nice form
|
||||
func (g *GrafanaLive) HandleListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
var channels []*managedstream.ManagedChannel
|
||||
var err error
|
||||
if g.IsHA() {
|
||||
@@ -1065,7 +1065,7 @@ func (g *GrafanaLive) HandleListHTTP(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// HandleInfoHTTP special http response for
|
||||
func (g *GrafanaLive) HandleInfoHTTP(ctx *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleInfoHTTP(ctx *contextmodel.ReqContext) response.Response {
|
||||
path := web.Params(ctx.Req)["*"]
|
||||
if path == "grafana/dashboards/gitops" {
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
@@ -1078,7 +1078,7 @@ func (g *GrafanaLive) HandleInfoHTTP(ctx *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// HandleChannelRulesListHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
result, err := g.pipelineStorage.ListChannelRules(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get channel rules", err)
|
||||
@@ -1139,7 +1139,7 @@ func (s *DryRunRuleStorage) ListChannelRules(_ context.Context, _ int64) ([]pipe
|
||||
}
|
||||
|
||||
// HandlePipelineConvertTestHTTP ...
|
||||
func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1184,7 +1184,7 @@ func (g *GrafanaLive) HandlePipelineConvertTestHTTP(c *models.ReqContext) respon
|
||||
}
|
||||
|
||||
// HandleChannelRulesPostHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1204,7 +1204,7 @@ func (g *GrafanaLive) HandleChannelRulesPostHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleChannelRulesPutHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1227,7 +1227,7 @@ func (g *GrafanaLive) HandleChannelRulesPutHTTP(c *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// HandleChannelRulesDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1248,7 +1248,7 @@ func (g *GrafanaLive) HandleChannelRulesDeleteHTTP(c *models.ReqContext) respons
|
||||
}
|
||||
|
||||
// HandlePipelineEntitiesListHTTP ...
|
||||
func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, util.DynMap{
|
||||
"subscribers": pipeline.SubscribersRegistry,
|
||||
"dataOutputs": pipeline.DataOutputsRegistry,
|
||||
@@ -1259,7 +1259,7 @@ func (g *GrafanaLive) HandlePipelineEntitiesListHTTP(_ *models.ReqContext) respo
|
||||
}
|
||||
|
||||
// HandleWriteConfigsListHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
backends, err := g.pipelineStorage.ListWriteConfigs(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get write configs", err)
|
||||
@@ -1274,7 +1274,7 @@ func (g *GrafanaLive) HandleWriteConfigsListHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleWriteConfigsPostHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1294,7 +1294,7 @@ func (g *GrafanaLive) HandleWriteConfigsPostHTTP(c *models.ReqContext) response.
|
||||
}
|
||||
|
||||
// HandleWriteConfigsPutHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
@@ -1338,7 +1338,7 @@ func (g *GrafanaLive) HandleWriteConfigsPutHTTP(c *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// HandleWriteConfigsDeleteHTTP ...
|
||||
func (g *GrafanaLive) HandleWriteConfigsDeleteHTTP(c *models.ReqContext) response.Response {
|
||||
func (g *GrafanaLive) HandleWriteConfigsDeleteHTTP(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error reading body", err)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
"github.com/grafana/grafana/pkg/services/live/convert"
|
||||
"github.com/grafana/grafana/pkg/services/live/pushurl"
|
||||
@@ -45,7 +45,7 @@ func (g *Gateway) Run(ctx context.Context) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
func (g *Gateway) Handle(ctx *models.ReqContext) {
|
||||
func (g *Gateway) Handle(ctx *contextmodel.ReqContext) {
|
||||
streamID := web.Params(ctx.Req)[":streamId"]
|
||||
|
||||
stream, err := g.GrafanaLive.ManagedStreamRunner.GetOrCreateStream(ctx.SignedInUser.OrgID, liveDto.ScopeStream, streamID)
|
||||
@@ -98,7 +98,7 @@ func (g *Gateway) Handle(ctx *models.ReqContext) {
|
||||
ctx.Resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (g *Gateway) HandlePipelinePush(ctx *models.ReqContext) {
|
||||
func (g *Gateway) HandlePipelinePush(ctx *contextmodel.ReqContext) {
|
||||
channelID := web.Params(ctx.Req)["*"]
|
||||
|
||||
body, err := io.ReadAll(ctx.Req.Body)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package navtree
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
pref "github.com/grafana/grafana/pkg/services/preference"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
GetNavTree(c *models.ReqContext, hasEditPerm bool, prefs *pref.Preference) (*NavTreeRoot, error)
|
||||
GetNavTree(c *contextmodel.ReqContext, hasEditPerm bool, prefs *pref.Preference) (*NavTreeRoot, error)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package navtreeimpl
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
)
|
||||
|
||||
func (s *ServiceImpl) getOrgAdminNode(c *models.ReqContext) (*navtree.NavLink, error) {
|
||||
func (s *ServiceImpl) getOrgAdminNode(c *contextmodel.ReqContext) (*navtree.NavLink, error) {
|
||||
var configNodes []*navtree.NavLink
|
||||
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
@@ -119,7 +119,7 @@ func (s *ServiceImpl) getOrgAdminNode(c *models.ReqContext) (*navtree.NavLink, e
|
||||
return configNode, nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) getServerAdminNode(c *models.ReqContext) *navtree.NavLink {
|
||||
func (s *ServiceImpl) getServerAdminNode(c *contextmodel.ReqContext) *navtree.NavLink {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
hasGlobalAccess := ac.HasGlobalAccess(s.accessControl, s.accesscontrolService, c)
|
||||
orgsAccessEvaluator := ac.EvalPermission(ac.ActionOrgsRead)
|
||||
@@ -204,11 +204,11 @@ func (s *ServiceImpl) getServerAdminNode(c *models.ReqContext) *navtree.NavLink
|
||||
return adminNode
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) ReqCanAdminTeams(c *models.ReqContext) bool {
|
||||
func (s *ServiceImpl) ReqCanAdminTeams(c *contextmodel.ReqContext) bool {
|
||||
return c.OrgRole == org.RoleAdmin || (s.cfg.EditorsCanAdmin && c.OrgRole == org.RoleEditor)
|
||||
}
|
||||
|
||||
func enableServiceAccount(s *ServiceImpl, c *models.ReqContext) bool {
|
||||
func enableServiceAccount(s *ServiceImpl, c *contextmodel.ReqContext) bool {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
return hasAccess(ac.ReqOrgAdmin, serviceaccounts.AccessEvaluator)
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/navtree"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsettings"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func (s *ServiceImpl) addAppLinks(treeRoot *navtree.NavTreeRoot, c *models.ReqContext) error {
|
||||
func (s *ServiceImpl) addAppLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) error {
|
||||
topNavEnabled := s.features.IsEnabled(featuremgmt.FlagTopnav)
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
appLinks := []*navtree.NavLink{}
|
||||
@@ -64,7 +64,7 @@ func (s *ServiceImpl) addAppLinks(treeRoot *navtree.NavTreeRoot, c *models.ReqCo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqContext, topNavEnabled bool, treeRoot *navtree.NavTreeRoot) *navtree.NavLink {
|
||||
func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *contextmodel.ReqContext, topNavEnabled bool, treeRoot *navtree.NavTreeRoot) *navtree.NavLink {
|
||||
hasAccessToInclude := s.hasAccessToInclude(c, plugin.ID)
|
||||
appLink := &navtree.NavLink{
|
||||
Text: plugin.Name,
|
||||
@@ -176,7 +176,7 @@ func (s *ServiceImpl) processAppPlugin(plugin plugins.PluginDTO, c *models.ReqCo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) addPluginToSection(c *models.ReqContext, treeRoot *navtree.NavTreeRoot, plugin plugins.PluginDTO, appLink *navtree.NavLink) {
|
||||
func (s *ServiceImpl) addPluginToSection(c *contextmodel.ReqContext, treeRoot *navtree.NavTreeRoot, plugin plugins.PluginDTO, appLink *navtree.NavLink) {
|
||||
// Handle moving apps into specific navtree sections
|
||||
alertingNode := treeRoot.FindById(navtree.NavIDAlerting)
|
||||
sectionID := navtree.NavIDApps
|
||||
@@ -241,7 +241,7 @@ func (s *ServiceImpl) addPluginToSection(c *models.ReqContext, treeRoot *navtree
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) hasAccessToInclude(c *models.ReqContext, pluginID string) func(include *plugins.Includes) bool {
|
||||
func (s *ServiceImpl) hasAccessToInclude(c *contextmodel.ReqContext, pluginID string) func(include *plugins.Includes) bool {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
return func(include *plugins.Includes) bool {
|
||||
useRBAC := s.features.IsEnabled(featuremgmt.FlagAccessControlOnCall) &&
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/roletype"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/navtree"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
func TestAddAppLinks(t *testing.T) {
|
||||
httpReq, _ := http.NewRequest(http.MethodGet, "", nil)
|
||||
reqCtx := &models.ReqContext{SignedInUser: &user.SignedInUser{}, Context: &web.Context{Req: httpReq}}
|
||||
reqCtx := &contextmodel.ReqContext{SignedInUser: &user.SignedInUser{}, Context: &web.Context{Req: httpReq}}
|
||||
permissions := []ac.Permission{
|
||||
{Action: plugins.ActionAppAccess, Scope: "*"},
|
||||
{Action: plugins.ActionInstall, Scope: "*"},
|
||||
@@ -388,7 +388,7 @@ func TestReadingNavigationSettings(t *testing.T) {
|
||||
func TestAddAppLinksAccessControl(t *testing.T) {
|
||||
httpReq, _ := http.NewRequest(http.MethodGet, "", nil)
|
||||
user := &user.SignedInUser{OrgID: 1}
|
||||
reqCtx := &models.ReqContext{SignedInUser: user, Context: &web.Context{Req: httpReq}}
|
||||
reqCtx := &contextmodel.ReqContext{SignedInUser: user, Context: &web.Context{Req: httpReq}}
|
||||
catalogReadAction := "test-app1.catalog:read"
|
||||
|
||||
testApp1 := plugins.PluginDTO{
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -71,7 +71,7 @@ func ProvideService(cfg *setting.Cfg, accessControl ac.AccessControl, pluginStor
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
func (s *ServiceImpl) GetNavTree(c *models.ReqContext, hasEditPerm bool, prefs *pref.Preference) (*navtree.NavTreeRoot, error) {
|
||||
func (s *ServiceImpl) GetNavTree(c *contextmodel.ReqContext, hasEditPerm bool, prefs *pref.Preference) (*navtree.NavTreeRoot, error) {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
treeRoot := &navtree.NavTreeRoot{}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (s *ServiceImpl) GetNavTree(c *models.ReqContext, hasEditPerm bool, prefs *
|
||||
treeRoot.AddSection(dashboardLink)
|
||||
}
|
||||
|
||||
canExplore := func(context *models.ReqContext) bool {
|
||||
canExplore := func(context *contextmodel.ReqContext) bool {
|
||||
return c.OrgRole == org.RoleAdmin || c.OrgRole == org.RoleEditor || setting.ViewersCanEdit
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ func (s *ServiceImpl) GetNavTree(c *models.ReqContext, hasEditPerm bool, prefs *
|
||||
return treeRoot, nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) getHomeNode(c *models.ReqContext, prefs *pref.Preference) *navtree.NavLink {
|
||||
func (s *ServiceImpl) getHomeNode(c *contextmodel.ReqContext, prefs *pref.Preference) *navtree.NavLink {
|
||||
homeUrl := s.cfg.AppSubURL + "/"
|
||||
homePage := s.cfg.HomePage
|
||||
|
||||
@@ -232,7 +232,7 @@ func (s *ServiceImpl) getHomeNode(c *models.ReqContext, prefs *pref.Preference)
|
||||
return homeNode
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *models.ReqContext) {
|
||||
func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) {
|
||||
if setting.HelpEnabled {
|
||||
helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, setting.BuildCommit)
|
||||
if s.cfg.AnonymousHideVersion && !c.IsSignedIn {
|
||||
@@ -261,7 +261,7 @@ func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *models.ReqC
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) getProfileNode(c *models.ReqContext) *navtree.NavLink {
|
||||
func (s *ServiceImpl) getProfileNode(c *contextmodel.ReqContext) *navtree.NavLink {
|
||||
// Only set login if it's different from the name
|
||||
var login string
|
||||
if c.SignedInUser.Login != c.SignedInUser.NameOrFallback() {
|
||||
@@ -311,7 +311,7 @@ func (s *ServiceImpl) getProfileNode(c *models.ReqContext) *navtree.NavLink {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) buildStarredItemsNavLinks(c *models.ReqContext) ([]*navtree.NavLink, error) {
|
||||
func (s *ServiceImpl) buildStarredItemsNavLinks(c *contextmodel.ReqContext) ([]*navtree.NavLink, error) {
|
||||
starredItemsChildNavs := []*navtree.NavLink{}
|
||||
|
||||
query := star.GetUserStarsQuery{
|
||||
@@ -357,9 +357,9 @@ func (s *ServiceImpl) buildStarredItemsNavLinks(c *models.ReqContext) ([]*navtre
|
||||
return starredItemsChildNavs, nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) buildDashboardNavLinks(c *models.ReqContext, hasEditPerm bool) []*navtree.NavLink {
|
||||
func (s *ServiceImpl) buildDashboardNavLinks(c *contextmodel.ReqContext, hasEditPerm bool) []*navtree.NavLink {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
hasEditPermInAnyFolder := func(c *models.ReqContext) bool {
|
||||
hasEditPermInAnyFolder := func(c *contextmodel.ReqContext) bool {
|
||||
return hasEditPerm
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ func (s *ServiceImpl) buildDashboardNavLinks(c *models.ReqContext, hasEditPerm b
|
||||
return dashboardChildNavs
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) buildLegacyAlertNavLinks(c *models.ReqContext) *navtree.NavLink {
|
||||
func (s *ServiceImpl) buildLegacyAlertNavLinks(c *contextmodel.ReqContext) *navtree.NavLink {
|
||||
var alertChildNavs []*navtree.NavLink
|
||||
alertChildNavs = append(alertChildNavs, &navtree.NavLink{
|
||||
Text: "Alert rules", Id: "alert-list", Url: s.cfg.AppSubURL + "/alerting/list", Icon: "list-ul",
|
||||
@@ -478,7 +478,7 @@ func (s *ServiceImpl) buildLegacyAlertNavLinks(c *models.ReqContext) *navtree.Na
|
||||
return &alertNav
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) buildAlertNavLinks(c *models.ReqContext, hasEditPerm bool) *navtree.NavLink {
|
||||
func (s *ServiceImpl) buildAlertNavLinks(c *contextmodel.ReqContext, hasEditPerm bool) *navtree.NavLink {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
var alertChildNavs []*navtree.NavLink
|
||||
|
||||
@@ -517,7 +517,7 @@ func (s *ServiceImpl) buildAlertNavLinks(c *models.ReqContext, hasEditPerm bool)
|
||||
})
|
||||
}
|
||||
|
||||
fallbackHasEditPerm := func(*models.ReqContext) bool { return hasEditPerm }
|
||||
fallbackHasEditPerm := func(*contextmodel.ReqContext) bool { return hasEditPerm }
|
||||
|
||||
if hasAccess(fallbackHasEditPerm, ac.EvalAny(ac.EvalPermission(ac.ActionAlertingRuleCreate), ac.EvalPermission(ac.ActionAlertingRuleExternalWrite))) {
|
||||
if !s.features.IsEnabled(featuremgmt.FlagTopnav) {
|
||||
@@ -555,7 +555,7 @@ func (s *ServiceImpl) buildAlertNavLinks(c *models.ReqContext, hasEditPerm bool)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) buildDataConnectionsNavLink(c *models.ReqContext) *navtree.NavLink {
|
||||
func (s *ServiceImpl) buildDataConnectionsNavLink(c *contextmodel.ReqContext) *navtree.NavLink {
|
||||
hasAccess := ac.HasAccess(s.accessControl, c)
|
||||
|
||||
var children []*navtree.NavLink
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||
@@ -42,7 +42,7 @@ func (e UnknownReceiverError) Error() string {
|
||||
return fmt.Sprintf("unknown receiver: %s", e.UID)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMStatus(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -51,7 +51,7 @@ func (srv AlertmanagerSrv) RouteGetAMStatus(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, am.GetStatus())
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSilence apimodels.PostableSilence) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteCreateSilence(c *contextmodel.ReqContext, postableSilence apimodels.PostableSilence) response.Response {
|
||||
err := postableSilence.Validate(strfmt.Default)
|
||||
if err != nil {
|
||||
srv.log.Error("silence failed validation", "error", err)
|
||||
@@ -92,7 +92,7 @@ func (srv AlertmanagerSrv) RouteCreateSilence(c *models.ReqContext, postableSile
|
||||
})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -106,7 +106,7 @@ func (srv AlertmanagerSrv) RouteDeleteAlertingConfig(c *models.ReqContext) respo
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "configuration deleted; the default is applied"})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext, silenceID string) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteDeleteSilence(c *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -121,7 +121,7 @@ func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext, silenceID st
|
||||
return response.JSON(http.StatusOK, util.DynMap{"message": "silence deleted"})
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *contextmodel.ReqContext) response.Response {
|
||||
config, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
@@ -132,7 +132,7 @@ func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *models.ReqContext) response
|
||||
return response.JSON(http.StatusOK, config)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -156,7 +156,7 @@ func (srv AlertmanagerSrv) RouteGetAMAlertGroups(c *models.ReqContext) response.
|
||||
return response.JSON(http.StatusOK, groups)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlerts(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetAMAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -183,7 +183,7 @@ func (srv AlertmanagerSrv) RouteGetAMAlerts(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, alerts)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetSilence(c *models.ReqContext, silenceID string) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetSilence(c *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -200,7 +200,7 @@ func (srv AlertmanagerSrv) RouteGetSilence(c *models.ReqContext, silenceID strin
|
||||
return response.JSON(http.StatusOK, gettableSilence)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetSilences(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetSilences(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -217,7 +217,7 @@ func (srv AlertmanagerSrv) RouteGetSilences(c *models.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, gettableSilences)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body apimodels.PostableUserConfig) response.Response {
|
||||
func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *contextmodel.ReqContext, body apimodels.PostableUserConfig) response.Response {
|
||||
currentConfig, err := srv.mam.GetAlertmanagerConfiguration(c.Req.Context(), c.OrgID)
|
||||
// If a config is present and valid we proceed with the guard, otherwise we
|
||||
// just bypass the guard which is okay as we are anyway in an invalid state.
|
||||
@@ -248,7 +248,7 @@ func (srv AlertmanagerSrv) RoutePostAlertingConfig(c *models.ReqContext, body ap
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RouteGetReceivers(c *models.ReqContext) response.Response {
|
||||
func (srv AlertmanagerSrv) RouteGetReceivers(c *contextmodel.ReqContext) response.Response {
|
||||
am, errResp := srv.AlertmanagerFor(c.OrgID)
|
||||
if errResp != nil {
|
||||
return errResp
|
||||
@@ -258,7 +258,7 @@ func (srv AlertmanagerSrv) RouteGetReceivers(c *models.ReqContext) response.Resp
|
||||
return response.JSON(http.StatusOK, rcvs)
|
||||
}
|
||||
|
||||
func (srv AlertmanagerSrv) RoutePostTestReceivers(c *models.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
func (srv AlertmanagerSrv) RoutePostTestReceivers(c *contextmodel.ReqContext, body apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
if err := srv.crypto.LoadSecureSettings(c.Req.Context(), c.OrgID, body.Receivers); err != nil {
|
||||
var unknownReceiverError UnknownReceiverError
|
||||
if errors.As(err, &unknownReceiverError) {
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -166,7 +166,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
sut := createSut(t, nil)
|
||||
|
||||
t.Run("assert 404 Not Found when applying config to nonexistent org", func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -183,7 +183,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("assert 202 when config successfully applied", func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -200,7 +200,7 @@ func TestAlertmanagerConfig(t *testing.T) {
|
||||
|
||||
t.Run("assert 202 when alertmanager to configure is not ready", func(t *testing.T) {
|
||||
sut := createSut(t, nil)
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -330,7 +330,7 @@ func TestSilenceCreate(t *testing.T) {
|
||||
|
||||
for _, cas := range cases {
|
||||
t.Run(cas.name, func(t *testing.T) {
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -456,7 +456,7 @@ func TestRouteCreateSilence(t *testing.T) {
|
||||
ac := tesCase.accessControl()
|
||||
sut := createSut(t, ac)
|
||||
|
||||
rc := models.ReqContext{
|
||||
rc := contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -622,8 +622,8 @@ func withEmptyID(silence *apimodels.PostableSilence) {
|
||||
silence.ID = ""
|
||||
}
|
||||
|
||||
func createRequestCtxInOrg(org int64) *models.ReqContext {
|
||||
return &models.ReqContext{
|
||||
func createRequestCtxInOrg(org int64) *contextmodel.ReqContext {
|
||||
return &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -26,7 +26,7 @@ type ConfigSrv struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetAlertmanagers(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetAlertmanagers(c *contextmodel.ReqContext) response.Response {
|
||||
urls := srv.alertmanagerProvider.AlertmanagersFor(c.OrgID)
|
||||
droppedURLs := srv.alertmanagerProvider.DroppedAlertmanagersFor(c.OrgID)
|
||||
ams := v1.AlertManagersResult{Active: make([]v1.AlertManager, len(urls)), Dropped: make([]v1.AlertManager, len(droppedURLs))}
|
||||
@@ -43,7 +43,7 @@ func (srv ConfigSrv) RouteGetAlertmanagers(c *models.ReqContext) response.Respon
|
||||
})
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (srv ConfigSrv) RouteGetNGalertConfig(c *models.ReqContext) response.Respon
|
||||
return response.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RoutePostNGalertConfig(c *models.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
func (srv ConfigSrv) RoutePostNGalertConfig(c *contextmodel.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (srv ConfigSrv) RoutePostNGalertConfig(c *models.ReqContext, body apimodels
|
||||
return response.JSON(http.StatusCreated, util.DynMap{"message": "admin configuration updated"})
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteDeleteNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteDeleteNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
if c.OrgRole != org.RoleAdmin {
|
||||
return accessForbiddenResp()
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (srv ConfigSrv) externalAlertmanagers(ctx context.Context, orgID int64) ([]
|
||||
return alertmanagers, nil
|
||||
}
|
||||
|
||||
func (srv ConfigSrv) RouteGetAlertingStatus(c *models.ReqContext) response.Response {
|
||||
func (srv ConfigSrv) RouteGetAlertingStatus(c *contextmodel.ReqContext) response.Response {
|
||||
sendsAlertsTo := ngmodels.InternalAlertmanager
|
||||
|
||||
cfg, err := srv.store.GetAdminConfiguration(c.OrgID)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
@@ -32,7 +32,7 @@ type PrometheusSrv struct {
|
||||
|
||||
const queryIncludeInternalLabels = "includeInternalLabels"
|
||||
|
||||
func (srv PrometheusSrv) RouteGetAlertStatuses(c *models.ReqContext) response.Response {
|
||||
func (srv PrometheusSrv) RouteGetAlertStatuses(c *contextmodel.ReqContext) response.Response {
|
||||
alertResponse := apimodels.AlertResponse{
|
||||
DiscoveryBase: apimodels.DiscoveryBase{
|
||||
Status: "success",
|
||||
@@ -105,7 +105,7 @@ func getPanelIDFromRequest(r *http.Request) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Response {
|
||||
func (srv PrometheusSrv) RouteGetRuleStatuses(c *contextmodel.ReqContext) response.Response {
|
||||
dashboardUID := c.Query("dashboard_uid")
|
||||
panelID, err := getPanelIDFromRequest(c.Req)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
|
||||
alertingModels "github.com/grafana/alerting/alerting/models"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
@@ -93,7 +93,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
_, _, _, api := setupAPI(t)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -112,7 +112,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(1, util.GenerateShortUID(), 2)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -154,7 +154,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(1, util.GenerateShortUID(), 2, withAlertingState())
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -196,7 +196,7 @@ func TestRouteGetAlertStatuses(t *testing.T) {
|
||||
fakeAIM.GenerateAlertInstances(orgID, util.GenerateShortUID(), 2)
|
||||
req, err := http.NewRequest("GET", "/api/v1/alerts?includeInternalLabels=true", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID}}
|
||||
|
||||
r := api.RouteGetAlertStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
@@ -258,7 +258,7 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
|
||||
req, err := http.NewRequest("GET", "/api/v1/rules", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
|
||||
t.Run("with no rules", func(t *testing.T) {
|
||||
_, _, _, api := setupAPI(t)
|
||||
@@ -328,7 +328,7 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
|
||||
req, err := http.NewRequest("GET", "/api/v1/rules?includeInternalLabels=true", nil)
|
||||
require.NoError(t, err)
|
||||
c := &models.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
c := &contextmodel.ReqContext{Context: &web.Context{Req: req}, SignedInUser: &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer}}
|
||||
|
||||
r := api.RouteGetRuleStatuses(c)
|
||||
require.Equal(t, http.StatusOK, r.Status())
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
alerting_models "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
|
||||
@@ -62,7 +62,7 @@ type AlertRuleService interface {
|
||||
ReplaceRuleGroup(ctx context.Context, orgID int64, group alerting_models.AlertRuleGroup, userID int64, provenance alerting_models.Provenance) error
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetPolicyTree(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetPolicyTree(c *contextmodel.ReqContext) response.Response {
|
||||
policies, err := srv.policies.GetPolicyTree(c.Req.Context(), c.OrgID)
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return ErrResp(http.StatusNotFound, err, "")
|
||||
@@ -74,7 +74,7 @@ func (srv *ProvisioningSrv) RouteGetPolicyTree(c *models.ReqContext) response.Re
|
||||
return response.JSON(http.StatusOK, policies)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutPolicyTree(c *models.ReqContext, tree definitions.Route) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutPolicyTree(c *contextmodel.ReqContext, tree definitions.Route) response.Response {
|
||||
err := srv.policies.UpdatePolicyTree(c.Req.Context(), c.OrgID, tree, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
|
||||
return ErrResp(http.StatusNotFound, err, "")
|
||||
@@ -89,7 +89,7 @@ func (srv *ProvisioningSrv) RoutePutPolicyTree(c *models.ReqContext, tree defini
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "policies updated"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteResetPolicyTree(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteResetPolicyTree(c *contextmodel.ReqContext) response.Response {
|
||||
tree, err := srv.policies.ResetPolicyTree(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -97,7 +97,7 @@ func (srv *ProvisioningSrv) RouteResetPolicyTree(c *models.ReqContext) response.
|
||||
return response.JSON(http.StatusAccepted, tree)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetContactPoints(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetContactPoints(c *contextmodel.ReqContext) response.Response {
|
||||
q := provisioning.ContactPointQuery{
|
||||
Name: c.Query("name"),
|
||||
OrgID: c.OrgID,
|
||||
@@ -109,7 +109,7 @@ func (srv *ProvisioningSrv) RouteGetContactPoints(c *models.ReqContext) response
|
||||
return response.JSON(http.StatusOK, cps)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostContactPoint(c *models.ReqContext, cp definitions.EmbeddedContactPoint) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostContactPoint(c *contextmodel.ReqContext, cp definitions.EmbeddedContactPoint) response.Response {
|
||||
// TODO: provenance is hardcoded for now, change it later to make it more flexible
|
||||
contactPoint, err := srv.contactPointService.CreateContactPoint(c.Req.Context(), c.OrgID, cp, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
@@ -121,7 +121,7 @@ func (srv *ProvisioningSrv) RoutePostContactPoint(c *models.ReqContext, cp defin
|
||||
return response.JSON(http.StatusAccepted, contactPoint)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutContactPoint(c *models.ReqContext, cp definitions.EmbeddedContactPoint, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutContactPoint(c *contextmodel.ReqContext, cp definitions.EmbeddedContactPoint, UID string) response.Response {
|
||||
cp.UID = UID
|
||||
err := srv.contactPointService.UpdateContactPoint(c.Req.Context(), c.OrgID, cp, alerting_models.ProvenanceAPI)
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
@@ -136,7 +136,7 @@ func (srv *ProvisioningSrv) RoutePutContactPoint(c *models.ReqContext, cp defini
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "contactpoint updated"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
err := srv.contactPointService.DeleteContactPoint(c.Req.Context(), c.OrgID, UID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -144,7 +144,7 @@ func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *models.ReqContext, UID st
|
||||
return response.JSON(http.StatusAccepted, util.DynMap{"message": "contactpoint deleted"})
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetTemplates(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetTemplates(c *contextmodel.ReqContext) response.Response {
|
||||
templates, err := srv.templates.GetTemplates(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -156,7 +156,7 @@ func (srv *ProvisioningSrv) RouteGetTemplates(c *models.ReqContext) response.Res
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetTemplate(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetTemplate(c *contextmodel.ReqContext, name string) response.Response {
|
||||
templates, err := srv.templates.GetTemplates(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -167,7 +167,7 @@ func (srv *ProvisioningSrv) RouteGetTemplate(c *models.ReqContext, name string)
|
||||
return response.Empty(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definitions.NotificationTemplateContent, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutTemplate(c *contextmodel.ReqContext, body definitions.NotificationTemplateContent, name string) response.Response {
|
||||
tmpl := definitions.NotificationTemplate{
|
||||
Name: name,
|
||||
Template: body.Template,
|
||||
@@ -183,7 +183,7 @@ func (srv *ProvisioningSrv) RoutePutTemplate(c *models.ReqContext, body definiti
|
||||
return response.JSON(http.StatusAccepted, modified)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteTemplate(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteTemplate(c *contextmodel.ReqContext, name string) response.Response {
|
||||
err := srv.templates.DeleteTemplate(c.Req.Context(), c.OrgID, name)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -191,7 +191,7 @@ func (srv *ProvisioningSrv) RouteDeleteTemplate(c *models.ReqContext, name strin
|
||||
return response.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTiming(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -204,7 +204,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTiming(c *models.ReqContext, name string
|
||||
return response.Empty(http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimings(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimings(c *contextmodel.ReqContext) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -212,7 +212,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTimings(c *models.ReqContext) response.R
|
||||
return response.JSON(http.StatusOK, timings)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostMuteTiming(c *models.ReqContext, mt definitions.MuteTimeInterval) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostMuteTiming(c *contextmodel.ReqContext, mt definitions.MuteTimeInterval) response.Response {
|
||||
mt.Provenance = alerting_models.ProvenanceAPI
|
||||
created, err := srv.muteTimings.CreateMuteTiming(c.Req.Context(), mt, c.OrgID)
|
||||
if err != nil {
|
||||
@@ -224,7 +224,7 @@ func (srv *ProvisioningSrv) RoutePostMuteTiming(c *models.ReqContext, mt definit
|
||||
return response.JSON(http.StatusCreated, created)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutMuteTiming(c *models.ReqContext, mt definitions.MuteTimeInterval, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutMuteTiming(c *contextmodel.ReqContext, mt definitions.MuteTimeInterval, name string) response.Response {
|
||||
mt.Name = name
|
||||
mt.Provenance = alerting_models.ProvenanceAPI
|
||||
updated, err := srv.muteTimings.UpdateMuteTiming(c.Req.Context(), mt, c.OrgID)
|
||||
@@ -240,7 +240,7 @@ func (srv *ProvisioningSrv) RoutePutMuteTiming(c *models.ReqContext, mt definiti
|
||||
return response.JSON(http.StatusAccepted, updated)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *models.ReqContext, name string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
err := srv.muteTimings.DeleteMuteTiming(c.Req.Context(), name, c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -248,7 +248,7 @@ func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *models.ReqContext, name str
|
||||
return response.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRules(c *models.ReqContext) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRules(c *contextmodel.ReqContext) response.Response {
|
||||
rules, err := srv.alertRules.GetAlertRules(c.Req.Context(), c.OrgID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -256,7 +256,7 @@ func (srv *ProvisioningSrv) RouteGetAlertRules(c *models.ReqContext) response.Re
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRules(rules))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
rule, provenace, err := srv.alertRules.GetAlertRule(c.Req.Context(), c.OrgID, UID)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -264,7 +264,7 @@ func (srv *ProvisioningSrv) RouteRouteGetAlertRule(c *models.ReqContext, UID str
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRule(rule, provenace))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePostAlertRule(c *models.ReqContext, ar definitions.ProvisionedAlertRule) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePostAlertRule(c *contextmodel.ReqContext, ar definitions.ProvisionedAlertRule) response.Response {
|
||||
upstreamModel, err := ar.UpstreamModel()
|
||||
upstreamModel.OrgID = c.OrgID
|
||||
if err != nil {
|
||||
@@ -289,7 +289,7 @@ func (srv *ProvisioningSrv) RoutePostAlertRule(c *models.ReqContext, ar definiti
|
||||
return response.JSON(http.StatusCreated, resp)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRule(c *models.ReqContext, ar definitions.ProvisionedAlertRule, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRule(c *contextmodel.ReqContext, ar definitions.ProvisionedAlertRule, UID string) response.Response {
|
||||
updated, err := ar.UpstreamModel()
|
||||
if err != nil {
|
||||
ErrResp(http.StatusBadRequest, err, "")
|
||||
@@ -315,7 +315,7 @@ func (srv *ProvisioningSrv) RoutePutAlertRule(c *models.ReqContext, ar definitio
|
||||
return response.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *models.ReqContext, UID string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *contextmodel.ReqContext, UID string) response.Response {
|
||||
err := srv.alertRules.DeleteAlertRule(c.Req.Context(), c.OrgID, UID, alerting_models.ProvenanceAPI)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -323,7 +323,7 @@ func (srv *ProvisioningSrv) RouteDeleteAlertRule(c *models.ReqContext, UID strin
|
||||
return response.JSON(http.StatusNoContent, "")
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *models.ReqContext, folder string, group string) response.Response {
|
||||
func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *contextmodel.ReqContext, folder string, group string) response.Response {
|
||||
g, err := srv.alertRules.GetRuleGroup(c.Req.Context(), c.OrgID, folder, group)
|
||||
if err != nil {
|
||||
if errors.Is(err, store.ErrAlertRuleGroupNotFound) {
|
||||
@@ -334,7 +334,7 @@ func (srv *ProvisioningSrv) RouteGetAlertRuleGroup(c *models.ReqContext, folder
|
||||
return response.JSON(http.StatusOK, definitions.NewAlertRuleGroupFromModel(g))
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *models.ReqContext, ag definitions.AlertRuleGroup, folderUID string, group string) response.Response {
|
||||
func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *contextmodel.ReqContext, ag definitions.AlertRuleGroup, folderUID string, group string) response.Response {
|
||||
ag.FolderUID = folderUID
|
||||
ag.Title = group
|
||||
groupModel, err := ag.ToModel()
|
||||
@@ -354,7 +354,7 @@ func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *models.ReqContext, ag defi
|
||||
return response.JSON(http.StatusOK, ag)
|
||||
}
|
||||
|
||||
func determineProvenance(ctx *models.ReqContext) alerting_models.Provenance {
|
||||
func determineProvenance(ctx *contextmodel.ReqContext) alerting_models.Provenance {
|
||||
if _, disabled := ctx.Req.Header[disableProvenanceHeaderName]; disabled {
|
||||
return alerting_models.ProvenanceNone
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
gfcore "github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/provisioning"
|
||||
@@ -438,8 +438,8 @@ func createProvisioningSrvSutFromEnv(t *testing.T, env *testEnvironment) Provisi
|
||||
}
|
||||
}
|
||||
|
||||
func createTestRequestCtx() gfcore.ReqContext {
|
||||
return gfcore.ReqContext{
|
||||
func createTestRequestCtx() contextmodel.ReqContext {
|
||||
return contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/schedule"
|
||||
@@ -53,7 +53,7 @@ var (
|
||||
// or, if non-empty, a specific group of rules in the namespace.
|
||||
// Returns http.StatusUnauthorized if user does not have access to any of the rules that match the filter.
|
||||
// Returns http.StatusBadRequest if all rules that match the filter and the user is authorized to delete are provisioned.
|
||||
func (srv RulerSrv) RouteDeleteAlertRules(c *models.ReqContext, namespaceTitle string, group string) response.Response {
|
||||
func (srv RulerSrv) RouteDeleteAlertRules(c *contextmodel.ReqContext, namespaceTitle string, group string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, true)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -155,7 +155,7 @@ func (srv RulerSrv) RouteDeleteAlertRules(c *models.ReqContext, namespaceTitle s
|
||||
}
|
||||
|
||||
// RouteGetNamespaceRulesConfig returns all rules in a specific folder that user has access to
|
||||
func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext, namespaceTitle string) response.Response {
|
||||
func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *contextmodel.ReqContext, namespaceTitle string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, false)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -197,7 +197,7 @@ func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *models.ReqContext, namespace
|
||||
|
||||
// RouteGetRulesGroupConfig returns rules that belong to a specific group in a specific namespace (folder).
|
||||
// If user does not have access to at least one of the rule in the group, returns status 401 Unauthorized
|
||||
func (srv RulerSrv) RouteGetRulesGroupConfig(c *models.ReqContext, namespaceTitle string, ruleGroup string) response.Response {
|
||||
func (srv RulerSrv) RouteGetRulesGroupConfig(c *contextmodel.ReqContext, namespaceTitle string, ruleGroup string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, false)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -232,7 +232,7 @@ func (srv RulerSrv) RouteGetRulesGroupConfig(c *models.ReqContext, namespaceTitl
|
||||
}
|
||||
|
||||
// RouteGetRulesConfig returns all alert rules that are available to the current user
|
||||
func (srv RulerSrv) RouteGetRulesConfig(c *models.ReqContext) response.Response {
|
||||
func (srv RulerSrv) RouteGetRulesConfig(c *contextmodel.ReqContext) response.Response {
|
||||
namespaceMap, err := srv.store.GetUserVisibleNamespaces(c.Req.Context(), c.OrgID, c.SignedInUser)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "failed to get namespaces visible to the user")
|
||||
@@ -301,7 +301,7 @@ func (srv RulerSrv) RouteGetRulesConfig(c *models.ReqContext) response.Response
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConfig apimodels.PostableRuleGroupConfig, namespaceTitle string) response.Response {
|
||||
func (srv RulerSrv) RoutePostNameRulesConfig(c *contextmodel.ReqContext, ruleGroupConfig apimodels.PostableRuleGroupConfig, namespaceTitle string) response.Response {
|
||||
namespace, err := srv.store.GetNamespaceByTitle(c.Req.Context(), namespaceTitle, c.SignedInUser.OrgID, c.SignedInUser, true)
|
||||
if err != nil {
|
||||
return toNamespaceErrorResponse(err)
|
||||
@@ -325,7 +325,7 @@ func (srv RulerSrv) RoutePostNameRulesConfig(c *models.ReqContext, ruleGroupConf
|
||||
|
||||
// updateAlertRulesInGroup calculates changes (rules to add,update,delete), verifies that the user is authorized to do the calculated changes and updates database.
|
||||
// All operations are performed in a single transaction
|
||||
func (srv RulerSrv) updateAlertRulesInGroup(c *models.ReqContext, groupKey ngmodels.AlertRuleGroupKey, rules []*ngmodels.AlertRule) response.Response {
|
||||
func (srv RulerSrv) updateAlertRulesInGroup(c *contextmodel.ReqContext, groupKey ngmodels.AlertRuleGroupKey, rules []*ngmodels.AlertRule) response.Response {
|
||||
var finalChanges *store.GroupDelta
|
||||
hasAccess := accesscontrol.HasAccess(srv.ac, c)
|
||||
err := srv.xactManager.InTransaction(c.Req.Context(), func(tranCtx context.Context) error {
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
models2 "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -657,7 +657,7 @@ func createService(ac *acMock.Mock, store *fakes.RuleStore, scheduler schedule.S
|
||||
}
|
||||
}
|
||||
|
||||
func createRequestContext(orgID int64, role org.RoleType, params map[string]string) *models2.ReqContext {
|
||||
func createRequestContext(orgID int64, role org.RoleType, params map[string]string) *contextmodel.ReqContext {
|
||||
uri, _ := url.Parse("http://localhost")
|
||||
ctx := web.Context{Req: &http.Request{
|
||||
URL: uri,
|
||||
@@ -666,7 +666,7 @@ func createRequestContext(orgID int64, role org.RoleType, params map[string]stri
|
||||
ctx.Req = web.SetURLParams(ctx.Req, params)
|
||||
}
|
||||
|
||||
return &models2.ReqContext{
|
||||
return &contextmodel.ReqContext{
|
||||
IsSignedIn: true,
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgRole: role,
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -35,7 +35,7 @@ type TestingApiSrv struct {
|
||||
featureManager featuremgmt.FeatureToggles
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
if body.Type() != apimodels.GrafanaBackend || body.GrafanaManagedCondition == nil {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, body.Type().String()))
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (srv TestingApiSrv) RouteTestGrafanaRuleConfig(c *models.ReqContext, body a
|
||||
})
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload, datasourceUID string) response.Response {
|
||||
func (srv TestingApiSrv) RouteTestRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload, datasourceUID string) response.Response {
|
||||
if body.Type() != apimodels.LoTexRulerBackend {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.LoTexRulerBackend, body.Type().String()))
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (srv TestingApiSrv) RouteTestRuleConfig(c *models.ReqContext, body apimodel
|
||||
)
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) RouteEvalQueries(c *models.ReqContext, cmd apimodels.EvalQueriesPayload) response.Response {
|
||||
func (srv TestingApiSrv) RouteEvalQueries(c *contextmodel.ReqContext, cmd apimodels.EvalQueriesPayload) response.Response {
|
||||
if !authorizeDatasourceAccessForRule(&ngmodels.AlertRule{Data: cmd.Data}, func(evaluator accesscontrol.Evaluator) bool {
|
||||
return accesscontrol.HasAccess(srv.accessControl, c)(accesscontrol.ReqSignedIn, evaluator)
|
||||
}) {
|
||||
@@ -145,7 +145,7 @@ func (srv TestingApiSrv) RouteEvalQueries(c *models.ReqContext, cmd apimodels.Ev
|
||||
return response.JSONStreaming(http.StatusOK, evalResults)
|
||||
}
|
||||
|
||||
func (srv TestingApiSrv) BacktestAlertRule(c *models.ReqContext, cmd apimodels.BacktestConfig) response.Response {
|
||||
func (srv TestingApiSrv) BacktestAlertRule(c *contextmodel.ReqContext, cmd apimodels.BacktestConfig) response.Response {
|
||||
if !srv.featureManager.IsEnabled(featuremgmt.FlagAlertingBacktesting) {
|
||||
return ErrResp(http.StatusNotFound, nil, "Backgtesting API is not enabled")
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
models2 "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acMock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
fakes "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
t.Run("when fine-grained access is enabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -95,7 +95,7 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("when fine-grained access is disabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -152,7 +152,7 @@ func TestRouteTestGrafanaRuleConfig(t *testing.T) {
|
||||
|
||||
func TestRouteEvalQueries(t *testing.T) {
|
||||
t.Run("when fine-grained access is enabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
@@ -222,7 +222,7 @@ func TestRouteEvalQueries(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("when fine-grained access is disabled", func(t *testing.T) {
|
||||
rc := &models2.ReqContext{
|
||||
rc := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -17,22 +17,22 @@ func NewConfiguration(grafana *ConfigSrv) *ConfigurationApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetAlertmanagers(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetAlertmanagers(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetAlertmanagers(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetNGalertConfig(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRoutePostNGalertConfig(c *models.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRoutePostNGalertConfig(c *contextmodel.ReqContext, body apimodels.PostableNGalertConfig) response.Response {
|
||||
return f.grafana.RoutePostNGalertConfig(c, body)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteDeleteNGalertConfig(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteDeleteNGalertConfig(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteDeleteNGalertConfig(c)
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) handleRouteGetStatus(c *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) handleRouteGetStatus(c *contextmodel.ReqContext) response.Response {
|
||||
return f.grafana.RouteGetAlertingStatus(c)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingAM(datasourceCache datasources.CacheService, proxy *LotexAM, graf
|
||||
}
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) getService(ctx *models.ReqContext) (*LotexAM, error) {
|
||||
func (f *AlertmanagerApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexAM, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.AlertmanagerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -30,7 +30,7 @@ func (f *AlertmanagerApiHandler) getService(ctx *models.ReqContext) (*LotexAM, e
|
||||
return f.AMSvc, nil
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -39,7 +39,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMStatus(ctx *models.ReqContext,
|
||||
return s.RouteGetAMStatus(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *models.ReqContext, body apimodels.PostableSilence, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *contextmodel.ReqContext, body apimodels.PostableSilence, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -48,7 +48,7 @@ func (f *AlertmanagerApiHandler) handleRouteCreateSilence(ctx *models.ReqContext
|
||||
return s.RouteCreateSilence(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -57,7 +57,7 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteAlertingConfig(ctx *models.Req
|
||||
return s.RouteDeleteAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *models.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -66,7 +66,7 @@ func (f *AlertmanagerApiHandler) handleRouteDeleteSilence(ctx *models.ReqContext
|
||||
return s.RouteDeleteSilence(ctx, silenceID)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -75,7 +75,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAlertingConfig(ctx *models.ReqCon
|
||||
return s.RouteGetAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -84,7 +84,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlertGroups(ctx *models.ReqCont
|
||||
return s.RouteGetAMAlertGroups(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -93,7 +93,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetAMAlerts(ctx *models.ReqContext,
|
||||
return s.RouteGetAMAlerts(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *models.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *contextmodel.ReqContext, silenceID string, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -102,7 +102,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilence(ctx *models.ReqContext, s
|
||||
return s.RouteGetSilence(ctx, silenceID)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -111,7 +111,7 @@ func (f *AlertmanagerApiHandler) handleRouteGetSilences(ctx *models.ReqContext,
|
||||
return s.RouteGetSilences(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *models.ReqContext, body apimodels.PostableUserConfig, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *contextmodel.ReqContext, body apimodels.PostableUserConfig, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -122,7 +122,7 @@ func (f *AlertmanagerApiHandler) handleRoutePostAlertingConfig(ctx *models.ReqCo
|
||||
return s.RoutePostAlertingConfig(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *models.ReqContext, body apimodels.PostableAlerts, dsUID string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *contextmodel.ReqContext, body apimodels.PostableAlerts, dsUID string) response.Response {
|
||||
s, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -131,53 +131,53 @@ func (f *AlertmanagerApiHandler) handleRoutePostAMAlerts(ctx *models.ReqContext,
|
||||
return s.RoutePostAMAlerts(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaSilence(ctx *models.ReqContext, id string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaSilence(ctx *contextmodel.ReqContext, id string) response.Response {
|
||||
return f.GrafanaSvc.RouteDeleteSilence(ctx, id)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteDeleteGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteDeleteAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateGrafanaSilence(ctx *models.ReqContext, body apimodels.PostableSilence) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteCreateGrafanaSilence(ctx *contextmodel.ReqContext, body apimodels.PostableSilence) response.Response {
|
||||
return f.GrafanaSvc.RouteCreateSilence(ctx, body)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMStatus(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMAlerts(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAMAlertGroups(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAlertingConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilence(ctx *models.ReqContext, id string) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilence(ctx *contextmodel.ReqContext, id string) response.Response {
|
||||
return f.GrafanaSvc.RouteGetSilence(ctx, id)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetSilences(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostGrafanaAlertingConfig(ctx *models.ReqContext, conf apimodels.PostableUserConfig) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostGrafanaAlertingConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableUserConfig) response.Response {
|
||||
if !conf.AlertmanagerConfig.ReceiverType().Can(apimodels.GrafanaReceiverType) {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, conf.AlertmanagerConfig.ReceiverType().String()))
|
||||
}
|
||||
return f.GrafanaSvc.RoutePostAlertingConfig(ctx, conf)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRouteGetGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetReceivers(ctx)
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostTestGrafanaReceivers(ctx *models.ReqContext, conf apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
func (f *AlertmanagerApiHandler) handleRoutePostTestGrafanaReceivers(ctx *contextmodel.ReqContext, conf apimodels.TestReceiversConfigBodyParams) response.Response {
|
||||
return f.GrafanaSvc.RoutePostTestReceivers(ctx, conf)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingProm(datasourceCache datasources.CacheService, proxy *LotexProm,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -30,7 +30,7 @@ func (f *PrometheusApiHandler) handleRouteGetAlertStatuses(ctx *models.ReqContex
|
||||
return t.RouteGetAlertStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -38,15 +38,15 @@ func (f *PrometheusApiHandler) handleRouteGetRuleStatuses(ctx *models.ReqContext
|
||||
return t.RouteGetRuleStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetAlertStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) handleRouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaSvc.RouteGetRuleStatuses(ctx)
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) getService(ctx *models.ReqContext) (*LotexProm, error) {
|
||||
func (f *PrometheusApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexProm, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func NewForkingRuler(datasourceCache datasources.CacheService, lotex *LotexRuler
|
||||
}
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -30,7 +30,7 @@ func (f *RulerApiHandler) handleRouteDeleteNamespaceRulesConfig(ctx *models.ReqC
|
||||
return t.RouteDeleteNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *models.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -38,7 +38,7 @@ func (f *RulerApiHandler) handleRouteDeleteRuleGroupConfig(ctx *models.ReqContex
|
||||
return t.RouteDeleteRuleGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *models.ReqContext, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -46,7 +46,7 @@ func (f *RulerApiHandler) handleRouteGetNamespaceRulesConfig(ctx *models.ReqCont
|
||||
return t.RouteGetNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *models.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *contextmodel.ReqContext, dsUID, namespace, group string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -54,7 +54,7 @@ func (f *RulerApiHandler) handleRouteGetRulegGroupConfig(ctx *models.ReqContext,
|
||||
return t.RouteGetRulegGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *models.ReqContext, dsUID string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *contextmodel.ReqContext, dsUID string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -62,7 +62,7 @@ func (f *RulerApiHandler) handleRouteGetRulesConfig(ctx *models.ReqContext, dsUI
|
||||
return t.RouteGetRulesConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, dsUID, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, dsUID, namespace string) response.Response {
|
||||
t, err := f.getService(ctx)
|
||||
if err != nil {
|
||||
return errorToResponse(err)
|
||||
@@ -73,27 +73,27 @@ func (f *RulerApiHandler) handleRoutePostNameRulesConfig(ctx *models.ReqContext,
|
||||
return t.RoutePostNameRulesConfig(ctx, conf, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceGrafanaRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
return f.GrafanaRuler.RouteDeleteAlertRules(ctx, namespace, "")
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteDeleteGrafanaRuleGroupConfig(ctx *models.ReqContext, namespace, groupName string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext, namespace, groupName string) response.Response {
|
||||
return f.GrafanaRuler.RouteDeleteAlertRules(ctx, namespace, groupName)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceGrafanaRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
return f.GrafanaRuler.RouteGetNamespaceRulesConfig(ctx, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRuleGroupConfig(ctx *models.ReqContext, namespace, group string) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext, namespace, group string) response.Response {
|
||||
return f.GrafanaRuler.RouteGetRulesGroupConfig(ctx, namespace, group)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) handleRouteGetGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.GrafanaRuler.RouteGetRulesConfig(ctx)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, namespace string) response.Response {
|
||||
func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, namespace string) response.Response {
|
||||
payloadType := conf.Type()
|
||||
if payloadType != apimodels.GrafanaBackend {
|
||||
return errorToResponse(backendTypeDoesNotMatchPayloadTypeError(apimodels.GrafanaBackend, conf.Type().String()))
|
||||
@@ -101,7 +101,7 @@ func (f *RulerApiHandler) handleRoutePostNameGrafanaRulesConfig(ctx *models.ReqC
|
||||
return f.GrafanaRuler.RoutePostNameRulesConfig(ctx, conf, namespace)
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) getService(ctx *models.ReqContext) (*LotexRuler, error) {
|
||||
func (f *RulerApiHandler) getService(ctx *contextmodel.ReqContext) (*LotexRuler, error) {
|
||||
_, err := getDatasourceByUID(ctx, f.DatasourceCache, apimodels.LoTexRulerBackend)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -12,39 +12,39 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type AlertmanagerApi interface {
|
||||
RouteCreateGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteCreateSilence(*models.ReqContext) response.Response
|
||||
RouteDeleteAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteDeleteSilence(*models.ReqContext) response.Response
|
||||
RouteGetAMAlertGroups(*models.ReqContext) response.Response
|
||||
RouteGetAMAlerts(*models.ReqContext) response.Response
|
||||
RouteGetAMStatus(*models.ReqContext) response.Response
|
||||
RouteGetAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlertGroups(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlerts(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAMStatus(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaReceivers(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaSilence(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaSilences(*models.ReqContext) response.Response
|
||||
RouteGetSilence(*models.ReqContext) response.Response
|
||||
RouteGetSilences(*models.ReqContext) response.Response
|
||||
RoutePostAMAlerts(*models.ReqContext) response.Response
|
||||
RoutePostAlertingConfig(*models.ReqContext) response.Response
|
||||
RoutePostGrafanaAlertingConfig(*models.ReqContext) response.Response
|
||||
RoutePostTestGrafanaReceivers(*models.ReqContext) response.Response
|
||||
RouteCreateGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteCreateSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMAlertGroups(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAMStatus(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlertGroups(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAMStatus(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaReceivers(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaSilences(*contextmodel.ReqContext) response.Response
|
||||
RouteGetSilence(*contextmodel.ReqContext) response.Response
|
||||
RouteGetSilences(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAMAlerts(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostGrafanaAlertingConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostTestGrafanaReceivers(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableSilence{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -52,7 +52,7 @@ func (f *AlertmanagerApiHandler) RouteCreateGrafanaSilence(ctx *models.ReqContex
|
||||
}
|
||||
return f.handleRouteCreateGrafanaSilence(ctx, conf)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -62,80 +62,80 @@ func (f *AlertmanagerApiHandler) RouteCreateSilence(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRouteCreateSilence(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteDeleteAlertingConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteDeleteGrafanaAlertingConfig(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
return f.handleRouteDeleteGrafanaSilence(ctx, silenceIdParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteDeleteSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteDeleteSilence(ctx, silenceIdParam, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMAlertGroups(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMAlerts(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAMStatus(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAlertingConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMAlertGroups(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMAlerts(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAMStatus(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAlertingConfig(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaReceivers(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
return f.handleRouteGetGrafanaSilence(ctx, silenceIdParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetGrafanaSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaSilences(ctx)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilence(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilence(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
silenceIdParam := web.Params(ctx.Req)[":SilenceId"]
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetSilence(ctx, silenceIdParam, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RouteGetSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetSilences(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -145,7 +145,7 @@ func (f *AlertmanagerApiHandler) RoutePostAMAlerts(ctx *models.ReqContext) respo
|
||||
}
|
||||
return f.handleRoutePostAMAlerts(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -155,7 +155,7 @@ func (f *AlertmanagerApiHandler) RoutePostAlertingConfig(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePostAlertingConfig(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableUserConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -163,7 +163,7 @@ func (f *AlertmanagerApiHandler) RoutePostGrafanaAlertingConfig(ctx *models.ReqC
|
||||
}
|
||||
return f.handleRoutePostGrafanaAlertingConfig(ctx, conf)
|
||||
}
|
||||
func (f *AlertmanagerApiHandler) RoutePostTestGrafanaReceivers(ctx *models.ReqContext) response.Response {
|
||||
func (f *AlertmanagerApiHandler) RoutePostTestGrafanaReceivers(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.TestReceiversConfigBodyParams{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,33 +12,33 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type ConfigurationApi interface {
|
||||
RouteDeleteNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteGetAlertmanagers(*models.ReqContext) response.Response
|
||||
RouteGetNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteGetStatus(*models.ReqContext) response.Response
|
||||
RoutePostNGalertConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertmanagers(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetStatus(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNGalertConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *ConfigurationApiHandler) RouteDeleteNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteDeleteNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteDeleteNGalertConfig(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetAlertmanagers(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetAlertmanagers(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetAlertmanagers(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetNGalertConfig(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RouteGetStatus(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RouteGetStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetStatus(ctx)
|
||||
}
|
||||
func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *ConfigurationApiHandler) RoutePostNGalertConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.PostableNGalertConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,30 +12,30 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type PrometheusApi interface {
|
||||
RouteGetAlertStatuses(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertStatuses(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleStatuses(*models.ReqContext) response.Response
|
||||
RouteGetRuleStatuses(*models.ReqContext) response.Response
|
||||
RouteGetAlertStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaAlertStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleStatuses(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRuleStatuses(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetAlertStatuses(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaAlertStatuses(ctx)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetGrafanaRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaRuleStatuses(ctx)
|
||||
}
|
||||
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (f *PrometheusApiHandler) RouteGetRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetRuleStatuses(ctx, datasourceUIDParam)
|
||||
|
||||
@@ -12,95 +12,95 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type ProvisioningApi interface {
|
||||
RouteDeleteAlertRule(*models.ReqContext) response.Response
|
||||
RouteDeleteContactpoints(*models.ReqContext) response.Response
|
||||
RouteDeleteMuteTiming(*models.ReqContext) response.Response
|
||||
RouteDeleteTemplate(*models.ReqContext) response.Response
|
||||
RouteGetAlertRule(*models.ReqContext) response.Response
|
||||
RouteGetAlertRuleGroup(*models.ReqContext) response.Response
|
||||
RouteGetAlertRules(*models.ReqContext) response.Response
|
||||
RouteGetContactpoints(*models.ReqContext) response.Response
|
||||
RouteGetMuteTiming(*models.ReqContext) response.Response
|
||||
RouteGetMuteTimings(*models.ReqContext) response.Response
|
||||
RouteGetPolicyTree(*models.ReqContext) response.Response
|
||||
RouteGetTemplate(*models.ReqContext) response.Response
|
||||
RouteGetTemplates(*models.ReqContext) response.Response
|
||||
RoutePostAlertRule(*models.ReqContext) response.Response
|
||||
RoutePostContactpoints(*models.ReqContext) response.Response
|
||||
RoutePostMuteTiming(*models.ReqContext) response.Response
|
||||
RoutePutAlertRule(*models.ReqContext) response.Response
|
||||
RoutePutAlertRuleGroup(*models.ReqContext) response.Response
|
||||
RoutePutContactpoint(*models.ReqContext) response.Response
|
||||
RoutePutMuteTiming(*models.ReqContext) response.Response
|
||||
RoutePutPolicyTree(*models.ReqContext) response.Response
|
||||
RoutePutTemplate(*models.ReqContext) response.Response
|
||||
RouteResetPolicyTree(*models.ReqContext) response.Response
|
||||
RouteDeleteAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRuleGroup(*contextmodel.ReqContext) response.Response
|
||||
RouteGetAlertRules(*contextmodel.ReqContext) response.Response
|
||||
RouteGetContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RouteGetMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RouteGetMuteTimings(*contextmodel.ReqContext) response.Response
|
||||
RouteGetPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
RouteGetTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteGetTemplates(*contextmodel.ReqContext) response.Response
|
||||
RoutePostAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RoutePostContactpoints(*contextmodel.ReqContext) response.Response
|
||||
RoutePostMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RoutePutAlertRule(*contextmodel.ReqContext) response.Response
|
||||
RoutePutAlertRuleGroup(*contextmodel.ReqContext) response.Response
|
||||
RoutePutContactpoint(*contextmodel.ReqContext) response.Response
|
||||
RoutePutMuteTiming(*contextmodel.ReqContext) response.Response
|
||||
RoutePutPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
RoutePutTemplate(*contextmodel.ReqContext) response.Response
|
||||
RouteResetPolicyTree(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) RouteDeleteAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteDeleteAlertRule(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteDeleteContactpoints(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteDeleteMuteTiming(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteDeleteTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteDeleteTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteDeleteTemplate(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
return f.handleRouteGetAlertRule(ctx, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRuleGroup(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRuleGroup(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
|
||||
groupParam := web.Params(ctx.Req)[":Group"]
|
||||
return f.handleRouteGetAlertRuleGroup(ctx, folderUIDParam, groupParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRules(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetAlertRules(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetAlertRules(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetContactpoints(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteGetMuteTiming(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTimings(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetMuteTimings(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetMuteTimings(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetPolicyTree(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
return f.handleRouteGetTemplate(ctx, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplates(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteGetTemplates(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetTemplates(ctx)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.ProvisionedAlertRule{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -108,7 +108,7 @@ func (f *ProvisioningApiHandler) RoutePostAlertRule(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePostAlertRule(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.EmbeddedContactPoint{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -116,7 +116,7 @@ func (f *ProvisioningApiHandler) RoutePostContactpoints(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePostContactpoints(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.MuteTimeInterval{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -124,7 +124,7 @@ func (f *ProvisioningApiHandler) RoutePostMuteTiming(ctx *models.ReqContext) res
|
||||
}
|
||||
return f.handleRoutePostMuteTiming(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
// Parse Request Body
|
||||
@@ -134,7 +134,7 @@ func (f *ProvisioningApiHandler) RoutePutAlertRule(ctx *models.ReqContext) respo
|
||||
}
|
||||
return f.handleRoutePutAlertRule(ctx, conf, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
|
||||
groupParam := web.Params(ctx.Req)[":Group"]
|
||||
@@ -145,7 +145,7 @@ func (f *ProvisioningApiHandler) RoutePutAlertRuleGroup(ctx *models.ReqContext)
|
||||
}
|
||||
return f.handleRoutePutAlertRuleGroup(ctx, conf, folderUIDParam, groupParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
uIDParam := web.Params(ctx.Req)[":UID"]
|
||||
// Parse Request Body
|
||||
@@ -155,7 +155,7 @@ func (f *ProvisioningApiHandler) RoutePutContactpoint(ctx *models.ReqContext) re
|
||||
}
|
||||
return f.handleRoutePutContactpoint(ctx, conf, uIDParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
// Parse Request Body
|
||||
@@ -165,7 +165,7 @@ func (f *ProvisioningApiHandler) RoutePutMuteTiming(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePutMuteTiming(ctx, conf, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.Route{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -173,7 +173,7 @@ func (f *ProvisioningApiHandler) RoutePutPolicyTree(ctx *models.ReqContext) resp
|
||||
}
|
||||
return f.handleRoutePutPolicyTree(ctx, conf)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
nameParam := web.Params(ctx.Req)[":name"]
|
||||
// Parse Request Body
|
||||
@@ -183,7 +183,7 @@ func (f *ProvisioningApiHandler) RoutePutTemplate(ctx *models.ReqContext) respon
|
||||
}
|
||||
return f.handleRoutePutTemplate(ctx, conf, nameParam)
|
||||
}
|
||||
func (f *ProvisioningApiHandler) RouteResetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) RouteResetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteResetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,84 +12,84 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type RulerApi interface {
|
||||
RouteDeleteGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteNamespaceRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetNamespaceGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetNamespaceRulesConfig(*models.ReqContext) response.Response
|
||||
RouteGetRulegGroupConfig(*models.ReqContext) response.Response
|
||||
RouteGetRulesConfig(*models.ReqContext) response.Response
|
||||
RoutePostNameGrafanaRulesConfig(*models.ReqContext) response.Response
|
||||
RoutePostNameRulesConfig(*models.ReqContext) response.Response
|
||||
RouteDeleteGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteDeleteRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRuleGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNamespaceGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetNamespaceRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulegGroupConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteGetRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameGrafanaRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
RoutePostNameRulesConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteDeleteGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteDeleteNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteDeleteNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteDeleteRuleGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRuleGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRuleGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteGetGrafanaRuleGroupConfig(ctx, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.handleRouteGetGrafanaRulesConfig(ctx)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetNamespaceGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetNamespaceGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteGetNamespaceGrafanaRulesConfig(ctx, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
return f.handleRouteGetNamespaceRulesConfig(ctx, datasourceUIDParam, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
groupnameParam := web.Params(ctx.Req)[":Groupname"]
|
||||
return f.handleRouteGetRulegGroupConfig(ctx, datasourceUIDParam, namespaceParam, groupnameParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RouteGetRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
return f.handleRouteGetRulesConfig(ctx, datasourceUIDParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
// Parse Request Body
|
||||
@@ -99,7 +99,7 @@ func (f *RulerApiHandler) RoutePostNameGrafanaRulesConfig(ctx *models.ReqContext
|
||||
}
|
||||
return f.handleRoutePostNameGrafanaRulesConfig(ctx, conf, namespaceParam)
|
||||
}
|
||||
func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *RulerApiHandler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
namespaceParam := web.Params(ctx.Req)[":Namespace"]
|
||||
|
||||
@@ -12,20 +12,20 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type TestingApi interface {
|
||||
BacktestConfig(*models.ReqContext) response.Response
|
||||
RouteEvalQueries(*models.ReqContext) response.Response
|
||||
RouteTestRuleConfig(*models.ReqContext) response.Response
|
||||
RouteTestRuleGrafanaConfig(*models.ReqContext) response.Response
|
||||
BacktestConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteEvalQueries(*contextmodel.ReqContext) response.Response
|
||||
RouteTestRuleConfig(*contextmodel.ReqContext) response.Response
|
||||
RouteTestRuleGrafanaConfig(*contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) BacktestConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) BacktestConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.BacktestConfig{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -33,7 +33,7 @@ func (f *TestingApiHandler) BacktestConfig(ctx *models.ReqContext) response.Resp
|
||||
}
|
||||
return f.handleBacktestConfig(ctx, conf)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteEvalQueries(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteEvalQueries(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.EvalQueriesPayload{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
@@ -41,7 +41,7 @@ func (f *TestingApiHandler) RouteEvalQueries(ctx *models.ReqContext) response.Re
|
||||
}
|
||||
return f.handleRouteEvalQueries(ctx, conf)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteTestRuleConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteTestRuleConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Path Parameters
|
||||
datasourceUIDParam := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
// Parse Request Body
|
||||
@@ -51,7 +51,7 @@ func (f *TestingApiHandler) RouteTestRuleConfig(ctx *models.ReqContext) response
|
||||
}
|
||||
return f.handleRouteTestRuleConfig(ctx, conf, datasourceUIDParam)
|
||||
}
|
||||
func (f *TestingApiHandler) RouteTestRuleGrafanaConfig(ctx *models.ReqContext) response.Response {
|
||||
func (f *TestingApiHandler) RouteTestRuleGrafanaConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
// Parse Request Body
|
||||
conf := apimodels.TestRulePayload{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -61,7 +61,7 @@ func NewLotexAM(proxy *AlertingProxy, log log.Logger) *LotexAM {
|
||||
}
|
||||
|
||||
func (am *LotexAM) withAMReq(
|
||||
ctx *models.ReqContext,
|
||||
ctx *contextmodel.ReqContext,
|
||||
method string,
|
||||
endpoint string,
|
||||
pathParams []string,
|
||||
@@ -110,7 +110,7 @@ func (am *LotexAM) withAMReq(
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -122,7 +122,7 @@ func (am *LotexAM) RouteGetAMStatus(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteCreateSilence(ctx *models.ReqContext, silenceBody apimodels.PostableSilence) response.Response {
|
||||
func (am *LotexAM) RouteCreateSilence(ctx *contextmodel.ReqContext, silenceBody apimodels.PostableSilence) response.Response {
|
||||
blob, err := json.Marshal(silenceBody)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal silence")
|
||||
@@ -138,7 +138,7 @@ func (am *LotexAM) RouteCreateSilence(ctx *models.ReqContext, silenceBody apimod
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteDeleteAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodDelete,
|
||||
@@ -150,7 +150,7 @@ func (am *LotexAM) RouteDeleteAlertingConfig(ctx *models.ReqContext) response.Re
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteDeleteSilence(ctx *models.ReqContext, silenceID string) response.Response {
|
||||
func (am *LotexAM) RouteDeleteSilence(ctx *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodDelete,
|
||||
@@ -162,7 +162,7 @@ func (am *LotexAM) RouteDeleteSilence(ctx *models.ReqContext, silenceID string)
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAlertingConfig(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAlertingConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -174,7 +174,7 @@ func (am *LotexAM) RouteGetAlertingConfig(ctx *models.ReqContext) response.Respo
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMAlertGroups(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -186,7 +186,7 @@ func (am *LotexAM) RouteGetAMAlertGroups(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetAMAlerts(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -198,7 +198,7 @@ func (am *LotexAM) RouteGetAMAlerts(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetSilence(ctx *models.ReqContext, silenceID string) response.Response {
|
||||
func (am *LotexAM) RouteGetSilence(ctx *contextmodel.ReqContext, silenceID string) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -210,7 +210,7 @@ func (am *LotexAM) RouteGetSilence(ctx *models.ReqContext, silenceID string) res
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
func (am *LotexAM) RouteGetSilences(ctx *contextmodel.ReqContext) response.Response {
|
||||
return am.withAMReq(
|
||||
ctx,
|
||||
http.MethodGet,
|
||||
@@ -222,7 +222,7 @@ func (am *LotexAM) RouteGetSilences(ctx *models.ReqContext) response.Response {
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RoutePostAlertingConfig(ctx *models.ReqContext, config apimodels.PostableUserConfig) response.Response {
|
||||
func (am *LotexAM) RoutePostAlertingConfig(ctx *contextmodel.ReqContext, config apimodels.PostableUserConfig) response.Response {
|
||||
yml, err := yaml.Marshal(&config)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal alert manager configuration ")
|
||||
@@ -239,7 +239,7 @@ func (am *LotexAM) RoutePostAlertingConfig(ctx *models.ReqContext, config apimod
|
||||
)
|
||||
}
|
||||
|
||||
func (am *LotexAM) RoutePostAMAlerts(ctx *models.ReqContext, alerts apimodels.PostableAlerts) response.Response {
|
||||
func (am *LotexAM) RoutePostAMAlerts(ctx *contextmodel.ReqContext, alerts apimodels.PostableAlerts) response.Response {
|
||||
yml, err := yaml.Marshal(alerts)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "Failed marshal postable alerts")
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -38,7 +38,7 @@ func NewLotexProm(proxy *AlertingProxy, log log.Logger) *LotexProm {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *LotexProm) RouteGetAlertStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (p *LotexProm) RouteGetAlertStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
endpoints, err := p.getEndpoints(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -57,7 +57,7 @@ func (p *LotexProm) RouteGetAlertStatuses(ctx *models.ReqContext) response.Respo
|
||||
)
|
||||
}
|
||||
|
||||
func (p *LotexProm) RouteGetRuleStatuses(ctx *models.ReqContext) response.Response {
|
||||
func (p *LotexProm) RouteGetRuleStatuses(ctx *contextmodel.ReqContext) response.Response {
|
||||
endpoints, err := p.getEndpoints(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
@@ -76,7 +76,7 @@ func (p *LotexProm) RouteGetRuleStatuses(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (p *LotexProm) getEndpoints(ctx *models.ReqContext) (*promEndpoints, error) {
|
||||
func (p *LotexProm) getEndpoints(ctx *contextmodel.ReqContext) (*promEndpoints, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
if datasourceUID == "" {
|
||||
return nil, fmt.Errorf("datasource UID is invalid")
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,7 +55,7 @@ func NewLotexRuler(proxy *AlertingProxy, log log.Logger) *LotexRuler {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -73,7 +73,7 @@ func (r *LotexRuler) RouteDeleteNamespaceRulesConfig(ctx *models.ReqContext, nam
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext, namespace string, group string) response.Response {
|
||||
func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *contextmodel.ReqContext, namespace string, group string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -96,7 +96,7 @@ func (r *LotexRuler) RouteDeleteRuleGroupConfig(ctx *models.ReqContext, namespac
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext, namespace string) response.Response {
|
||||
func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *contextmodel.ReqContext, namespace string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -118,7 +118,7 @@ func (r *LotexRuler) RouteGetNamespaceRulesConfig(ctx *models.ReqContext, namesp
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *models.ReqContext, namespace string, group string) response.Response {
|
||||
func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *contextmodel.ReqContext, namespace string, group string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -141,7 +141,7 @@ func (r *LotexRuler) RouteGetRulegGroupConfig(ctx *models.ReqContext, namespace
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RouteGetRulesConfig(ctx *models.ReqContext) response.Response {
|
||||
func (r *LotexRuler) RouteGetRulesConfig(ctx *contextmodel.ReqContext) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -160,7 +160,7 @@ func (r *LotexRuler) RouteGetRulesConfig(ctx *models.ReqContext) response.Respon
|
||||
)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig, ns string) response.Response {
|
||||
func (r *LotexRuler) RoutePostNameRulesConfig(ctx *contextmodel.ReqContext, conf apimodels.PostableRuleGroupConfig, ns string) response.Response {
|
||||
legacyRulerPrefix, err := r.validateAndGetPrefix(ctx)
|
||||
if err != nil {
|
||||
return ErrResp(500, err, "")
|
||||
@@ -173,7 +173,7 @@ func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimo
|
||||
return r.withReq(ctx, http.MethodPost, u, bytes.NewBuffer(yml), jsonExtractor(nil), nil)
|
||||
}
|
||||
|
||||
func (r *LotexRuler) validateAndGetPrefix(ctx *models.ReqContext) (string, error) {
|
||||
func (r *LotexRuler) validateAndGetPrefix(ctx *contextmodel.ReqContext) (string, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
if datasourceUID == "" {
|
||||
return "", fmt.Errorf("datasource UID is invalid")
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -98,7 +98,7 @@ func TestLotexRuler_ValidateAndGetPrefix(t *testing.T) {
|
||||
// Setup request context.
|
||||
httpReq, err := http.NewRequest(http.MethodGet, "http://grafanacloud.com"+tt.urlParams, nil)
|
||||
require.NoError(t, err)
|
||||
ctx := &models.ReqContext{Context: &web.Context{Req: web.SetURLParams(httpReq, tt.namedParams)}}
|
||||
ctx := &contextmodel.ReqContext{Context: &web.Context{Req: web.SetURLParams(httpReq, tt.namedParams)}}
|
||||
|
||||
prefix, err := ruler.validateAndGetPrefix(ctx)
|
||||
require.Equal(t, tt.expected, prefix)
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -16,94 +16,94 @@ func NewProvisioningApi(svc *ProvisioningSrv) *ProvisioningApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutPolicyTree(ctx *models.ReqContext, route apimodels.Route) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutPolicyTree(ctx *contextmodel.ReqContext, route apimodels.Route) response.Response {
|
||||
return f.svc.RoutePutPolicyTree(ctx, route)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetContactpoints(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetContactpoints(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetContactPoints(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostContactpoints(ctx *models.ReqContext, cp apimodels.EmbeddedContactPoint) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostContactpoints(ctx *contextmodel.ReqContext, cp apimodels.EmbeddedContactPoint) response.Response {
|
||||
return f.svc.RoutePostContactPoint(ctx, cp)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutContactpoint(ctx *models.ReqContext, cp apimodels.EmbeddedContactPoint, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutContactpoint(ctx *contextmodel.ReqContext, cp apimodels.EmbeddedContactPoint, UID string) response.Response {
|
||||
return f.svc.RoutePutContactPoint(ctx, cp, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteContactpoints(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteContactpoints(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteDeleteContactPoint(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplates(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplates(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetTemplates(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplate(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetTemplate(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteGetTemplate(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *models.ReqContext, body apimodels.NotificationTemplateContent, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutTemplate(ctx *contextmodel.ReqContext, body apimodels.NotificationTemplateContent, name string) response.Response {
|
||||
return f.svc.RoutePutTemplate(ctx, body, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteTemplate(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteTemplate(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteDeleteTemplate(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTiming(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTiming(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteGetMuteTiming(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTimings(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetMuteTimings(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetMuteTimings(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostMuteTiming(ctx *models.ReqContext, mt apimodels.MuteTimeInterval) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostMuteTiming(ctx *contextmodel.ReqContext, mt apimodels.MuteTimeInterval) response.Response {
|
||||
return f.svc.RoutePostMuteTiming(ctx, mt)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutMuteTiming(ctx *models.ReqContext, mt apimodels.MuteTimeInterval, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutMuteTiming(ctx *contextmodel.ReqContext, mt apimodels.MuteTimeInterval, name string) response.Response {
|
||||
return f.svc.RoutePutMuteTiming(ctx, mt, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteMuteTiming(ctx *models.ReqContext, name string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteMuteTiming(ctx *contextmodel.ReqContext, name string) response.Response {
|
||||
return f.svc.RouteDeleteMuteTiming(ctx, name)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRules(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRules(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteGetAlertRules(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRule(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRule(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteRouteGetAlertRule(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePostAlertRule(ctx *models.ReqContext, ar apimodels.ProvisionedAlertRule) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePostAlertRule(ctx *contextmodel.ReqContext, ar apimodels.ProvisionedAlertRule) response.Response {
|
||||
return f.svc.RoutePostAlertRule(ctx, ar)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRule(ctx *models.ReqContext, ar apimodels.ProvisionedAlertRule, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRule(ctx *contextmodel.ReqContext, ar apimodels.ProvisionedAlertRule, UID string) response.Response {
|
||||
return f.svc.RoutePutAlertRule(ctx, ar, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteAlertRule(ctx *models.ReqContext, UID string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteDeleteAlertRule(ctx *contextmodel.ReqContext, UID string) response.Response {
|
||||
return f.svc.RouteDeleteAlertRule(ctx, UID)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteResetPolicyTree(ctx *models.ReqContext) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteResetPolicyTree(ctx *contextmodel.ReqContext) response.Response {
|
||||
return f.svc.RouteResetPolicyTree(ctx)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRuleGroup(ctx *models.ReqContext, folder, group string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRouteGetAlertRuleGroup(ctx *contextmodel.ReqContext, folder, group string) response.Response {
|
||||
return f.svc.RouteGetAlertRuleGroup(ctx, folder, group)
|
||||
}
|
||||
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRuleGroup(ctx *models.ReqContext, ag apimodels.AlertRuleGroup, folder, group string) response.Response {
|
||||
func (f *ProvisioningApiHandler) handleRoutePutAlertRuleGroup(ctx *contextmodel.ReqContext, ag apimodels.AlertRuleGroup, folder, group string) response.Response {
|
||||
return f.svc.RoutePutAlertRuleGroup(ctx, ag, folder, group)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
)
|
||||
|
||||
@@ -17,18 +17,18 @@ func NewTestingApi(svc *TestingApiSrv) *TestingApiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteTestRuleConfig(c *models.ReqContext, body apimodels.TestRulePayload, dsUID string) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteTestRuleConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload, dsUID string) response.Response {
|
||||
return f.svc.RouteTestRuleConfig(c, body, dsUID)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteTestRuleGrafanaConfig(c *models.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteTestRuleGrafanaConfig(c *contextmodel.ReqContext, body apimodels.TestRulePayload) response.Response {
|
||||
return f.svc.RouteTestGrafanaRuleConfig(c, body)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleRouteEvalQueries(c *models.ReqContext, body apimodels.EvalQueriesPayload) response.Response {
|
||||
func (f *TestingApiHandler) handleRouteEvalQueries(c *contextmodel.ReqContext, body apimodels.EvalQueriesPayload) response.Response {
|
||||
return f.svc.RouteEvalQueries(c, body)
|
||||
}
|
||||
|
||||
func (f *TestingApiHandler) handleBacktestConfig(ctx *models.ReqContext, conf apimodels.BacktestConfig) response.Response {
|
||||
func (f *TestingApiHandler) handleBacktestConfig(ctx *contextmodel.ReqContext, conf apimodels.BacktestConfig) response.Response {
|
||||
return f.svc.BacktestAlertRule(ctx, conf)
|
||||
}
|
||||
|
||||
@@ -11,14 +11,15 @@ import (
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
type {{classname}} interface { {{#operation}}
|
||||
{{nickname}}(*models.ReqContext) response.Response{{/operation}}
|
||||
{{nickname}}(*contextmodel.ReqContext) response.Response{{/operation}}
|
||||
}
|
||||
|
||||
{{#operations}}{{#operation}}
|
||||
func (f *{{classname}}Handler) {{nickname}}(ctx *models.ReqContext) response.Response { {{#hasPathParams}}
|
||||
func (f *{{classname}}Handler) {{nickname}}(ctx *contextmodel.ReqContext) response.Response { {{#hasPathParams}}
|
||||
// Parse Path Parameters{{/hasPathParams}}{{#pathParams}}
|
||||
{{paramName}}Param := web.Params(ctx.Req)[":{{baseName}}"]{{/pathParams}}
|
||||
{{#bodyParams}}
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -34,7 +34,7 @@ func toMacaronPath(path string) string {
|
||||
}))
|
||||
}
|
||||
|
||||
func getDatasourceByUID(ctx *models.ReqContext, cache datasources.CacheService, expectedType apimodels.Backend) (*datasources.DataSource, error) {
|
||||
func getDatasourceByUID(ctx *contextmodel.ReqContext, cache datasources.CacheService, expectedType apimodels.Backend) (*datasources.DataSource, error) {
|
||||
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
|
||||
ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache)
|
||||
if err != nil {
|
||||
@@ -69,12 +69,12 @@ func (w *safeMacaronWrapper) CloseNotify() <-chan bool {
|
||||
|
||||
// createProxyContext creates a new request context that is provided down to the data source proxy.
|
||||
// The request context
|
||||
// 1. overwrites the underlying response writer used by a *models.ReqContext because AlertingProxy needs to intercept
|
||||
// 1. overwrites the underlying response writer used by a *contextmodel.ReqContext because AlertingProxy needs to intercept
|
||||
// the response from the data source to analyze it and probably change
|
||||
// 2. elevates the current user permissions to Editor if both conditions are met: RBAC is enabled, user does not have Editor role.
|
||||
// This is needed to bypass the plugin authorization, which still relies on the legacy roles.
|
||||
// This elevation can be considered safe because all upstream calls are protected by the RBAC on web request router level.
|
||||
func (p *AlertingProxy) createProxyContext(ctx *models.ReqContext, request *http.Request, response *response.NormalResponse) *models.ReqContext {
|
||||
func (p *AlertingProxy) createProxyContext(ctx *contextmodel.ReqContext, request *http.Request, response *response.NormalResponse) *contextmodel.ReqContext {
|
||||
cpy := *ctx
|
||||
cpyMCtx := *cpy.Context
|
||||
cpyMCtx.Resp = web.NewResponseWriter(ctx.Req.Method, &safeMacaronWrapper{response})
|
||||
@@ -100,7 +100,7 @@ type AlertingProxy struct {
|
||||
|
||||
// withReq proxies a different request
|
||||
func (p *AlertingProxy) withReq(
|
||||
ctx *models.ReqContext,
|
||||
ctx *contextmodel.ReqContext,
|
||||
method string,
|
||||
u *url.URL,
|
||||
body io.Reader,
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
models2 "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -41,7 +41,7 @@ func TestToMacaronPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAlertingProxy_createProxyContext(t *testing.T) {
|
||||
ctx := &models.ReqContext{
|
||||
ctx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{
|
||||
Req: &http.Request{},
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/grafana/grafana/pkg/util/ticker"
|
||||
|
||||
@@ -305,12 +305,12 @@ func (m *OrgRegistries) RemoveOrgRegistry(org int64) {
|
||||
func Instrument(
|
||||
method,
|
||||
path string,
|
||||
action func(*models.ReqContext) response.Response,
|
||||
action func(*contextmodel.ReqContext) response.Response,
|
||||
metrics *API,
|
||||
) web.Handler {
|
||||
normalizedPath := MakeLabelValue(path)
|
||||
|
||||
return func(c *models.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
start := time.Now()
|
||||
res := action(c)
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||
@@ -89,7 +89,7 @@ func (api *Api) RegisterAPIEndpoints() {
|
||||
|
||||
// ListPublicDashboards Gets list of public dashboards by orgId
|
||||
// GET /api/dashboards/public-dashboards
|
||||
func (api *Api) ListPublicDashboards(c *models.ReqContext) response.Response {
|
||||
func (api *Api) ListPublicDashboards(c *contextmodel.ReqContext) response.Response {
|
||||
resp, err := api.PublicDashboardService.FindAll(c.Req.Context(), c.SignedInUser, c.OrgID)
|
||||
if err != nil {
|
||||
return response.Err(err)
|
||||
@@ -99,7 +99,7 @@ func (api *Api) ListPublicDashboards(c *models.ReqContext) response.Response {
|
||||
|
||||
// GetPublicDashboard Gets public dashboard for dashboard
|
||||
// GET /api/dashboards/uid/:dashboardUid/public-dashboards
|
||||
func (api *Api) GetPublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) GetPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
if !tokens.IsValidShortUID(dashboardUid) {
|
||||
@@ -120,7 +120,7 @@ func (api *Api) GetPublicDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
// CreatePublicDashboard Sets public dashboard for dashboard
|
||||
// POST /api/dashboards/uid/:dashboardUid/public-dashboards
|
||||
func (api *Api) CreatePublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
if !tokens.IsValidShortUID(dashboardUid) {
|
||||
@@ -152,7 +152,7 @@ func (api *Api) CreatePublicDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
// UpdatePublicDashboard Sets public dashboard for dashboard
|
||||
// PUT /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
||||
func (api *Api) UpdatePublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
if !tokens.IsValidShortUID(dashboardUid) {
|
||||
@@ -190,7 +190,7 @@ func (api *Api) UpdatePublicDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
// Delete a public dashboard
|
||||
// DELETE /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
||||
func (api *Api) DeletePublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) DeletePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if !tokens.IsValidShortUID(uid) {
|
||||
return response.Err(ErrInvalidUid.Errorf("UpdatePublicDashboard: invalid Uid %s", uid))
|
||||
|
||||
@@ -15,12 +15,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
datasourceService "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||
@@ -82,7 +82,7 @@ type testContext struct {
|
||||
func contextProvider(tc *testContext) web.Handler {
|
||||
return func(c *web.Context) {
|
||||
signedIn := tc.user != nil
|
||||
reqCtx := &models.ReqContext{
|
||||
reqCtx := &contextmodel.ReqContext{
|
||||
Context: c,
|
||||
SignedInUser: tc.user,
|
||||
IsSignedIn: signedIn,
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/internal/tokens"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
// SetPublicDashboardOrgIdOnContext Adds orgId to context based on org of public dashboard
|
||||
func SetPublicDashboardOrgIdOnContext(publicDashboardService publicdashboards.Service) func(c *models.ReqContext) {
|
||||
return func(c *models.ReqContext) {
|
||||
func SetPublicDashboardOrgIdOnContext(publicDashboardService publicdashboards.Service) func(c *contextmodel.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
accessToken, ok := web.Params(c.Req)[":accessToken"]
|
||||
if !ok || !tokens.IsValidAccessToken(accessToken) {
|
||||
return
|
||||
@@ -29,15 +29,15 @@ func SetPublicDashboardOrgIdOnContext(publicDashboardService publicdashboards.Se
|
||||
}
|
||||
|
||||
// SetPublicDashboardFlag Adds public dashboard flag on context
|
||||
func SetPublicDashboardFlag(c *models.ReqContext) {
|
||||
func SetPublicDashboardFlag(c *contextmodel.ReqContext) {
|
||||
c.IsPublicDashboardView = true
|
||||
}
|
||||
|
||||
// RequiresExistingAccessToken Middleware to enforce that a public dashboards exists before continuing to handler. This
|
||||
// method will query the database to ensure that it exists.
|
||||
// Use when we want to enforce a public dashboard is valid on an endpoint we do not maintain
|
||||
func RequiresExistingAccessToken(publicDashboardService publicdashboards.Service) func(c *models.ReqContext) {
|
||||
return func(c *models.ReqContext) {
|
||||
func RequiresExistingAccessToken(publicDashboardService publicdashboards.Service) func(c *contextmodel.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
accessToken, ok := web.Params(c.Req)[":accessToken"]
|
||||
|
||||
if !ok {
|
||||
@@ -62,8 +62,8 @@ func RequiresExistingAccessToken(publicDashboardService publicdashboards.Service
|
||||
}
|
||||
}
|
||||
|
||||
func CountPublicDashboardRequest() func(c *models.ReqContext) {
|
||||
return func(c *models.ReqContext) {
|
||||
func CountPublicDashboardRequest() func(c *contextmodel.ReqContext) {
|
||||
return func(c *contextmodel.ReqContext) {
|
||||
metrics.MPublicDashboardRequestCount.Inc()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/internal/tokens"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -146,21 +146,21 @@ func TestSetPublicDashboardOrgIdOnContext(t *testing.T) {
|
||||
|
||||
func TestSetPublicDashboardFlag(t *testing.T) {
|
||||
t.Run("Adds context.IsPublicDashboardView=true to request", func(t *testing.T) {
|
||||
ctx := &models.ReqContext{}
|
||||
ctx := &contextmodel.ReqContext{}
|
||||
SetPublicDashboardFlag(ctx)
|
||||
assert.True(t, ctx.IsPublicDashboardView)
|
||||
})
|
||||
}
|
||||
|
||||
// This is a helper to test middleware. It handles creating a
|
||||
// proper models.ReqContext, setting web parameters, executing middleware, and
|
||||
// proper contextmodel.ReqContext, setting web parameters, executing middleware, and
|
||||
// returning a response. Response will default to result of
|
||||
// httptest.NewRecorder() return value and will only change if modified by the
|
||||
// middlware as this will no accept a handler method
|
||||
func runMw(t *testing.T, ctx *models.ReqContext, httpmethod string, path string, webparams map[string]string, mw func(c *models.ReqContext)) (*models.ReqContext, *httptest.ResponseRecorder) {
|
||||
func runMw(t *testing.T, ctx *contextmodel.ReqContext, httpmethod string, path string, webparams map[string]string, mw func(c *contextmodel.ReqContext)) (*contextmodel.ReqContext, *httptest.ResponseRecorder) {
|
||||
// create valid request context and set 0 values if they don't exist
|
||||
if ctx == nil {
|
||||
ctx = &models.ReqContext{}
|
||||
ctx = &contextmodel.ReqContext{}
|
||||
}
|
||||
if ctx.Context == nil {
|
||||
ctx.Context = &web.Context{}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/internal/tokens"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// ViewPublicDashboard Gets public dashboard
|
||||
// GET /api/public/dashboards/:accessToken
|
||||
func (api *Api) ViewPublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) ViewPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !tokens.IsValidAccessToken(accessToken) {
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("ViewPublicDashboard: invalid access token"))
|
||||
@@ -53,7 +53,7 @@ func (api *Api) ViewPublicDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
// QueryPublicDashboard returns all results for a given panel on a public dashboard
|
||||
// POST /api/public/dashboard/:accessToken/panels/:panelId/query
|
||||
func (api *Api) QueryPublicDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *Api) QueryPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !tokens.IsValidAccessToken(accessToken) {
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("QueryPublicDashboard: invalid access token"))
|
||||
@@ -79,7 +79,7 @@ func (api *Api) QueryPublicDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
// GetAnnotations returns annotations for a public dashboard
|
||||
// GET /api/public/dashboards/:accessToken/annotations
|
||||
func (api *Api) GetAnnotations(c *models.ReqContext) response.Response {
|
||||
func (api *Api) GetAnnotations(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !tokens.IsValidAccessToken(accessToken) {
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("GetAnnotations: invalid access token"))
|
||||
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/roletype"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
dsSvc "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||
@@ -211,7 +211,7 @@ func TestParseMetricRequest(t *testing.T) {
|
||||
httpreq, err := http.NewRequest(http.MethodPost, "http://localhost/", bytes.NewReader([]byte{}))
|
||||
require.NoError(t, err)
|
||||
|
||||
reqCtx := &models.ReqContext{
|
||||
reqCtx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{},
|
||||
}
|
||||
ctx := ctxkey.Set(context.Background(), reqCtx)
|
||||
@@ -325,7 +325,7 @@ func TestQueryDataMultipleSources(t *testing.T) {
|
||||
httpreq, err := http.NewRequest(http.MethodPost, "http://localhost/ds/query?expression=true", bytes.NewReader([]byte{}))
|
||||
require.NoError(t, err)
|
||||
|
||||
reqCtx := &models.ReqContext{
|
||||
reqCtx := &contextmodel.ReqContext{
|
||||
Context: &web.Context{},
|
||||
}
|
||||
ctx := ctxkey.Set(context.Background(), reqCtx)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -36,7 +36,7 @@ func (s *QueryHistoryService) registerAPIEndpoints() {
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) createHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) createHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := CreateQueryInQueryHistoryCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -62,7 +62,7 @@ func (s *QueryHistoryService) createHandler(c *models.ReqContext) response.Respo
|
||||
// 200: getQueryHistorySearchResponse
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) searchHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) searchHandler(c *contextmodel.ReqContext) response.Response {
|
||||
timeRange := legacydata.NewDataTimeRange(c.Query("from"), c.Query("to"))
|
||||
|
||||
query := SearchInQueryHistoryQuery{
|
||||
@@ -94,7 +94,7 @@ func (s *QueryHistoryService) searchHandler(c *models.ReqContext) response.Respo
|
||||
// 200: getQueryHistoryDeleteQueryResponse
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) deleteHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) deleteHandler(c *contextmodel.ReqContext) response.Response {
|
||||
queryUID := web.Params(c.Req)[":uid"]
|
||||
if len(queryUID) > 0 && !util.IsValidShortUID(queryUID) {
|
||||
return response.Error(http.StatusNotFound, "Query in query history not found", nil)
|
||||
@@ -122,7 +122,7 @@ func (s *QueryHistoryService) deleteHandler(c *models.ReqContext) response.Respo
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) patchCommentHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) patchCommentHandler(c *contextmodel.ReqContext) response.Response {
|
||||
queryUID := web.Params(c.Req)[":uid"]
|
||||
if len(queryUID) > 0 && !util.IsValidShortUID(queryUID) {
|
||||
return response.Error(http.StatusNotFound, "Query in query history not found", nil)
|
||||
@@ -151,7 +151,7 @@ func (s *QueryHistoryService) patchCommentHandler(c *models.ReqContext) response
|
||||
// 200: getQueryHistoryResponse
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) starHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) starHandler(c *contextmodel.ReqContext) response.Response {
|
||||
queryUID := web.Params(c.Req)[":uid"]
|
||||
if len(queryUID) > 0 && !util.IsValidShortUID(queryUID) {
|
||||
return response.Error(http.StatusNotFound, "Query in query history not found", nil)
|
||||
@@ -175,7 +175,7 @@ func (s *QueryHistoryService) starHandler(c *models.ReqContext) response.Respons
|
||||
// 200: getQueryHistoryResponse
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) unstarHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) unstarHandler(c *contextmodel.ReqContext) response.Response {
|
||||
queryUID := web.Params(c.Req)[":uid"]
|
||||
if len(queryUID) > 0 && !util.IsValidShortUID(queryUID) {
|
||||
return response.Error(http.StatusNotFound, "Query in query history not found", nil)
|
||||
@@ -200,7 +200,7 @@ func (s *QueryHistoryService) unstarHandler(c *models.ReqContext) response.Respo
|
||||
// 400: badRequestError
|
||||
// 401: unauthorisedError
|
||||
// 500: internalServerError
|
||||
func (s *QueryHistoryService) migrateHandler(c *models.ReqContext) response.Response {
|
||||
func (s *QueryHistoryService) migrateHandler(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := MigrateQueriesToQueryHistoryCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
@@ -35,7 +35,7 @@ var (
|
||||
type scenarioContext struct {
|
||||
ctx *web.Context
|
||||
service *QueryHistoryService
|
||||
reqContext *models.ReqContext
|
||||
reqContext *contextmodel.ReqContext
|
||||
sqlStore db.DB
|
||||
initialResult QueryHistoryResponse
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
||||
ctx: &ctx,
|
||||
service: &service,
|
||||
sqlStore: sqlStore,
|
||||
reqContext: &models.ReqContext{
|
||||
reqContext: &contextmodel.ReqContext{
|
||||
Context: &ctx,
|
||||
SignedInUser: &usr,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/querylibrary"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *queriesServiceHTTPHandler) IsDisabled() bool {
|
||||
return s.service.IsDisabled()
|
||||
}
|
||||
|
||||
func (s *queriesServiceHTTPHandler) delete(c *models.ReqContext) response.Response {
|
||||
func (s *queriesServiceHTTPHandler) delete(c *contextmodel.ReqContext) response.Response {
|
||||
uid := c.Query("uid")
|
||||
err := s.service.Delete(c.Req.Context(), c.SignedInUser, uid)
|
||||
if err != nil {
|
||||
@@ -40,7 +40,7 @@ func (s *queriesServiceHTTPHandler) RegisterHTTPRoutes(routes routing.RouteRegis
|
||||
routes.Delete("/", reqSignedIn, routing.Wrap(s.delete))
|
||||
}
|
||||
|
||||
func (s *queriesServiceHTTPHandler) getBatch(c *models.ReqContext) response.Response {
|
||||
func (s *queriesServiceHTTPHandler) getBatch(c *contextmodel.ReqContext) response.Response {
|
||||
uids := c.QueryStrings("uid")
|
||||
|
||||
queries, err := s.service.GetBatch(c.Req.Context(), c.SignedInUser, uids)
|
||||
@@ -51,7 +51,7 @@ func (s *queriesServiceHTTPHandler) getBatch(c *models.ReqContext) response.Resp
|
||||
return response.JSON(200, queries)
|
||||
}
|
||||
|
||||
func (s *queriesServiceHTTPHandler) update(c *models.ReqContext) response.Response {
|
||||
func (s *queriesServiceHTTPHandler) update(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(500, "error reading bytes", err)
|
||||
|
||||
@@ -3,7 +3,7 @@ package quota
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
@@ -16,7 +16,7 @@ type Service interface {
|
||||
// If the cmd.UseID is set, then the user quota are updated.
|
||||
Update(ctx context.Context, cmd *UpdateQuotaCmd) error
|
||||
// QuotaReached is called by the quota middleware for applying quota enforcement to API handlers
|
||||
QuotaReached(c *models.ReqContext, targetSrv TargetSrv) (bool, error)
|
||||
QuotaReached(c *contextmodel.ReqContext, targetSrv TargetSrv) (bool, error)
|
||||
// CheckQuotaReached checks if the quota limitations have been reached for a specific service
|
||||
CheckQuotaReached(ctx context.Context, targetSrv TargetSrv, scopeParams *ScopeParameters) (bool, error)
|
||||
// DeleteQuotaForUser deletes custom quota limitations for the user
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type serviceDisabled struct {
|
||||
}
|
||||
|
||||
func (s *serviceDisabled) QuotaReached(c *models.ReqContext, targetSrv quota.TargetSrv) (bool, error) {
|
||||
func (s *serviceDisabled) QuotaReached(c *contextmodel.ReqContext, targetSrv quota.TargetSrv) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (s *service) IsDisabled() bool {
|
||||
}
|
||||
|
||||
// QuotaReached checks that quota is reached for a target. Runs CheckQuotaReached and take context and scope parameters from the request context
|
||||
func (s *service) QuotaReached(c *models.ReqContext, targetSrv quota.TargetSrv) (bool, error) {
|
||||
func (s *service) QuotaReached(c *contextmodel.ReqContext, targetSrv quota.TargetSrv) (bool, error) {
|
||||
// No request context means this is a background service, like LDAP Background Sync
|
||||
if c == nil {
|
||||
return false, nil
|
||||
|
||||
@@ -3,7 +3,7 @@ package quotatest
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func (f *FakeQuotaService) Update(ctx context.Context, cmd *quota.UpdateQuotaCmd
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FakeQuotaService) QuotaReached(c *models.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
func (f *FakeQuotaService) QuotaReached(c *contextmodel.ReqContext, target quota.TargetSrv) (bool, error) {
|
||||
return f.reached, f.err
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (s *searchHTTPService) RegisterHTTPRoutes(storageRoute routing.RouteRegiste
|
||||
storageRoute.Post("/", middleware.ReqSignedIn, routing.Wrap(s.doQuery))
|
||||
}
|
||||
|
||||
func (s *searchHTTPService) doQuery(c *models.ReqContext) response.Response {
|
||||
func (s *searchHTTPService) doQuery(c *contextmodel.ReqContext) response.Response {
|
||||
searchReadinessCheckResp := s.search.IsReady(c.Req.Context(), c.OrgID)
|
||||
if !searchReadinessCheckResp.IsReady {
|
||||
dashboardSearchNotServedRequestsCounter.With(prometheus.Labels{
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
SearchUsers(c *models.ReqContext) response.Response
|
||||
SearchUsersWithPaging(c *models.ReqContext) response.Response
|
||||
SearchUsers(c *contextmodel.ReqContext) response.Response
|
||||
SearchUsersWithPaging(c *contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
type OSSService struct {
|
||||
@@ -39,7 +39,7 @@ func ProvideUsersService(searchUserFilter user.SearchUserFilter, userService use
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (s *OSSService) SearchUsers(c *models.ReqContext) response.Response {
|
||||
func (s *OSSService) SearchUsers(c *contextmodel.ReqContext) response.Response {
|
||||
result, err := s.SearchUser(c)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to fetch users", err)
|
||||
@@ -58,7 +58,7 @@ func (s *OSSService) SearchUsers(c *models.ReqContext) response.Response {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (s *OSSService) SearchUsersWithPaging(c *models.ReqContext) response.Response {
|
||||
func (s *OSSService) SearchUsersWithPaging(c *contextmodel.ReqContext) response.Response {
|
||||
result, err := s.SearchUser(c)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to fetch users", err)
|
||||
@@ -67,7 +67,7 @@ func (s *OSSService) SearchUsersWithPaging(c *models.ReqContext) response.Respon
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (s *OSSService) SearchUser(c *models.ReqContext) (*user.SearchUserQueryResult, error) {
|
||||
func (s *OSSService) SearchUser(c *contextmodel.ReqContext) (*user.SearchUserQueryResult, error) {
|
||||
perPage := c.QueryInt("perpage")
|
||||
if perPage <= 0 {
|
||||
perPage = 1000
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
@@ -117,7 +117,7 @@ func (api *ServiceAccountsAPI) RegisterAPIEndpoints() {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) CreateServiceAccount(c *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) CreateServiceAccount(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := serviceaccounts.CreateServiceAccountForm{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Bad request data", err)
|
||||
@@ -171,7 +171,7 @@ func (api *ServiceAccountsAPI) CreateServiceAccount(c *models.ReqContext) respon
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) RetrieveServiceAccount(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) RetrieveServiceAccount(ctx *contextmodel.ReqContext) response.Response {
|
||||
scopeID, err := strconv.ParseInt(web.Params(ctx.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service Account ID is invalid", err)
|
||||
@@ -218,7 +218,7 @@ func (api *ServiceAccountsAPI) RetrieveServiceAccount(ctx *models.ReqContext) re
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) UpdateServiceAccount(c *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) UpdateServiceAccount(c *contextmodel.ReqContext) response.Response {
|
||||
scopeID, err := strconv.ParseInt(web.Params(c.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service Account ID is invalid", err)
|
||||
@@ -286,7 +286,7 @@ func (api *ServiceAccountsAPI) validateRole(r *org.RoleType, orgRole *org.RoleTy
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) DeleteServiceAccount(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) DeleteServiceAccount(ctx *contextmodel.ReqContext) response.Response {
|
||||
scopeID, err := strconv.ParseInt(web.Params(ctx.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service account ID is invalid", err)
|
||||
@@ -310,7 +310,7 @@ func (api *ServiceAccountsAPI) DeleteServiceAccount(ctx *models.ReqContext) resp
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) SearchOrgServiceAccountsWithPaging(c *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) SearchOrgServiceAccountsWithPaging(c *contextmodel.ReqContext) response.Response {
|
||||
ctx := c.Req.Context()
|
||||
perPage := c.QueryInt("perpage")
|
||||
if perPage <= 0 {
|
||||
@@ -365,7 +365,7 @@ func (api *ServiceAccountsAPI) SearchOrgServiceAccountsWithPaging(c *models.ReqC
|
||||
}
|
||||
|
||||
// GET /api/serviceaccounts/migrationstatus
|
||||
func (api *ServiceAccountsAPI) GetAPIKeysMigrationStatus(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) GetAPIKeysMigrationStatus(ctx *contextmodel.ReqContext) response.Response {
|
||||
upgradeStatus, err := api.service.GetAPIKeysMigrationStatus(ctx.Req.Context(), ctx.OrgID)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Internal server error", err)
|
||||
@@ -374,7 +374,7 @@ func (api *ServiceAccountsAPI) GetAPIKeysMigrationStatus(ctx *models.ReqContext)
|
||||
}
|
||||
|
||||
// POST /api/serviceaccounts/hideapikeys
|
||||
func (api *ServiceAccountsAPI) HideApiKeysTab(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) HideApiKeysTab(ctx *contextmodel.ReqContext) response.Response {
|
||||
if err := api.service.HideApiKeysTab(ctx.Req.Context(), ctx.OrgID); err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Internal server error", err)
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func (api *ServiceAccountsAPI) HideApiKeysTab(ctx *models.ReqContext) response.R
|
||||
}
|
||||
|
||||
// POST /api/serviceaccounts/migrate
|
||||
func (api *ServiceAccountsAPI) MigrateApiKeysToServiceAccounts(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) MigrateApiKeysToServiceAccounts(ctx *contextmodel.ReqContext) response.Response {
|
||||
if err := api.service.MigrateApiKeysToServiceAccounts(ctx.Req.Context(), ctx.OrgID); err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Internal server error", err)
|
||||
}
|
||||
@@ -391,7 +391,7 @@ func (api *ServiceAccountsAPI) MigrateApiKeysToServiceAccounts(ctx *models.ReqCo
|
||||
}
|
||||
|
||||
// POST /api/serviceaccounts/migrate/:keyId
|
||||
func (api *ServiceAccountsAPI) ConvertToServiceAccount(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) ConvertToServiceAccount(ctx *contextmodel.ReqContext) response.Response {
|
||||
keyId, err := strconv.ParseInt(web.Params(ctx.Req)[":keyId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Key ID is invalid", err)
|
||||
@@ -405,7 +405,7 @@ func (api *ServiceAccountsAPI) ConvertToServiceAccount(ctx *models.ReqContext) r
|
||||
}
|
||||
|
||||
// POST /api/serviceaccounts/revert/:keyId
|
||||
func (api *ServiceAccountsAPI) RevertApiKey(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) RevertApiKey(ctx *contextmodel.ReqContext) response.Response {
|
||||
keyId, err := strconv.ParseInt(web.Params(ctx.Req)[":keyId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "key ID is invalid", err)
|
||||
@@ -421,7 +421,7 @@ func (api *ServiceAccountsAPI) RevertApiKey(ctx *models.ReqContext) response.Res
|
||||
return response.Success("reverted service account to API key")
|
||||
}
|
||||
|
||||
func (api *ServiceAccountsAPI) getAccessControlMetadata(c *models.ReqContext, saIDs map[string]bool) map[string]accesscontrol.Metadata {
|
||||
func (api *ServiceAccountsAPI) getAccessControlMetadata(c *contextmodel.ReqContext, saIDs map[string]bool) map[string]accesscontrol.Metadata {
|
||||
if api.accesscontrol.IsDisabled() || !c.QueryBool("accesscontrol") {
|
||||
return map[string]accesscontrol.Metadata{}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
apikeygenprefix "github.com/grafana/grafana/pkg/components/apikeygenprefixed"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -66,7 +66,7 @@ const sevenDaysAhead = 7 * 24 * time.Hour
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) ListTokens(ctx *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) ListTokens(ctx *contextmodel.ReqContext) response.Response {
|
||||
saID, err := strconv.ParseInt(web.Params(ctx.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service Account ID is invalid", err)
|
||||
@@ -127,7 +127,7 @@ func (api *ServiceAccountsAPI) ListTokens(ctx *models.ReqContext) response.Respo
|
||||
// 404: notFoundError
|
||||
// 409: conflictError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) CreateToken(c *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) CreateToken(c *contextmodel.ReqContext) response.Response {
|
||||
saID, err := strconv.ParseInt(web.Params(c.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service Account ID is invalid", err)
|
||||
@@ -210,7 +210,7 @@ func (api *ServiceAccountsAPI) CreateToken(c *models.ReqContext) response.Respon
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (api *ServiceAccountsAPI) DeleteToken(c *models.ReqContext) response.Response {
|
||||
func (api *ServiceAccountsAPI) DeleteToken(c *contextmodel.ReqContext) response.Response {
|
||||
saID, err := strconv.ParseInt(web.Params(c.Req)[":serviceAccountId"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Service Account ID is invalid", err)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -45,7 +45,7 @@ func (api *API) getDashboardHelper(ctx context.Context, orgID int64, id int64, u
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (api *API) GetStars(c *models.ReqContext) response.Response {
|
||||
func (api *API) GetStars(c *contextmodel.ReqContext) response.Response {
|
||||
query := star.GetUserStarsQuery{
|
||||
UserID: c.SignedInUser.UserID,
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func (api *API) GetStars(c *models.ReqContext) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *API) StarDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *API) StarDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard ID", nil)
|
||||
@@ -115,7 +115,7 @@ func (api *API) StarDashboard(c *models.ReqContext) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *API) StarDashboardByUID(c *models.ReqContext) response.Response {
|
||||
func (api *API) StarDashboardByUID(c *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if uid == "" {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil)
|
||||
@@ -151,7 +151,7 @@ func (api *API) StarDashboardByUID(c *models.ReqContext) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *API) UnstarDashboard(c *models.ReqContext) response.Response {
|
||||
func (api *API) UnstarDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard ID", nil)
|
||||
@@ -181,7 +181,7 @@ func (api *API) UnstarDashboard(c *models.ReqContext) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (api *API) UnstarDashboardByUID(c *models.ReqContext) response.Response {
|
||||
func (api *API) UnstarDashboardByUID(c *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if uid == "" {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
"github.com/grafana/grafana/pkg/services/store/kind"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
type HTTPEntityStore interface {
|
||||
@@ -60,7 +60,7 @@ func (s *httpEntityStore) RegisterHTTPRoutes(route routing.RouteRegister) {
|
||||
// This function will extract UID+Kind from the requested path "*" in our router
|
||||
// This is far from ideal! but is at least consistent for these endpoints.
|
||||
// This will quickly be revisited as we explore how to encode UID+Kind in a "GRN" format
|
||||
func (s *httpEntityStore) getGRNFromRequest(c *models.ReqContext) (*entity.GRN, map[string]string, error) {
|
||||
func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*entity.GRN, map[string]string, error) {
|
||||
params := web.Params(c.Req)
|
||||
// Read parameters that are encoded in the URL
|
||||
vals := c.Req.URL.Query()
|
||||
@@ -76,7 +76,7 @@ func (s *httpEntityStore) getGRNFromRequest(c *models.ReqContext) (*entity.GRN,
|
||||
}, params, nil
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doGetEntity(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doGetEntity(c *contextmodel.ReqContext) response.Response {
|
||||
grn, params, err := s.getGRNFromRequest(c)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), err)
|
||||
@@ -111,7 +111,7 @@ func (s *httpEntityStore) doGetEntity(c *models.ReqContext) response.Response {
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doGetRawEntity(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doGetRawEntity(c *contextmodel.ReqContext) response.Response {
|
||||
grn, params, err := s.getGRNFromRequest(c)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), err)
|
||||
@@ -161,7 +161,7 @@ func (s *httpEntityStore) doGetRawEntity(c *models.ReqContext) response.Response
|
||||
|
||||
const MAX_UPLOAD_SIZE = 5 * 1024 * 1024 // 5MB
|
||||
|
||||
func (s *httpEntityStore) doWriteEntity(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doWriteEntity(c *contextmodel.ReqContext) response.Response {
|
||||
grn, params, err := s.getGRNFromRequest(c)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), err)
|
||||
@@ -187,7 +187,7 @@ func (s *httpEntityStore) doWriteEntity(c *models.ReqContext) response.Response
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doDeleteEntity(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doDeleteEntity(c *contextmodel.ReqContext) response.Response {
|
||||
grn, params, err := s.getGRNFromRequest(c)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), err)
|
||||
@@ -202,7 +202,7 @@ func (s *httpEntityStore) doDeleteEntity(c *models.ReqContext) response.Response
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doGetHistory(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doGetHistory(c *contextmodel.ReqContext) response.Response {
|
||||
grn, params, err := s.getGRNFromRequest(c)
|
||||
if err != nil {
|
||||
return response.Error(400, err.Error(), err)
|
||||
@@ -219,7 +219,7 @@ func (s *httpEntityStore) doGetHistory(c *models.ReqContext) response.Response {
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doUpload(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doUpload(c *contextmodel.ReqContext) response.Response {
|
||||
c.Req.Body = http.MaxBytesReader(c.Resp, c.Req.Body, MAX_UPLOAD_SIZE)
|
||||
if err := c.Req.ParseMultipartForm(MAX_UPLOAD_SIZE); err != nil {
|
||||
msg := fmt.Sprintf("Please limit file uploaded under %s", util.ByteCountSI(MAX_UPLOAD_SIZE))
|
||||
@@ -302,11 +302,11 @@ func (s *httpEntityStore) doUpload(c *models.ReqContext) response.Response {
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doListFolder(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doListFolder(c *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(501, "Not implemented yet")
|
||||
}
|
||||
|
||||
func (s *httpEntityStore) doSearch(c *models.ReqContext) response.Response {
|
||||
func (s *httpEntityStore) doSearch(c *contextmodel.ReqContext) response.Response {
|
||||
vals := c.Req.URL.Query()
|
||||
|
||||
req := &entity.EntitySearchRequest{
|
||||
|
||||
+10
-10
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -57,7 +57,7 @@ func (s *standardStorageService) RegisterHTTPRoutes(storageRoute routing.RouteRe
|
||||
storageRoute.Get("/config", reqGrafanaAdmin, routing.Wrap(s.getConfig))
|
||||
}
|
||||
|
||||
func (s *standardStorageService) doWrite(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) doWrite(c *contextmodel.ReqContext) response.Response {
|
||||
scope, path := getPathAndScope(c)
|
||||
cmd := &WriteValueRequest{}
|
||||
if err := web.Bind(c.Req, cmd); err != nil {
|
||||
@@ -71,7 +71,7 @@ func (s *standardStorageService) doWrite(c *models.ReqContext) response.Response
|
||||
return response.JSON(200, rsp)
|
||||
}
|
||||
|
||||
func (s *standardStorageService) doUpload(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) doUpload(c *contextmodel.ReqContext) response.Response {
|
||||
type rspInfo struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
@@ -158,7 +158,7 @@ func getMultipartFormValue(req *http.Request, key string) string {
|
||||
return v[0]
|
||||
}
|
||||
|
||||
func (s *standardStorageService) read(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) read(c *contextmodel.ReqContext) response.Response {
|
||||
// full path is api/storage/read/upload/example.jpg, but we only want the part after read
|
||||
scope, path := getPathAndScope(c)
|
||||
file, err := s.Read(c.Req.Context(), c.SignedInUser, scope+"/"+path)
|
||||
@@ -177,7 +177,7 @@ func (s *standardStorageService) read(c *models.ReqContext) response.Response {
|
||||
return response.Respond(200, file.Contents)
|
||||
}
|
||||
|
||||
func (s *standardStorageService) getOptions(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) getOptions(c *contextmodel.ReqContext) response.Response {
|
||||
scope, path := getPathAndScope(c)
|
||||
opts, err := s.getWorkflowOptions(c.Req.Context(), c.SignedInUser, scope+"/"+path)
|
||||
if err != nil {
|
||||
@@ -186,7 +186,7 @@ func (s *standardStorageService) getOptions(c *models.ReqContext) response.Respo
|
||||
return response.JSON(200, opts)
|
||||
}
|
||||
|
||||
func (s *standardStorageService) doDelete(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) doDelete(c *contextmodel.ReqContext) response.Response {
|
||||
// full path is api/storage/delete/upload/example.jpg, but we only want the part after upload
|
||||
scope, path := getPathAndScope(c)
|
||||
|
||||
@@ -201,7 +201,7 @@ func (s *standardStorageService) doDelete(c *models.ReqContext) response.Respons
|
||||
})
|
||||
}
|
||||
|
||||
func (s *standardStorageService) doDeleteFolder(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) doDeleteFolder(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(500, "error reading bytes", err)
|
||||
@@ -230,7 +230,7 @@ func (s *standardStorageService) doDeleteFolder(c *models.ReqContext) response.R
|
||||
})
|
||||
}
|
||||
|
||||
func (s *standardStorageService) doCreateFolder(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) doCreateFolder(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(500, "error reading bytes", err)
|
||||
@@ -257,7 +257,7 @@ func (s *standardStorageService) doCreateFolder(c *models.ReqContext) response.R
|
||||
})
|
||||
}
|
||||
|
||||
func (s *standardStorageService) list(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) list(c *contextmodel.ReqContext) response.Response {
|
||||
params := web.Params(c.Req)
|
||||
path := params["*"]
|
||||
frame, err := s.List(c.Req.Context(), c.SignedInUser, path)
|
||||
@@ -270,7 +270,7 @@ func (s *standardStorageService) list(c *models.ReqContext) response.Response {
|
||||
return response.JSONStreaming(http.StatusOK, frame)
|
||||
}
|
||||
|
||||
func (s *standardStorageService) getConfig(c *models.ReqContext) response.Response {
|
||||
func (s *standardStorageService) getConfig(c *contextmodel.ReqContext) response.Response {
|
||||
roots := make([]RootStorageMeta, 0)
|
||||
orgId := c.OrgID
|
||||
t := s.tree
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -84,7 +84,7 @@ func defaultServerUrlFor(config *rest.Config) (*url.URL, string, error) {
|
||||
return rest.DefaultServerURL(host, config.APIPath, schema.GroupVersion{}, defaultTLS)
|
||||
}
|
||||
|
||||
func (s *clientWrapper) doProxy(c *models.ReqContext) {
|
||||
func (s *clientWrapper) doProxy(c *contextmodel.ReqContext) {
|
||||
if s.baseURL == nil {
|
||||
c.Resp.WriteHeader(500)
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
type httpHelper struct {
|
||||
@@ -25,7 +25,7 @@ func newHTTPHelper(access *k8sAccess, router routing.RouteRegister) *httpHelper
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *httpHelper) showClientInfo(c *models.ReqContext) response.Response {
|
||||
func (s *httpHelper) showClientInfo(c *contextmodel.ReqContext) response.Response {
|
||||
if s.access.sys != nil {
|
||||
info := s.access.sys.getInfo()
|
||||
if s.access.sys.err != nil {
|
||||
@@ -38,7 +38,7 @@ func (s *httpHelper) showClientInfo(c *models.ReqContext) response.Response {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *httpHelper) doProxy(c *models.ReqContext) {
|
||||
func (s *httpHelper) doProxy(c *contextmodel.ReqContext) {
|
||||
// TODO... this does not yet do a real proxy
|
||||
if s.access.sys != nil {
|
||||
if s.access.sys.err == nil {
|
||||
|
||||
@@ -3,7 +3,7 @@ package store
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ func splitFirstSegment(path string) (string, string) {
|
||||
return path, ""
|
||||
}
|
||||
|
||||
func getPathAndScope(c *models.ReqContext) (string, string) {
|
||||
func getPathAndScope(c *contextmodel.ReqContext) (string, string) {
|
||||
params := web.Params(c.Req)
|
||||
path := params["*"]
|
||||
if path == "" {
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/roletype"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/supportbundles"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -49,7 +49,7 @@ func (s *Service) registerAPIEndpoints(httpServer *grafanaApi.HTTPServer, routeR
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) handleList(ctx *models.ReqContext) response.Response {
|
||||
func (s *Service) handleList(ctx *contextmodel.ReqContext) response.Response {
|
||||
bundles, err := s.list(ctx.Req.Context())
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "failed to list bundles", err)
|
||||
@@ -63,7 +63,7 @@ func (s *Service) handleList(ctx *models.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
func (s *Service) handleCreate(ctx *models.ReqContext) response.Response {
|
||||
func (s *Service) handleCreate(ctx *contextmodel.ReqContext) response.Response {
|
||||
type command struct {
|
||||
Collectors []string `json:"collectors"`
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (s *Service) handleCreate(ctx *models.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusCreated, data)
|
||||
}
|
||||
|
||||
func (s *Service) handleDownload(ctx *models.ReqContext) response.Response {
|
||||
func (s *Service) handleDownload(ctx *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(ctx.Req)[":uid"]
|
||||
bundle, err := s.get(ctx.Req.Context(), uid)
|
||||
if err != nil {
|
||||
@@ -102,7 +102,7 @@ func (s *Service) handleDownload(ctx *models.ReqContext) response.Response {
|
||||
return response.CreateNormalResponse(ctx.Resp.Header(), bundle.TarBytes, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Service) handleRemove(ctx *models.ReqContext) response.Response {
|
||||
func (s *Service) handleRemove(ctx *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(ctx.Req)[":uid"]
|
||||
err := s.remove(ctx.Req.Context(), uid)
|
||||
if err != nil {
|
||||
@@ -112,7 +112,7 @@ func (s *Service) handleRemove(ctx *models.ReqContext) response.Response {
|
||||
return response.Respond(http.StatusOK, "successfully removed the support bundle")
|
||||
}
|
||||
|
||||
func (s *Service) handleGetCollectors(ctx *models.ReqContext) response.Response {
|
||||
func (s *Service) handleGetCollectors(ctx *contextmodel.ReqContext) response.Response {
|
||||
collectors := make([]supportbundles.Collector, 0, len(s.collectors))
|
||||
|
||||
for _, c := range s.collectors {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
// When the feature flag is not enabled we just implement a dummy service
|
||||
@@ -15,15 +15,15 @@ func (ds *dummyService) GetUsageStats(ctx context.Context) map[string]interface{
|
||||
return make(map[string]interface{})
|
||||
}
|
||||
|
||||
func (ds *dummyService) GetImage(c *models.ReqContext) {
|
||||
func (ds *dummyService) GetImage(c *contextmodel.ReqContext) {
|
||||
c.JSON(400, map[string]string{"error": "invalid size"})
|
||||
}
|
||||
|
||||
func (ds *dummyService) UpdateThumbnailState(c *models.ReqContext) {
|
||||
func (ds *dummyService) UpdateThumbnailState(c *contextmodel.ReqContext) {
|
||||
c.JSON(400, map[string]string{"error": "invalid size"})
|
||||
}
|
||||
|
||||
func (ds *dummyService) SetImage(c *models.ReqContext) {
|
||||
func (ds *dummyService) SetImage(c *contextmodel.ReqContext) {
|
||||
c.JSON(400, map[string]string{"error": "invalid size"})
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (ds *dummyService) Enabled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ds *dummyService) GetDashboardPreviewsSetupSettings(c *models.ReqContext) dashboardPreviewsSetupConfig {
|
||||
func (ds *dummyService) GetDashboardPreviewsSetupSettings(c *contextmodel.ReqContext) dashboardPreviewsSetupConfig {
|
||||
return dashboardPreviewsSetupConfig{
|
||||
SystemRequirements: dashboardPreviewsSystemRequirements{
|
||||
Met: false,
|
||||
@@ -41,19 +41,19 @@ func (ds *dummyService) GetDashboardPreviewsSetupSettings(c *models.ReqContext)
|
||||
}
|
||||
}
|
||||
|
||||
func (ds *dummyService) StartCrawler(c *models.ReqContext) response.Response {
|
||||
func (ds *dummyService) StartCrawler(c *contextmodel.ReqContext) response.Response {
|
||||
result := make(map[string]string)
|
||||
result["error"] = "Not enabled"
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (ds *dummyService) StopCrawler(c *models.ReqContext) response.Response {
|
||||
func (ds *dummyService) StopCrawler(c *contextmodel.ReqContext) response.Response {
|
||||
result := make(map[string]string)
|
||||
result["error"] = "Not enabled"
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (ds *dummyService) CrawlerStatus(c *models.ReqContext) response.Response {
|
||||
func (ds *dummyService) CrawlerStatus(c *contextmodel.ReqContext) response.Response {
|
||||
result := make(map[string]string)
|
||||
result["error"] = "Not enabled"
|
||||
return response.JSON(http.StatusOK, result)
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/serverlock"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources/permissions"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -32,17 +33,17 @@ type Service interface {
|
||||
registry.ProvidesUsageStats
|
||||
Run(ctx context.Context) error
|
||||
Enabled() bool
|
||||
GetImage(c *models.ReqContext)
|
||||
GetDashboardPreviewsSetupSettings(c *models.ReqContext) dashboardPreviewsSetupConfig
|
||||
GetImage(c *contextmodel.ReqContext)
|
||||
GetDashboardPreviewsSetupSettings(c *contextmodel.ReqContext) dashboardPreviewsSetupConfig
|
||||
|
||||
// from dashboard page
|
||||
SetImage(c *models.ReqContext) // form post
|
||||
UpdateThumbnailState(c *models.ReqContext)
|
||||
SetImage(c *contextmodel.ReqContext) // form post
|
||||
UpdateThumbnailState(c *contextmodel.ReqContext)
|
||||
|
||||
// Must be admin
|
||||
StartCrawler(c *models.ReqContext) response.Response
|
||||
StopCrawler(c *models.ReqContext) response.Response
|
||||
CrawlerStatus(c *models.ReqContext) response.Response
|
||||
StartCrawler(c *contextmodel.ReqContext) response.Response
|
||||
StopCrawler(c *contextmodel.ReqContext) response.Response
|
||||
CrawlerStatus(c *contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
type thumbService struct {
|
||||
@@ -154,7 +155,7 @@ func (hs *thumbService) Enabled() bool {
|
||||
return hs.features.IsEnabled(featuremgmt.FlagDashboardPreviews)
|
||||
}
|
||||
|
||||
func (hs *thumbService) parseImageReq(c *models.ReqContext, checkSave bool) *previewRequest {
|
||||
func (hs *thumbService) parseImageReq(c *contextmodel.ReqContext, checkSave bool) *previewRequest {
|
||||
params := web.Params(c.Req)
|
||||
|
||||
kind, err := ParseThumbnailKind(params[":kind"])
|
||||
@@ -199,7 +200,7 @@ type updateThumbnailStateRequest struct {
|
||||
State ThumbnailState `json:"state" binding:"Required"`
|
||||
}
|
||||
|
||||
func (hs *thumbService) UpdateThumbnailState(c *models.ReqContext) {
|
||||
func (hs *thumbService) UpdateThumbnailState(c *contextmodel.ReqContext) {
|
||||
req := hs.parseImageReq(c, false)
|
||||
if req == nil {
|
||||
return // already returned value
|
||||
@@ -231,7 +232,7 @@ func (hs *thumbService) UpdateThumbnailState(c *models.ReqContext) {
|
||||
c.JSON(http.StatusOK, map[string]string{"success": "true"})
|
||||
}
|
||||
|
||||
func (hs *thumbService) GetImage(c *models.ReqContext) {
|
||||
func (hs *thumbService) GetImage(c *contextmodel.ReqContext) {
|
||||
req := hs.parseImageReq(c, false)
|
||||
if req == nil {
|
||||
return // already returned value
|
||||
@@ -274,7 +275,7 @@ func (hs *thumbService) GetImage(c *models.ReqContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (hs *thumbService) hasAccessToPreview(c *models.ReqContext, res *DashboardThumbnail, req *previewRequest) bool {
|
||||
func (hs *thumbService) hasAccessToPreview(c *contextmodel.ReqContext, res *DashboardThumbnail, req *previewRequest) bool {
|
||||
if !hs.licensing.FeatureEnabled("accesscontrol.enforcement") {
|
||||
return true
|
||||
}
|
||||
@@ -318,7 +319,7 @@ func (hs *thumbService) hasAccessToPreview(c *models.ReqContext, res *DashboardT
|
||||
return true
|
||||
}
|
||||
|
||||
func (hs *thumbService) GetDashboardPreviewsSetupSettings(c *models.ReqContext) dashboardPreviewsSetupConfig {
|
||||
func (hs *thumbService) GetDashboardPreviewsSetupSettings(c *contextmodel.ReqContext) dashboardPreviewsSetupConfig {
|
||||
return hs.getDashboardPreviewsSetupSettings(c.Req.Context())
|
||||
}
|
||||
|
||||
@@ -361,7 +362,7 @@ func (hs *thumbService) getSystemRequirements(ctx context.Context) dashboardPrev
|
||||
}
|
||||
|
||||
// Hack for now -- lets you upload images explicitly
|
||||
func (hs *thumbService) SetImage(c *models.ReqContext) {
|
||||
func (hs *thumbService) SetImage(c *contextmodel.ReqContext) {
|
||||
req := hs.parseImageReq(c, false)
|
||||
if req == nil {
|
||||
return // already returned value
|
||||
@@ -423,7 +424,7 @@ func (hs *thumbService) SetImage(c *models.ReqContext) {
|
||||
c.JSON(http.StatusOK, map[string]int{"OK": len(fileBytes)})
|
||||
}
|
||||
|
||||
func (hs *thumbService) StartCrawler(c *models.ReqContext) response.Response {
|
||||
func (hs *thumbService) StartCrawler(c *contextmodel.ReqContext) response.Response {
|
||||
body, err := io.ReadAll(c.Req.Body)
|
||||
if err != nil {
|
||||
return response.Error(500, "error reading bytes", err)
|
||||
@@ -451,7 +452,7 @@ func (hs *thumbService) StartCrawler(c *models.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, status)
|
||||
}
|
||||
|
||||
func (hs *thumbService) StopCrawler(c *models.ReqContext) response.Response {
|
||||
func (hs *thumbService) StopCrawler(c *contextmodel.ReqContext) response.Response {
|
||||
msg, err := hs.renderer.Stop()
|
||||
if err != nil {
|
||||
return response.Error(500, "error starting", err)
|
||||
@@ -459,7 +460,7 @@ func (hs *thumbService) StopCrawler(c *models.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, msg)
|
||||
}
|
||||
|
||||
func (hs *thumbService) CrawlerStatus(c *models.ReqContext) response.Response {
|
||||
func (hs *thumbService) CrawlerStatus(c *contextmodel.ReqContext) response.Response {
|
||||
msg, err := hs.renderer.Status()
|
||||
if err != nil {
|
||||
return response.Error(500, "error starting", err)
|
||||
@@ -468,7 +469,7 @@ func (hs *thumbService) CrawlerStatus(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// Ideally this service would not require first looking up the full dashboard just to bet the id!
|
||||
func (hs *thumbService) getStatus(c *models.ReqContext, uid string, checkSave bool) (int, error) {
|
||||
func (hs *thumbService) getStatus(c *contextmodel.ReqContext, uid string, checkSave bool) (int, error) {
|
||||
guardian, err := guardian.NewByUID(c.Req.Context(), uid, c.OrgID, c.SignedInUser)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user