mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore: replace sqlstore.Store with db.DB (#57010)
* chore: replace sqlstore.SQLStore with db.DB * more post-sqlstore.SQLStore cleanup
This commit is contained in:
@@ -367,12 +367,11 @@ func setupHTTPServerWithCfgDb(
|
|||||||
) accessControlScenarioContext {
|
) accessControlScenarioContext {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
db.Cfg.RBACEnabled = cfg.RBACEnabled
|
|
||||||
|
|
||||||
license := &licensing.OSSLicensingService{}
|
license := &licensing.OSSLicensingService{}
|
||||||
routeRegister := routing.NewRouteRegister()
|
routeRegister := routing.NewRouteRegister()
|
||||||
teamService := teamimpl.ProvideService(db, cfg)
|
teamService := teamimpl.ProvideService(db, cfg)
|
||||||
dashboardsStore := dashboardsstore.ProvideDashboardStore(db, featuremgmt.WithFeatures(), tagimpl.ProvideService(db, db.Cfg))
|
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||||
|
dashboardsStore := dashboardsstore.ProvideDashboardStore(db, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(db, cfg))
|
||||||
|
|
||||||
var acmock *accesscontrolmock.Mock
|
var acmock *accesscontrolmock.Mock
|
||||||
var ac accesscontrol.AccessControl
|
var ac accesscontrol.AccessControl
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/provisioning"
|
"github.com/grafana/grafana/pkg/services/provisioning"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
||||||
@@ -102,7 +103,7 @@ func TestGetHomeDashboard(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestLive(t *testing.T, store *sqlstore.SQLStore) *live.GrafanaLive {
|
func newTestLive(t *testing.T, store db.DB) *live.GrafanaLive {
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
cfg := &setting.Cfg{AppURL: "http://localhost:3000/"}
|
cfg := &setting.Cfg{AppURL: "http://localhost:3000/"}
|
||||||
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||||
@@ -991,7 +992,7 @@ func getDashboardShouldReturn200WithConfig(t *testing.T, sc *scenarioContext, pr
|
|||||||
|
|
||||||
if dashboardStore == nil {
|
if dashboardStore == nil {
|
||||||
sql := sqlstore.InitTestDB(t)
|
sql := sqlstore.InitTestDB(t)
|
||||||
dashboardStore = database.ProvideDashboardStore(sql, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
dashboardStore = database.ProvideDashboardStore(sql, sql.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryPanelsService := mockLibraryPanelService{}
|
libraryPanelsService := mockLibraryPanelService{}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
@@ -13,17 +15,16 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/api"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/api"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/database"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/database"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cacheTTL = 10 * time.Second
|
cacheTTL = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(cfg *setting.Cfg, store sqlstore.Store, routeRegister routing.RouteRegister, cache *localcache.CacheService) (*Service, error) {
|
func ProvideService(cfg *setting.Cfg, store db.DB, routeRegister routing.RouteRegister, cache *localcache.CacheService) (*Service, error) {
|
||||||
service := ProvideOSSService(cfg, database.ProvideService(store), cache)
|
service := ProvideOSSService(cfg, database.ProvideService(store), cache)
|
||||||
|
|
||||||
if !accesscontrol.IsDisabled(cfg) {
|
if !accesscontrol.IsDisabled(cfg) {
|
||||||
|
|||||||
@@ -7,18 +7,19 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
globalOrgID = 0
|
globalOrgID = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(sql sqlstore.Store) *AccessControlStore {
|
func ProvideService(sql db.DB) *AccessControlStore {
|
||||||
return &AccessControlStore{sql}
|
return &AccessControlStore{sql}
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccessControlStore struct {
|
type AccessControlStore struct {
|
||||||
sql sqlstore.Store
|
sql db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccessControlStore) GetUserPermissions(ctx context.Context, query accesscontrol.GetUserPermissionsQuery) ([]accesscontrol.Permission, error) {
|
func (s *AccessControlStore) GetUserPermissions(ctx context.Context, query accesscontrol.GetUserPermissionsQuery) ([]accesscontrol.Permission, error) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
@@ -38,7 +39,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ProvideTeamPermissions(
|
func ProvideTeamPermissions(
|
||||||
cfg *setting.Cfg, router routing.RouteRegister, sql *sqlstore.SQLStore,
|
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB,
|
||||||
ac accesscontrol.AccessControl, license models.Licensing, service accesscontrol.Service,
|
ac accesscontrol.AccessControl, license models.Licensing, service accesscontrol.Service,
|
||||||
teamService team.Service, userService user.Service,
|
teamService team.Service, userService user.Service,
|
||||||
) (*TeamPermissionsService, error) {
|
) (*TeamPermissionsService, error) {
|
||||||
@@ -112,7 +113,7 @@ var DashboardEditActions = append(DashboardViewActions, []string{dashboards.Acti
|
|||||||
var DashboardAdminActions = append(DashboardEditActions, []string{dashboards.ActionDashboardsPermissionsRead, dashboards.ActionDashboardsPermissionsWrite}...)
|
var DashboardAdminActions = append(DashboardEditActions, []string{dashboards.ActionDashboardsPermissionsRead, dashboards.ActionDashboardsPermissionsWrite}...)
|
||||||
|
|
||||||
func ProvideDashboardPermissions(
|
func ProvideDashboardPermissions(
|
||||||
cfg *setting.Cfg, router routing.RouteRegister, sql *sqlstore.SQLStore, ac accesscontrol.AccessControl,
|
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl,
|
||||||
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
|
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
|
||||||
teamService team.Service, userService user.Service,
|
teamService team.Service, userService user.Service,
|
||||||
) (*DashboardPermissionsService, error) {
|
) (*DashboardPermissionsService, error) {
|
||||||
@@ -191,7 +192,7 @@ var FolderEditActions = append(FolderViewActions, []string{
|
|||||||
var FolderAdminActions = append(FolderEditActions, []string{dashboards.ActionFoldersPermissionsRead, dashboards.ActionFoldersPermissionsWrite}...)
|
var FolderAdminActions = append(FolderEditActions, []string{dashboards.ActionFoldersPermissionsRead, dashboards.ActionFoldersPermissionsWrite}...)
|
||||||
|
|
||||||
func ProvideFolderPermissions(
|
func ProvideFolderPermissions(
|
||||||
cfg *setting.Cfg, router routing.RouteRegister, sql *sqlstore.SQLStore, accesscontrol accesscontrol.AccessControl,
|
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, accesscontrol accesscontrol.AccessControl,
|
||||||
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
|
license models.Licensing, dashboardStore dashboards.Store, service accesscontrol.Service,
|
||||||
teamService team.Service, userService user.Service,
|
teamService team.Service, userService user.Service,
|
||||||
) (*FolderPermissionsService, error) {
|
) (*FolderPermissionsService, error) {
|
||||||
@@ -282,7 +283,7 @@ type ServiceAccountPermissionsService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ProvideServiceAccountPermissions(
|
func ProvideServiceAccountPermissions(
|
||||||
cfg *setting.Cfg, router routing.RouteRegister, sql *sqlstore.SQLStore, ac accesscontrol.AccessControl,
|
cfg *setting.Cfg, router routing.RouteRegister, sql db.DB, ac accesscontrol.AccessControl,
|
||||||
license models.Licensing, serviceAccountStore serviceaccounts.Store, service accesscontrol.Service,
|
license models.Licensing, serviceAccountStore serviceaccounts.Store, service accesscontrol.Service,
|
||||||
teamService team.Service, userService user.Service,
|
teamService team.Service, userService user.Service,
|
||||||
) (*ServiceAccountPermissionsService, error) {
|
) (*ServiceAccountPermissionsService, error) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -50,7 +50,7 @@ type Store interface {
|
|||||||
|
|
||||||
func New(
|
func New(
|
||||||
options Options, cfg *setting.Cfg, router routing.RouteRegister, license models.Licensing,
|
options Options, cfg *setting.Cfg, router routing.RouteRegister, license models.Licensing,
|
||||||
ac accesscontrol.AccessControl, service accesscontrol.Service, sqlStore *sqlstore.SQLStore,
|
ac accesscontrol.AccessControl, service accesscontrol.Service, sqlStore db.DB,
|
||||||
teamService team.Service, userService user.Service,
|
teamService team.Service, userService user.Service,
|
||||||
) (*Service, error) {
|
) (*Service, error) {
|
||||||
var permissions []string
|
var permissions []string
|
||||||
@@ -109,7 +109,7 @@ type Service struct {
|
|||||||
options Options
|
options Options
|
||||||
permissions []string
|
permissions []string
|
||||||
actions []string
|
actions []string
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
teamService team.Service
|
teamService team.Service
|
||||||
userService user.Service
|
userService user.Service
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,16 +10,17 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewStore(sql *sqlstore.SQLStore) *store {
|
func NewStore(sql db.DB) *store {
|
||||||
return &store{sql}
|
return &store{sql}
|
||||||
}
|
}
|
||||||
|
|
||||||
type store struct {
|
type store struct {
|
||||||
sql *sqlstore.SQLStore
|
sql db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type flatResourcePermission struct {
|
type flatResourcePermission struct {
|
||||||
@@ -309,7 +310,7 @@ func (s *store) getResourcePermissions(sess *sqlstore.DBSession, orgID int64, qu
|
|||||||
`
|
`
|
||||||
userFrom := rawFrom + `
|
userFrom := rawFrom + `
|
||||||
INNER JOIN user_role ur ON r.id = ur.role_id AND (ur.org_id = 0 OR ur.org_id = ?)
|
INNER JOIN user_role ur ON r.id = ur.role_id AND (ur.org_id = 0 OR ur.org_id = ?)
|
||||||
INNER JOIN ` + s.sql.Dialect.Quote("user") + ` u ON ur.user_id = u.id
|
INNER JOIN ` + s.sql.GetDialect().Quote("user") + ` u ON ur.user_id = u.id
|
||||||
`
|
`
|
||||||
teamFrom := rawFrom + `
|
teamFrom := rawFrom + `
|
||||||
INNER JOIN team_role tr ON r.id = tr.role_id AND (tr.org_id = 0 OR tr.org_id = ?)
|
INNER JOIN team_role tr ON r.id = tr.role_id AND (tr.org_id = 0 OR tr.org_id = ?)
|
||||||
@@ -591,7 +592,7 @@ func (s *store) getPermissions(sess *sqlstore.DBSession, resource, resourceID, r
|
|||||||
LEFT JOIN team_role tr ON r.id = tr.role_id
|
LEFT JOIN team_role tr ON r.id = tr.role_id
|
||||||
LEFT JOIN team t ON tr.team_id = t.id
|
LEFT JOIN team t ON tr.team_id = t.id
|
||||||
LEFT JOIN user_role ur ON r.id = ur.role_id
|
LEFT JOIN user_role ur ON r.id = ur.role_id
|
||||||
LEFT JOIN ` + s.sql.Dialect.Quote("user") + ` u ON ur.user_id = u.id
|
LEFT JOIN ` + s.sql.GetDialect().Quote("user") + ` u ON ur.user_id = u.id
|
||||||
LEFT JOIN builtin_role br ON r.id = br.role_id
|
LEFT JOIN builtin_role br ON r.id = br.role_id
|
||||||
WHERE r.id = ? AND p.scope = ?
|
WHERE r.id = ? AND p.scope = ?
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -6,22 +6,21 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations"
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegrationAnnotations(t *testing.T) {
|
func TestIntegrationAnnotations(t *testing.T) {
|
||||||
@@ -55,7 +54,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
dashboardStore := dashboardstore.ProvideDashboardStore(sql, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
dashboardStore := dashboardstore.ProvideDashboardStore(sql, sql.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
||||||
|
|
||||||
testDashboard1 := models.SaveDashboardCommand{
|
testDashboard1 := models.SaveDashboardCommand{
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
@@ -410,7 +409,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
sql := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
sql := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
||||||
var maximumTagsLength int64 = 60
|
var maximumTagsLength int64 = 60
|
||||||
repo := xormRepositoryImpl{db: sql, cfg: setting.NewCfg(), log: log.New("annotation.test"), tagService: tagimpl.ProvideService(sql, sql.Cfg), maximumTagsLength: maximumTagsLength}
|
repo := xormRepositoryImpl{db: sql, cfg: setting.NewCfg(), log: log.New("annotation.test"), tagService: tagimpl.ProvideService(sql, sql.Cfg), maximumTagsLength: maximumTagsLength}
|
||||||
dashboardStore := dashboardstore.ProvideDashboardStore(sql, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
dashboardStore := dashboardstore.ProvideDashboardStore(sql, sql.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sql, sql.Cfg))
|
||||||
|
|
||||||
testDashboard1 := models.SaveDashboardCommand{
|
testDashboard1 := models.SaveDashboardCommand{
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
|
|||||||
@@ -10,19 +10,19 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PermissionChecker struct {
|
type PermissionChecker struct {
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
accessControl accesscontrol.AccessControl
|
accessControl accesscontrol.AccessControl
|
||||||
dashboardService dashboards.DashboardService
|
dashboardService dashboards.DashboardService
|
||||||
annotationsRepo annotations.Repository
|
annotationsRepo annotations.Repository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPermissionChecker(sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles,
|
func NewPermissionChecker(sqlStore db.DB, features featuremgmt.FeatureToggles,
|
||||||
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService,
|
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService,
|
||||||
annotationsRepo annotations.Repository,
|
annotationsRepo annotations.Repository,
|
||||||
) *PermissionChecker {
|
) *PermissionChecker {
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/comments/commentmodel"
|
"github.com/grafana/grafana/pkg/services/comments/commentmodel"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sqlStorage struct {
|
type sqlStorage struct {
|
||||||
sql *sqlstore.SQLStore
|
sql db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkObjectType(contentType string) bool {
|
func checkObjectType(contentType string) bool {
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(sqlStore *sqlstore.SQLStore, routeRegister routing.RouteRegister, ds datasources.DataSourceService, ac accesscontrol.AccessControl, bus bus.Bus) *CorrelationsService {
|
func ProvideService(sqlStore db.DB, routeRegister routing.RouteRegister, ds datasources.DataSourceService, ac accesscontrol.AccessControl, bus bus.Bus) *CorrelationsService {
|
||||||
s := &CorrelationsService{
|
s := &CorrelationsService{
|
||||||
SQLStore: sqlStore,
|
SQLStore: sqlStore,
|
||||||
RouteRegister: routeRegister,
|
RouteRegister: routeRegister,
|
||||||
@@ -37,7 +37,7 @@ type Service interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CorrelationsService struct {
|
type CorrelationsService struct {
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
log log.Logger
|
log log.Logger
|
||||||
DataSourceService datasources.DataSourceService
|
DataSourceService datasources.DataSourceService
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *models.GetDashboardACLInfoListQuery) error {
|
func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *models.GetDashboardACLInfoListQuery) error {
|
||||||
outerErr := d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
outerErr := d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||||
query.Result = make([]*models.DashboardACLInfoDTO, 0)
|
query.Result = make([]*models.DashboardACLInfoDTO, 0)
|
||||||
falseStr := d.dialect.BooleanStr(false)
|
falseStr := d.sqlStore.GetDialect().BooleanStr(false)
|
||||||
|
|
||||||
if query.DashboardID == 0 {
|
if query.DashboardID == 0 {
|
||||||
sql := `SELECT
|
sql := `SELECT
|
||||||
@@ -62,7 +62,7 @@ func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *mod
|
|||||||
d.slug,
|
d.slug,
|
||||||
d.uid,
|
d.uid,
|
||||||
d.is_folder,
|
d.is_folder,
|
||||||
CASE WHEN (da.dashboard_id = -1 AND d.folder_id > 0) OR da.dashboard_id = d.folder_id THEN ` + d.dialect.BooleanStr(true) + ` ELSE ` + falseStr + ` END AS inherited
|
CASE WHEN (da.dashboard_id = -1 AND d.folder_id > 0) OR da.dashboard_id = d.folder_id THEN ` + d.sqlStore.GetDialect().BooleanStr(true) + ` ELSE ` + falseStr + ` END AS inherited
|
||||||
FROM dashboard as d
|
FROM dashboard as d
|
||||||
LEFT JOIN dashboard folder on folder.id = d.folder_id
|
LEFT JOIN dashboard folder on folder.id = d.folder_id
|
||||||
LEFT JOIN dashboard_acl AS da ON
|
LEFT JOIN dashboard_acl AS da ON
|
||||||
@@ -75,7 +75,7 @@ func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *mod
|
|||||||
(folder.id IS NULL AND d.has_acl = ` + falseStr + `)
|
(folder.id IS NULL AND d.has_acl = ` + falseStr + `)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
LEFT JOIN ` + d.dialect.Quote("user") + ` AS u ON u.id = da.user_id
|
LEFT JOIN ` + d.sqlStore.GetDialect().Quote("user") + ` AS u ON u.id = da.user_id
|
||||||
LEFT JOIN team ug on ug.id = da.team_id
|
LEFT JOIN team ug on ug.id = da.team_id
|
||||||
WHERE d.org_id = ? AND d.id = ? AND da.id IS NOT NULL
|
WHERE d.org_id = ? AND d.id = ? AND da.id IS NOT NULL
|
||||||
ORDER BY da.id ASC
|
ORDER BY da.id ASC
|
||||||
@@ -103,9 +103,9 @@ func (d *DashboardStore) HasEditPermissionInFolders(ctx context.Context, query *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := sqlstore.NewSqlBuilder(d.sqlStore.Cfg)
|
builder := sqlstore.NewSqlBuilder(d.cfg)
|
||||||
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ? AND dashboard.is_folder = ?",
|
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ? AND dashboard.is_folder = ?",
|
||||||
query.SignedInUser.OrgID, d.dialect.BooleanStr(true))
|
query.SignedInUser.OrgID, d.sqlStore.GetDialect().BooleanStr(true))
|
||||||
builder.WriteDashboardPermissionFilter(query.SignedInUser, models.PERMISSION_EDIT)
|
builder.WriteDashboardPermissionFilter(query.SignedInUser, models.PERMISSION_EDIT)
|
||||||
|
|
||||||
type folderCount struct {
|
type folderCount struct {
|
||||||
@@ -131,7 +131,7 @@ func (d *DashboardStore) HasAdminPermissionInDashboardsOrFolders(ctx context.Con
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := sqlstore.NewSqlBuilder(d.sqlStore.Cfg)
|
builder := sqlstore.NewSqlBuilder(d.cfg)
|
||||||
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ?", query.SignedInUser.OrgID)
|
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ?", query.SignedInUser.OrgID)
|
||||||
builder.WriteDashboardPermissionFilter(query.SignedInUser, models.PERMISSION_ADMIN)
|
builder.WriteDashboardPermissionFilter(query.SignedInUser, models.PERMISSION_ADMIN)
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||||
@@ -24,7 +25,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup := func(t *testing.T) {
|
setup := func(t *testing.T) {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
||||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.Id, false, "prod", "webapp")
|
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.Id, false, "prod", "webapp")
|
||||||
|
|||||||
@@ -16,18 +16,20 @@ import (
|
|||||||
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||||
"github.com/grafana/grafana/pkg/services/store"
|
"github.com/grafana/grafana/pkg/services/store"
|
||||||
"github.com/grafana/grafana/pkg/services/tag"
|
"github.com/grafana/grafana/pkg/services/tag"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DashboardStore struct {
|
type DashboardStore struct {
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
|
cfg *setting.Cfg
|
||||||
log log.Logger
|
log log.Logger
|
||||||
dialect migrator.Dialect
|
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
tagService tag.Service
|
tagService tag.Service
|
||||||
}
|
}
|
||||||
@@ -35,8 +37,8 @@ type DashboardStore struct {
|
|||||||
// DashboardStore implements the Store interface
|
// DashboardStore implements the Store interface
|
||||||
var _ dashboards.Store = (*DashboardStore)(nil)
|
var _ dashboards.Store = (*DashboardStore)(nil)
|
||||||
|
|
||||||
func ProvideDashboardStore(sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles, tagService tag.Service) *DashboardStore {
|
func ProvideDashboardStore(sqlStore db.DB, cfg *setting.Cfg, features featuremgmt.FeatureToggles, tagService tag.Service) *DashboardStore {
|
||||||
return &DashboardStore{sqlStore: sqlStore, log: log.New("dashboard-store"), dialect: sqlStore.Dialect, features: features, tagService: tagService}
|
return &DashboardStore{sqlStore: sqlStore, cfg: cfg, log: log.New("dashboard-store"), features: features, tagService: tagService}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DashboardStore) emitEntityEvent() bool {
|
func (d *DashboardStore) emitEntityEvent() bool {
|
||||||
@@ -47,12 +49,12 @@ func (d *DashboardStore) ValidateDashboardBeforeSave(ctx context.Context, dashbo
|
|||||||
isParentFolderChanged := false
|
isParentFolderChanged := false
|
||||||
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
var err error
|
var err error
|
||||||
isParentFolderChanged, err = getExistingDashboardByIdOrUidForUpdate(sess, dashboard, d.sqlStore.Dialect, overwrite)
|
isParentFolderChanged, err = getExistingDashboardByIdOrUidForUpdate(sess, dashboard, d.sqlStore.GetDialect(), overwrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
isParentFolderChanged, err = getExistingDashboardByTitleAndFolder(sess, dashboard, d.sqlStore.Dialect, overwrite,
|
isParentFolderChanged, err = getExistingDashboardByTitleAndFolder(sess, dashboard, d.sqlStore.GetDialect(), overwrite,
|
||||||
isParentFolderChanged)
|
isParentFolderChanged)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -76,7 +78,7 @@ func (d *DashboardStore) GetFolderByTitle(ctx context.Context, orgID int64, titl
|
|||||||
// there are no nested folders so the parent folder id is always 0
|
// there are no nested folders so the parent folder id is always 0
|
||||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Title: title}
|
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Title: title}
|
||||||
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.Dialect.BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ func (d *DashboardStore) GetFolderByTitle(ctx context.Context, orgID int64, titl
|
|||||||
func (d *DashboardStore) GetFolderByID(ctx context.Context, orgID int64, id int64) (*models.Folder, error) {
|
func (d *DashboardStore) GetFolderByID(ctx context.Context, orgID int64, id int64) (*models.Folder, error) {
|
||||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Id: id}
|
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Id: id}
|
||||||
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.Dialect.BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -117,7 +119,7 @@ func (d *DashboardStore) GetFolderByUID(ctx context.Context, orgID int64, uid st
|
|||||||
|
|
||||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Uid: uid}
|
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Uid: uid}
|
||||||
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.Dialect.BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.sqlStore.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -682,7 +684,7 @@ func (d *DashboardStore) deleteAlertByIdInternal(alertId int64, reason string, s
|
|||||||
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||||
return d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
return d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||||
var dashboards = make([]*models.Dashboard, 0)
|
var dashboards = make([]*models.Dashboard, 0)
|
||||||
whereExpr := "org_id=? AND plugin_id=? AND is_folder=" + d.sqlStore.Dialect.BooleanStr(false)
|
whereExpr := "org_id=? AND plugin_id=? AND is_folder=" + d.sqlStore.GetDialect().BooleanStr(false)
|
||||||
|
|
||||||
err := dbSession.Where(whereExpr, query.OrgId, query.PluginId).Find(&dashboards)
|
err := dbSession.Where(whereExpr, query.OrgId, query.PluginId).Find(&dashboards)
|
||||||
query.Result = dashboards
|
query.Result = dashboards
|
||||||
@@ -914,13 +916,13 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
|||||||
permissions.DashboardPermissionFilter{
|
permissions.DashboardPermissionFilter{
|
||||||
OrgRole: query.SignedInUser.OrgRole,
|
OrgRole: query.SignedInUser.OrgRole,
|
||||||
OrgId: query.SignedInUser.OrgID,
|
OrgId: query.SignedInUser.OrgID,
|
||||||
Dialect: d.dialect,
|
Dialect: d.sqlStore.GetDialect(),
|
||||||
UserId: query.SignedInUser.UserID,
|
UserId: query.SignedInUser.UserID,
|
||||||
PermissionLevel: query.Permission,
|
PermissionLevel: query.Permission,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ac.IsDisabled(d.sqlStore.Cfg) {
|
if !ac.IsDisabled(d.cfg) {
|
||||||
// if access control is enabled, overwrite the filters so far
|
// if access control is enabled, overwrite the filters so far
|
||||||
filters = []interface{}{
|
filters = []interface{}{
|
||||||
permissions.NewAccessControlDashboardPermissionFilter(query.SignedInUser, query.Permission, query.Type),
|
permissions.NewAccessControlDashboardPermissionFilter(query.SignedInUser, query.Permission, query.Type),
|
||||||
@@ -954,11 +956,11 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(query.Title) > 0 {
|
if len(query.Title) > 0 {
|
||||||
filters = append(filters, searchstore.TitleFilter{Dialect: d.dialect, Title: query.Title})
|
filters = append(filters, searchstore.TitleFilter{Dialect: d.sqlStore.GetDialect(), Title: query.Title})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(query.Type) > 0 {
|
if len(query.Type) > 0 {
|
||||||
filters = append(filters, searchstore.TypeFilter{Dialect: d.dialect, Type: query.Type})
|
filters = append(filters, searchstore.TypeFilter{Dialect: d.sqlStore.GetDialect(), Type: query.Type})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(query.FolderIds) > 0 {
|
if len(query.FolderIds) > 0 {
|
||||||
@@ -966,7 +968,7 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
|||||||
}
|
}
|
||||||
|
|
||||||
var res []dashboards.DashboardSearchProjection
|
var res []dashboards.DashboardSearchProjection
|
||||||
sb := &searchstore.Builder{Dialect: d.dialect, Filters: filters}
|
sb := &searchstore.Builder{Dialect: d.sqlStore.GetDialect(), Filters: filters}
|
||||||
|
|
||||||
limit := query.Limit
|
limit := query.Limit
|
||||||
if limit < 1 {
|
if limit < 1 {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
||||||
@@ -31,7 +32,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
sqlStore.Cfg.RBACEnabled = false
|
sqlStore.Cfg.RBACEnabled = false
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = ProvideDashboardStore(sqlStore, &setting.Cfg{}, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
folder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod", "webapp")
|
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod", "webapp")
|
||||||
childDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, folder.Id, false, "prod", "webapp")
|
childDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, folder.Id, false, "prod", "webapp")
|
||||||
@@ -184,7 +185,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup2 := func() {
|
setup2 := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
||||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod")
|
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, false, "prod")
|
||||||
@@ -289,7 +290,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
setup3 := func() {
|
setup3 := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod")
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod")
|
||||||
insertTestDashboard(t, dashboardStore, "folder in another org", 2, 0, true, "prod")
|
insertTestDashboard(t, dashboardStore, "folder in another org", 2, 0, true, "prod")
|
||||||
@@ -471,7 +472,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore *sqlstore.SQLStore
|
||||||
var folder1, folder2 *models.Dashboard
|
var folder1, folder2 *models.Dashboard
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.Id, false, "prod")
|
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.Id, false, "prod")
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, title, orgId, 0, true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, title, orgId, 0, true, "prod")
|
||||||
@@ -486,7 +487,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
t.Run("GetFolderByUID", func(t *testing.T) {
|
t.Run("GetFolderByUID", func(t *testing.T) {
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
||||||
|
|
||||||
@@ -510,7 +511,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
t.Run("GetFolderByID", func(t *testing.T) {
|
t.Run("GetFolderByID", func(t *testing.T) {
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
folder := insertTestDashboard(t, dashboardStore, "TEST", orgId, 0, true, "prod")
|
||||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.Id, false, "prod")
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||||
@@ -19,7 +18,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
|
|
||||||
folderCmd := models.SaveDashboardCommand{
|
folderCmd := models.SaveDashboardCommand{
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/star/starimpl"
|
"github.com/grafana/grafana/pkg/services/star/starimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIntegrationDashboardDataAccess(t *testing.T) {
|
func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||||
@@ -35,7 +36,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
|||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
starService = starimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
starService = starimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||||
dashboardStore = ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
savedDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, savedFolder.Id, false, "prod", "webapp")
|
savedDash = insertTestDashboard(t, dashboardStore, "test dash 23", 1, savedFolder.Id, false, "prod", "webapp")
|
||||||
insertTestDashboard(t, dashboardStore, "test dash 45", 1, savedFolder.Id, false, "prod")
|
insertTestDashboard(t, dashboardStore, "test dash 45", 1, savedFolder.Id, false, "prod")
|
||||||
@@ -486,7 +487,9 @@ func TestIntegrationDashboardDataAccessGivenPluginWithImportedDashboards(t *test
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
cfg := setting.NewCfg()
|
||||||
|
cfg.IsFeatureToggleEnabled = func(key string) bool { return false }
|
||||||
|
dashboardStore := ProvideDashboardStore(sqlStore, &setting.Cfg{}, testFeatureToggles, tagimpl.ProvideService(sqlStore, cfg))
|
||||||
pluginId := "test-app"
|
pluginId := "test-app"
|
||||||
|
|
||||||
appFolder := insertTestDashboardForPlugin(t, dashboardStore, "app-test", 1, 0, true, pluginId)
|
appFolder := insertTestDashboardForPlugin(t, dashboardStore, "app-test", 1, 0, true, pluginId)
|
||||||
@@ -508,7 +511,9 @@ func TestIntegrationDashboard_SortingOptions(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
cfg := setting.NewCfg()
|
||||||
|
cfg.IsFeatureToggleEnabled = func(key string) bool { return false }
|
||||||
|
dashboardStore := ProvideDashboardStore(sqlStore, &setting.Cfg{}, testFeatureToggles, tagimpl.ProvideService(sqlStore, cfg))
|
||||||
|
|
||||||
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
||||||
dashA := insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
dashA := insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
||||||
@@ -557,7 +562,9 @@ func TestIntegrationDashboard_Filter(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := ProvideDashboardStore(sqlStore, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
cfg := setting.NewCfg()
|
||||||
|
cfg.IsFeatureToggleEnabled = func(key string) bool { return false }
|
||||||
|
dashboardStore := ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, cfg))
|
||||||
insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
||||||
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
||||||
qNoFilter := &models.FindPersistedDashboardsQuery{
|
qNoFilter := &models.FindPersistedDashboardsQuery{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
@@ -799,7 +800,7 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
|||||||
|
|
||||||
type permissionScenarioContext struct {
|
type permissionScenarioContext struct {
|
||||||
dashboardGuardianMock *guardian.FakeDashboardGuardian
|
dashboardGuardianMock *guardian.FakeDashboardGuardian
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
dashboardStore dashboards.Store
|
dashboardStore dashboards.Store
|
||||||
savedFolder *models.Dashboard
|
savedFolder *models.Dashboard
|
||||||
savedDashInFolder *models.Dashboard
|
savedDashInFolder *models.Dashboard
|
||||||
@@ -819,8 +820,9 @@ func permissionScenario(t *testing.T, desc string, canSave bool, fn permissionSc
|
|||||||
t.Run(desc, func(t *testing.T) {
|
t.Run(desc, func(t *testing.T) {
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
@@ -870,14 +872,14 @@ func permissionScenario(t *testing.T, desc string, canSave bool, fn permissionSc
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore *sqlstore.SQLStore) *models.Dashboard {
|
func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore db.DB) *models.Dashboard {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dto := toSaveDashboardDto(cmd)
|
dto := toSaveDashboardDto(cmd)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
@@ -891,12 +893,12 @@ func callSaveWithResult(t *testing.T, cmd models.SaveDashboardCommand, sqlStore
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore *sqlstore.SQLStore) error {
|
func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore db.DB) error {
|
||||||
dto := toSaveDashboardDto(cmd)
|
dto := toSaveDashboardDto(cmd)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
@@ -908,7 +910,7 @@ func callSaveWithError(cmd models.SaveDashboardCommand, sqlStore *sqlstore.SQLSt
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlStore *sqlstore.SQLStore) *models.Dashboard {
|
func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlStore db.DB) *models.Dashboard {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
cmd := models.SaveDashboardCommand{
|
cmd := models.SaveDashboardCommand{
|
||||||
@@ -930,10 +932,10 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
@@ -947,7 +949,7 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore *sqlstore.SQLStore) *models.Dashboard {
|
func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *models.Dashboard {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
cmd := models.SaveDashboardCommand{
|
cmd := models.SaveDashboardCommand{
|
||||||
OrgId: orgID,
|
OrgId: orgID,
|
||||||
@@ -968,10 +970,10 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore *sqlstore.
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
service := ProvideDashboardService(
|
service := ProvideDashboardService(
|
||||||
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
cfg, dashboardStore, &dummyDashAlertExtractor{},
|
||||||
featuremgmt.WithFeatures(),
|
featuremgmt.WithFeatures(),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
@@ -23,7 +23,7 @@ var _ DashboardGuardian = new(AccessControlDashboardGuardian)
|
|||||||
|
|
||||||
func NewAccessControlDashboardGuardian(
|
func NewAccessControlDashboardGuardian(
|
||||||
ctx context.Context, dashboardId int64, user *user.SignedInUser,
|
ctx context.Context, dashboardId int64, user *user.SignedInUser,
|
||||||
store sqlstore.Store, ac accesscontrol.AccessControl,
|
store db.DB, ac accesscontrol.AccessControl,
|
||||||
folderPermissionsService accesscontrol.FolderPermissionsService,
|
folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
||||||
dashboardService dashboards.DashboardService,
|
dashboardService dashboards.DashboardService,
|
||||||
@@ -47,7 +47,7 @@ type AccessControlDashboardGuardian struct {
|
|||||||
dashboardID int64
|
dashboardID int64
|
||||||
dashboard *models.Dashboard
|
dashboard *models.Dashboard
|
||||||
user *user.SignedInUser
|
user *user.SignedInUser
|
||||||
store sqlstore.Store
|
store db.DB
|
||||||
ac accesscontrol.AccessControl
|
ac accesscontrol.AccessControl
|
||||||
folderPermissionsService accesscontrol.FolderPermissionsService
|
folderPermissionsService accesscontrol.FolderPermissionsService
|
||||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService
|
||||||
|
|||||||
@@ -5,12 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -22,8 +16,13 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashdb "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashdb "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -592,7 +591,7 @@ func setupAccessControlGuardianTest(t *testing.T, uid string, permissions []acce
|
|||||||
toSave.SetUid(uid)
|
toSave.SetUid(uid)
|
||||||
|
|
||||||
// seed dashboard
|
// seed dashboard
|
||||||
dashStore := dashdb.ProvideDashboardStore(store, featuremgmt.WithFeatures(), tagimpl.ProvideService(store, store.Cfg))
|
dashStore := dashdb.ProvideDashboardStore(store, store.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(store, store.Cfg))
|
||||||
dash, err := dashStore.SaveDashboard(context.Background(), models.SaveDashboardCommand{
|
dash, err := dashStore.SaveDashboard(context.Background(), models.SaveDashboardCommand{
|
||||||
Dashboard: toSave.Data,
|
Dashboard: toSave.Data,
|
||||||
UserId: 1,
|
UserId: 1,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -47,7 +47,7 @@ type dashboardGuardianImpl struct {
|
|||||||
teams []*models.TeamDTO
|
teams []*models.TeamDTO
|
||||||
log log.Logger
|
log log.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
store sqlstore.Store
|
store db.DB
|
||||||
dashboardService dashboards.DashboardService
|
dashboardService dashboards.DashboardService
|
||||||
teamService team.Service
|
teamService team.Service
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ var New = func(ctx context.Context, dashId int64, orgId int64, user *user.Signed
|
|||||||
panic("no guardian factory implementation provided")
|
panic("no guardian factory implementation provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDashboardGuardian(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser, store sqlstore.Store, dashSvc dashboards.DashboardService, teamSvc team.Service) *dashboardGuardianImpl {
|
func newDashboardGuardian(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser, store db.DB, dashSvc dashboards.DashboardService, teamSvc team.Service) *dashboardGuardianImpl {
|
||||||
return &dashboardGuardianImpl{
|
return &dashboardGuardianImpl{
|
||||||
user: user,
|
user: user,
|
||||||
dashId: dashId,
|
dashId: dashId,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
type Provider struct{}
|
type Provider struct{}
|
||||||
|
|
||||||
func ProvideService(
|
func ProvideService(
|
||||||
store *sqlstore.SQLStore, ac accesscontrol.AccessControl,
|
store db.DB, ac accesscontrol.AccessControl,
|
||||||
folderPermissionsService accesscontrol.FolderPermissionsService, dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
folderPermissionsService accesscontrol.FolderPermissionsService, dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
||||||
dashboardService dashboards.DashboardService, teamService team.Service,
|
dashboardService dashboards.DashboardService, teamService team.Service,
|
||||||
) *Provider {
|
) *Provider {
|
||||||
@@ -26,14 +26,14 @@ func ProvideService(
|
|||||||
return &Provider{}
|
return &Provider{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLegacyGuardian(store sqlstore.Store, dashSvc dashboards.DashboardService, teamSvc team.Service) {
|
func InitLegacyGuardian(store db.DB, dashSvc dashboards.DashboardService, teamSvc team.Service) {
|
||||||
New = func(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser) DashboardGuardian {
|
New = func(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser) DashboardGuardian {
|
||||||
return newDashboardGuardian(ctx, dashId, orgId, user, store, dashSvc, teamSvc)
|
return newDashboardGuardian(ctx, dashId, orgId, user, store, dashSvc, teamSvc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitAccessControlGuardian(
|
func InitAccessControlGuardian(
|
||||||
store sqlstore.Store, ac accesscontrol.AccessControl, folderPermissionsService accesscontrol.FolderPermissionsService,
|
store db.DB, ac accesscontrol.AccessControl, folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardService dashboards.DashboardService,
|
dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardService dashboards.DashboardService,
|
||||||
) {
|
) {
|
||||||
New = func(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser) DashboardGuardian {
|
New = func(ctx context.Context, dashId int64, orgId int64, user *user.SignedInUser) DashboardGuardian {
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/search"
|
"github.com/grafana/grafana/pkg/services/search"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -142,7 +144,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := session.Insert(&element); err != nil {
|
if _, err := session.Insert(&element); err != nil {
|
||||||
if l.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if l.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return errLibraryElementAlreadyExists
|
return errLibraryElementAlreadyExists
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -185,7 +187,7 @@ func (l *LibraryElementService) createLibraryElement(c context.Context, signedIn
|
|||||||
func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedInUser *user.SignedInUser, uid string) (int64, error) {
|
func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedInUser *user.SignedInUser, uid string) (int64, error) {
|
||||||
var elementID int64
|
var elementID int64
|
||||||
err := l.SQLStore.WithTransactionalDbSession(c, func(session *sqlstore.DBSession) error {
|
err := l.SQLStore.WithTransactionalDbSession(c, func(session *sqlstore.DBSession) error {
|
||||||
element, err := getLibraryElement(l.SQLStore.Dialect, session, uid, signedInUser.OrgID)
|
element, err := getLibraryElement(l.SQLStore.GetDialect(), session, uid, signedInUser.OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -225,20 +227,20 @@ func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getLibraryElements gets a Library Element where param == value
|
// getLibraryElements gets a Library Element where param == value
|
||||||
func getLibraryElements(c context.Context, store *sqlstore.SQLStore, signedInUser *user.SignedInUser, params []Pair) ([]LibraryElementDTO, error) {
|
func getLibraryElements(c context.Context, store db.DB, cfg *setting.Cfg, signedInUser *user.SignedInUser, params []Pair) ([]LibraryElementDTO, error) {
|
||||||
libraryElements := make([]LibraryElementWithMeta, 0)
|
libraryElements := make([]LibraryElementWithMeta, 0)
|
||||||
err := store.WithDbSession(c, func(session *sqlstore.DBSession) error {
|
err := store.WithDbSession(c, func(session *sqlstore.DBSession) error {
|
||||||
builder := sqlstore.NewSqlBuilder(store.Cfg)
|
builder := sqlstore.NewSqlBuilder(cfg)
|
||||||
builder.Write(selectLibraryElementDTOWithMeta)
|
builder.Write(selectLibraryElementDTOWithMeta)
|
||||||
builder.Write(", 'General' as folder_name ")
|
builder.Write(", 'General' as folder_name ")
|
||||||
builder.Write(", '' as folder_uid ")
|
builder.Write(", '' as folder_uid ")
|
||||||
builder.Write(getFromLibraryElementDTOWithMeta(store.Dialect))
|
builder.Write(getFromLibraryElementDTOWithMeta(store.GetDialect()))
|
||||||
writeParamSelectorSQL(&builder, append(params, Pair{"folder_id", 0})...)
|
writeParamSelectorSQL(&builder, append(params, Pair{"folder_id", 0})...)
|
||||||
builder.Write(" UNION ")
|
builder.Write(" UNION ")
|
||||||
builder.Write(selectLibraryElementDTOWithMeta)
|
builder.Write(selectLibraryElementDTOWithMeta)
|
||||||
builder.Write(", dashboard.title as folder_name ")
|
builder.Write(", dashboard.title as folder_name ")
|
||||||
builder.Write(", dashboard.uid as folder_uid ")
|
builder.Write(", dashboard.uid as folder_uid ")
|
||||||
builder.Write(getFromLibraryElementDTOWithMeta(store.Dialect))
|
builder.Write(getFromLibraryElementDTOWithMeta(store.GetDialect()))
|
||||||
builder.Write(" INNER JOIN dashboard AS dashboard on le.folder_id = dashboard.id AND le.folder_id <> 0")
|
builder.Write(" INNER JOIN dashboard AS dashboard on le.folder_id = dashboard.id AND le.folder_id <> 0")
|
||||||
writeParamSelectorSQL(&builder, params...)
|
writeParamSelectorSQL(&builder, params...)
|
||||||
if signedInUser.OrgRole != org.RoleAdmin {
|
if signedInUser.OrgRole != org.RoleAdmin {
|
||||||
@@ -297,7 +299,7 @@ func getLibraryElements(c context.Context, store *sqlstore.SQLStore, signedInUse
|
|||||||
|
|
||||||
// getLibraryElementByUid gets a Library Element by uid.
|
// getLibraryElementByUid gets a Library Element by uid.
|
||||||
func (l *LibraryElementService) getLibraryElementByUid(c context.Context, signedInUser *user.SignedInUser, UID string) (LibraryElementDTO, error) {
|
func (l *LibraryElementService) getLibraryElementByUid(c context.Context, signedInUser *user.SignedInUser, UID string) (LibraryElementDTO, error) {
|
||||||
libraryElements, err := getLibraryElements(c, l.SQLStore, signedInUser, []Pair{{key: "org_id", value: signedInUser.OrgID}, {key: "uid", value: UID}})
|
libraryElements, err := getLibraryElements(c, l.SQLStore, l.Cfg, signedInUser, []Pair{{key: "org_id", value: signedInUser.OrgID}, {key: "uid", value: UID}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return LibraryElementDTO{}, err
|
return LibraryElementDTO{}, err
|
||||||
}
|
}
|
||||||
@@ -310,7 +312,7 @@ func (l *LibraryElementService) getLibraryElementByUid(c context.Context, signed
|
|||||||
|
|
||||||
// getLibraryElementByName gets a Library Element by name.
|
// getLibraryElementByName gets a Library Element by name.
|
||||||
func (l *LibraryElementService) getLibraryElementsByName(c context.Context, signedInUser *user.SignedInUser, name string) ([]LibraryElementDTO, error) {
|
func (l *LibraryElementService) getLibraryElementsByName(c context.Context, signedInUser *user.SignedInUser, name string) ([]LibraryElementDTO, error) {
|
||||||
return getLibraryElements(c, l.SQLStore, signedInUser, []Pair{{"org_id", signedInUser.OrgID}, {"name", name}})
|
return getLibraryElements(c, l.SQLStore, l.Cfg, signedInUser, []Pair{{"org_id", signedInUser.OrgID}, {"name", name}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// getAllLibraryElements gets all Library Elements.
|
// getAllLibraryElements gets all Library Elements.
|
||||||
@@ -337,7 +339,7 @@ func (l *LibraryElementService) getAllLibraryElements(c context.Context, signedI
|
|||||||
builder.Write(selectLibraryElementDTOWithMeta)
|
builder.Write(selectLibraryElementDTOWithMeta)
|
||||||
builder.Write(", 'General' as folder_name ")
|
builder.Write(", 'General' as folder_name ")
|
||||||
builder.Write(", '' as folder_uid ")
|
builder.Write(", '' as folder_uid ")
|
||||||
builder.Write(getFromLibraryElementDTOWithMeta(l.SQLStore.Dialect))
|
builder.Write(getFromLibraryElementDTOWithMeta(l.SQLStore.GetDialect()))
|
||||||
builder.Write(` WHERE le.org_id=? AND le.folder_id=0`, signedInUser.OrgID)
|
builder.Write(` WHERE le.org_id=? AND le.folder_id=0`, signedInUser.OrgID)
|
||||||
writeKindSQL(query, &builder)
|
writeKindSQL(query, &builder)
|
||||||
writeSearchStringSQL(query, l.SQLStore, &builder)
|
writeSearchStringSQL(query, l.SQLStore, &builder)
|
||||||
@@ -348,7 +350,7 @@ func (l *LibraryElementService) getAllLibraryElements(c context.Context, signedI
|
|||||||
builder.Write(selectLibraryElementDTOWithMeta)
|
builder.Write(selectLibraryElementDTOWithMeta)
|
||||||
builder.Write(", dashboard.title as folder_name ")
|
builder.Write(", dashboard.title as folder_name ")
|
||||||
builder.Write(", dashboard.uid as folder_uid ")
|
builder.Write(", dashboard.uid as folder_uid ")
|
||||||
builder.Write(getFromLibraryElementDTOWithMeta(l.SQLStore.Dialect))
|
builder.Write(getFromLibraryElementDTOWithMeta(l.SQLStore.GetDialect()))
|
||||||
builder.Write(" INNER JOIN dashboard AS dashboard on le.folder_id = dashboard.id AND le.folder_id<>0")
|
builder.Write(" INNER JOIN dashboard AS dashboard on le.folder_id = dashboard.id AND le.folder_id<>0")
|
||||||
builder.Write(` WHERE le.org_id=?`, signedInUser.OrgID)
|
builder.Write(` WHERE le.org_id=?`, signedInUser.OrgID)
|
||||||
writeKindSQL(query, &builder)
|
writeKindSQL(query, &builder)
|
||||||
@@ -463,7 +465,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
|||||||
return LibraryElementDTO{}, err
|
return LibraryElementDTO{}, err
|
||||||
}
|
}
|
||||||
err := l.SQLStore.WithTransactionalDbSession(c, func(session *sqlstore.DBSession) error {
|
err := l.SQLStore.WithTransactionalDbSession(c, func(session *sqlstore.DBSession) error {
|
||||||
elementInDB, err := getLibraryElement(l.SQLStore.Dialect, session, uid, signedInUser.OrgID)
|
elementInDB, err := getLibraryElement(l.SQLStore.GetDialect(), session, uid, signedInUser.OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -480,7 +482,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
|||||||
return errLibraryElementUIDTooLong
|
return errLibraryElementUIDTooLong
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := getLibraryElement(l.SQLStore.Dialect, session, updateUID, signedInUser.OrgID)
|
_, err := getLibraryElement(l.SQLStore.GetDialect(), session, updateUID, signedInUser.OrgID)
|
||||||
if !errors.Is(err, ErrLibraryElementNotFound) {
|
if !errors.Is(err, ErrLibraryElementNotFound) {
|
||||||
return errLibraryElementAlreadyExists
|
return errLibraryElementAlreadyExists
|
||||||
}
|
}
|
||||||
@@ -516,7 +518,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if rowsAffected, err := session.ID(elementInDB.ID).Update(&libraryElement); err != nil {
|
if rowsAffected, err := session.ID(elementInDB.ID).Update(&libraryElement); err != nil {
|
||||||
if l.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if l.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return errLibraryElementAlreadyExists
|
return errLibraryElementAlreadyExists
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -561,7 +563,7 @@ func (l *LibraryElementService) patchLibraryElement(c context.Context, signedInU
|
|||||||
func (l *LibraryElementService) getConnections(c context.Context, signedInUser *user.SignedInUser, uid string) ([]LibraryElementConnectionDTO, error) {
|
func (l *LibraryElementService) getConnections(c context.Context, signedInUser *user.SignedInUser, uid string) ([]LibraryElementConnectionDTO, error) {
|
||||||
connections := make([]LibraryElementConnectionDTO, 0)
|
connections := make([]LibraryElementConnectionDTO, 0)
|
||||||
err := l.SQLStore.WithDbSession(c, func(session *sqlstore.DBSession) error {
|
err := l.SQLStore.WithDbSession(c, func(session *sqlstore.DBSession) error {
|
||||||
element, err := getLibraryElement(l.SQLStore.Dialect, session, uid, signedInUser.OrgID)
|
element, err := getLibraryElement(l.SQLStore.GetDialect(), session, uid, signedInUser.OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -569,7 +571,7 @@ func (l *LibraryElementService) getConnections(c context.Context, signedInUser *
|
|||||||
builder := sqlstore.NewSqlBuilder(l.Cfg)
|
builder := sqlstore.NewSqlBuilder(l.Cfg)
|
||||||
builder.Write("SELECT lec.*, u1.login AS created_by_name, u1.email AS created_by_email, dashboard.uid AS connection_uid")
|
builder.Write("SELECT lec.*, u1.login AS created_by_name, u1.email AS created_by_email, dashboard.uid AS connection_uid")
|
||||||
builder.Write(" FROM " + models.LibraryElementConnectionTableName + " AS lec")
|
builder.Write(" FROM " + models.LibraryElementConnectionTableName + " AS lec")
|
||||||
builder.Write(" LEFT JOIN " + l.SQLStore.Dialect.Quote("user") + " AS u1 ON lec.created_by = u1.id")
|
builder.Write(" LEFT JOIN " + l.SQLStore.GetDialect().Quote("user") + " AS u1 ON lec.created_by = u1.id")
|
||||||
builder.Write(" INNER JOIN dashboard AS dashboard on lec.connection_id = dashboard.id")
|
builder.Write(" INNER JOIN dashboard AS dashboard on lec.connection_id = dashboard.id")
|
||||||
builder.Write(` WHERE lec.element_id=?`, element.ID)
|
builder.Write(` WHERE lec.element_id=?`, element.ID)
|
||||||
if signedInUser.OrgRole != org.RoleAdmin {
|
if signedInUser.OrgRole != org.RoleAdmin {
|
||||||
@@ -609,7 +611,7 @@ func (l *LibraryElementService) getElementsForDashboardID(c context.Context, das
|
|||||||
sql := selectLibraryElementDTOWithMeta +
|
sql := selectLibraryElementDTOWithMeta +
|
||||||
", coalesce(dashboard.title, 'General') AS folder_name" +
|
", coalesce(dashboard.title, 'General') AS folder_name" +
|
||||||
", coalesce(dashboard.uid, '') AS folder_uid" +
|
", coalesce(dashboard.uid, '') AS folder_uid" +
|
||||||
getFromLibraryElementDTOWithMeta(l.SQLStore.Dialect) +
|
getFromLibraryElementDTOWithMeta(l.SQLStore.GetDialect()) +
|
||||||
" LEFT JOIN dashboard AS dashboard ON dashboard.id = le.folder_id" +
|
" LEFT JOIN dashboard AS dashboard ON dashboard.id = le.folder_id" +
|
||||||
" INNER JOIN " + models.LibraryElementConnectionTableName + " AS lce ON lce.element_id = le.id AND lce.kind=1 AND lce.connection_id=?"
|
" INNER JOIN " + models.LibraryElementConnectionTableName + " AS lce ON lce.element_id = le.id AND lce.kind=1 AND lce.connection_id=?"
|
||||||
sess := session.SQL(sql, dashboardID)
|
sess := session.SQL(sql, dashboardID)
|
||||||
@@ -664,7 +666,7 @@ func (l *LibraryElementService) connectElementsToDashboardID(c context.Context,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, elementUID := range elementUIDs {
|
for _, elementUID := range elementUIDs {
|
||||||
element, err := getLibraryElement(l.SQLStore.Dialect, session, elementUID, signedInUser.OrgID)
|
element, err := getLibraryElement(l.SQLStore.GetDialect(), session, elementUID, signedInUser.OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -680,7 +682,7 @@ func (l *LibraryElementService) connectElementsToDashboardID(c context.Context,
|
|||||||
CreatedBy: signedInUser.UserID,
|
CreatedBy: signedInUser.UserID,
|
||||||
}
|
}
|
||||||
if _, err := session.Insert(&connection); err != nil {
|
if _, err := session.Insert(&connection); err != nil {
|
||||||
if l.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if l.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -709,7 +711,7 @@ func (l *LibraryElementService) deleteLibraryElementsInFolderUID(c context.Conte
|
|||||||
var folderUIDs []struct {
|
var folderUIDs []struct {
|
||||||
ID int64 `xorm:"id"`
|
ID int64 `xorm:"id"`
|
||||||
}
|
}
|
||||||
err := session.SQL("SELECT id from dashboard WHERE uid=? AND org_id=? AND is_folder=?", folderUID, signedInUser.OrgID, l.SQLStore.Dialect.BooleanStr(true)).Find(&folderUIDs)
|
err := session.SQL("SELECT id from dashboard WHERE uid=? AND org_id=? AND is_folder=?", folderUID, signedInUser.OrgID, l.SQLStore.GetDialect().BooleanStr(true)).Find(&folderUIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/folder"
|
"github.com/grafana/grafana/pkg/services/folder"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, routeRegister routing.RouteRegister, folderService folder.Service) *LibraryElementService {
|
func ProvideService(cfg *setting.Cfg, sqlStore db.DB, routeRegister routing.RouteRegister, folderService folder.Service) *LibraryElementService {
|
||||||
l := &LibraryElementService{
|
l := &LibraryElementService{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
SQLStore: sqlStore,
|
SQLStore: sqlStore,
|
||||||
@@ -36,7 +36,7 @@ type Service interface {
|
|||||||
// LibraryElementService is the service for the Library Element feature.
|
// LibraryElementService is the service for the Library Element feature.
|
||||||
type LibraryElementService struct {
|
type LibraryElementService struct {
|
||||||
Cfg *setting.Cfg
|
Cfg *setting.Cfg
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
folderService folder.Service
|
folderService folder.Service
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
||||||
@@ -255,7 +256,7 @@ type scenarioContext struct {
|
|||||||
user user.SignedInUser
|
user user.SignedInUser
|
||||||
folder *models.Folder
|
folder *models.Folder
|
||||||
initialResult libraryElementResult
|
initialResult libraryElementResult
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
type folderACLItem struct {
|
type folderACLItem struct {
|
||||||
@@ -263,7 +264,7 @@ type folderACLItem struct {
|
|||||||
permission models.PermissionType
|
permission models.PermissionType
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user user.SignedInUser, dash *models.Dashboard, folderID int64) *models.Dashboard {
|
func createDashboard(t *testing.T, sqlStore db.DB, user user.SignedInUser, dash *models.Dashboard, folderID int64) *models.Dashboard {
|
||||||
dash.FolderId = folderID
|
dash.FolderId = folderID
|
||||||
dashItem := &dashboards.SaveDashboardDTO{
|
dashItem := &dashboards.SaveDashboardDTO{
|
||||||
Dashboard: dash,
|
Dashboard: dash,
|
||||||
@@ -273,12 +274,12 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user user.Signed
|
|||||||
Overwrite: false,
|
Overwrite: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
dashAlertExtractor := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
|
||||||
features := featuremgmt.WithFeatures()
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
|
features := featuremgmt.WithFeatures()
|
||||||
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
|
dashAlertExtractor := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
folderPermissions := acmock.NewMockedPermissionsService()
|
folderPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||||
@@ -292,7 +293,7 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user user.Signed
|
|||||||
return dashboard
|
return dashboard
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string, user user.SignedInUser,
|
func createFolderWithACL(t *testing.T, sqlStore db.DB, title string, user user.SignedInUser,
|
||||||
items []folderACLItem) *models.Folder {
|
items []folderACLItem) *models.Folder {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -303,7 +304,7 @@ func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string
|
|||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
folderPermissions := acmock.NewMockedPermissionsService()
|
folderPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
|
|
||||||
d := dashboardservice.ProvideDashboardService(
|
d := dashboardservice.ProvideDashboardService(
|
||||||
cfg, dashboardStore, nil,
|
cfg, dashboardStore, nil,
|
||||||
@@ -404,7 +405,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
orgID := int64(1)
|
orgID := int64(1)
|
||||||
role := org.RoleAdmin
|
role := org.RoleAdmin
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
ac := acmock.New().WithDisabled()
|
ac := acmock.New().WithDisabled()
|
||||||
// TODO: Update tests to work with rbac
|
// TODO: Update tests to work with rbac
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pair struct {
|
type Pair struct {
|
||||||
@@ -31,10 +32,10 @@ func writeParamSelectorSQL(builder *sqlstore.SQLBuilder, params ...Pair) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePerPageSQL(query searchLibraryElementsQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writePerPageSQL(query searchLibraryElementsQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
if query.perPage != 0 {
|
if query.perPage != 0 {
|
||||||
offset := query.perPage * (query.page - 1)
|
offset := query.perPage * (query.page - 1)
|
||||||
builder.Write(sqlStore.Dialect.LimitOffset(int64(query.perPage), int64(offset)))
|
builder.Write(sqlStore.GetDialect().LimitOffset(int64(query.perPage), int64(offset)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +57,10 @@ func writeTypeFilterSQL(typeFilter []string, builder *sqlstore.SQLBuilder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSearchStringSQL(query searchLibraryElementsQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeSearchStringSQL(query searchLibraryElementsQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
if len(strings.TrimSpace(query.searchString)) > 0 {
|
if len(strings.TrimSpace(query.searchString)) > 0 {
|
||||||
builder.Write(" AND (le.name "+sqlStore.Dialect.LikeStr()+" ?", "%"+query.searchString+"%")
|
builder.Write(" AND (le.name "+sqlStore.GetDialect().LikeStr()+" ?", "%"+query.searchString+"%")
|
||||||
builder.Write(" OR le.description "+sqlStore.Dialect.LikeStr()+" ?)", "%"+query.searchString+"%")
|
builder.Write(" OR le.description "+sqlStore.GetDialect().LikeStr()+" ?)", "%"+query.searchString+"%")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/libraryelements"
|
"github.com/grafana/grafana/pkg/services/libraryelements"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, routeRegister routing.RouteRegister,
|
func ProvideService(cfg *setting.Cfg, sqlStore db.DB, routeRegister routing.RouteRegister,
|
||||||
libraryElementService libraryelements.Service) *LibraryPanelService {
|
libraryElementService libraryelements.Service) *LibraryPanelService {
|
||||||
return &LibraryPanelService{
|
return &LibraryPanelService{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
@@ -43,7 +43,7 @@ type LibraryInfo struct {
|
|||||||
// LibraryPanelService is the service for the Panel Library feature.
|
// LibraryPanelService is the service for the Panel Library feature.
|
||||||
type LibraryPanelService struct {
|
type LibraryPanelService struct {
|
||||||
Cfg *setting.Cfg
|
Cfg *setting.Cfg
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
LibraryElementService libraryelements.Service
|
LibraryElementService libraryelements.Service
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/libraryelements"
|
"github.com/grafana/grafana/pkg/services/libraryelements"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
||||||
@@ -1368,7 +1369,7 @@ func getExpected(t *testing.T, res libraryelements.LibraryElementDTO, UID string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user *user.SignedInUser, dash *models.Dashboard, folderID int64) *models.Dashboard {
|
func createDashboard(t *testing.T, sqlStore db.DB, user *user.SignedInUser, dash *models.Dashboard, folderID int64) *models.Dashboard {
|
||||||
dash.FolderId = folderID
|
dash.FolderId = folderID
|
||||||
dashItem := &dashboards.SaveDashboardDTO{
|
dashItem := &dashboards.SaveDashboardDTO{
|
||||||
Dashboard: dash,
|
Dashboard: dash,
|
||||||
@@ -1378,11 +1379,11 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user *user.Signe
|
|||||||
Overwrite: false,
|
Overwrite: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
|
||||||
dashAlertService := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.RBACEnabled = false
|
cfg.RBACEnabled = false
|
||||||
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
cfg.IsFeatureToggleEnabled = featuremgmt.WithFeatures().IsEnabled
|
||||||
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
|
dashAlertService := alerting.ProvideDashAlertExtractorService(nil, nil, nil)
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
service := dashboardservice.ProvideDashboardService(
|
service := dashboardservice.ProvideDashboardService(
|
||||||
cfg, dashboardStore, dashAlertService,
|
cfg, dashboardStore, dashAlertService,
|
||||||
@@ -1394,7 +1395,7 @@ func createDashboard(t *testing.T, sqlStore *sqlstore.SQLStore, user *user.Signe
|
|||||||
return dashboard
|
return dashboard
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string, user *user.SignedInUser,
|
func createFolderWithACL(t *testing.T, sqlStore db.DB, title string, user *user.SignedInUser,
|
||||||
items []folderACLItem) *models.Folder {
|
items []folderACLItem) *models.Folder {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -1405,7 +1406,7 @@ func createFolderWithACL(t *testing.T, sqlStore *sqlstore.SQLStore, title string
|
|||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
folderPermissions := acmock.NewMockedPermissionsService()
|
folderPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardPermissions := acmock.NewMockedPermissionsService()
|
dashboardPermissions := acmock.NewMockedPermissionsService()
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
dashboardStore := database.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, cfg))
|
||||||
d := dashboardservice.ProvideDashboardService(cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac)
|
d := dashboardservice.ProvideDashboardService(cfg, dashboardStore, nil, features, folderPermissions, dashboardPermissions, ac)
|
||||||
s := folderimpl.ProvideService(ac, busmock.New(), cfg, d, dashboardStore, features, folderPermissions, nil)
|
s := folderimpl.ProvideService(ac, busmock.New(), cfg, d, dashboardStore, features, folderPermissions, nil)
|
||||||
|
|
||||||
@@ -1498,7 +1499,7 @@ func testScenario(t *testing.T, desc string, fn func(t *testing.T, sc scenarioCo
|
|||||||
orgID := int64(1)
|
orgID := int64(1)
|
||||||
role := org.RoleAdmin
|
role := org.RoleAdmin
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := database.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
|
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
store *sqlstore.SQLStore
|
store db.DB
|
||||||
cache *localcache.CacheService
|
cache *localcache.CacheService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorage(store *sqlstore.SQLStore, cache *localcache.CacheService) *Storage {
|
func NewStorage(store db.DB, cache *localcache.CacheService) *Storage {
|
||||||
return &Storage{store: store, cache: cache}
|
return &Storage{store: store, cache: cache}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ type dashboardEvent struct {
|
|||||||
type DashboardHandler struct {
|
type DashboardHandler struct {
|
||||||
Publisher models.ChannelPublisher
|
Publisher models.ChannelPublisher
|
||||||
ClientCount models.ChannelClientCount
|
ClientCount models.ChannelClientCount
|
||||||
Store sqlstore.Store
|
Store db.DB
|
||||||
DashboardService dashboards.DashboardService
|
DashboardService dashboards.DashboardService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/query"
|
"github.com/grafana/grafana/pkg/services/query"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
@@ -74,7 +74,7 @@ type CoreGrafanaScope struct {
|
|||||||
|
|
||||||
func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, routeRegister routing.RouteRegister,
|
func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, routeRegister routing.RouteRegister,
|
||||||
pluginStore plugins.Store, cacheService *localcache.CacheService,
|
pluginStore plugins.Store, cacheService *localcache.CacheService,
|
||||||
dataSourceCache datasources.CacheService, sqlStore *sqlstore.SQLStore, secretsService secrets.Service,
|
dataSourceCache datasources.CacheService, sqlStore db.DB, secretsService secrets.Service,
|
||||||
usageStatsService usagestats.Service, queryDataService *query.Service, toggles featuremgmt.FeatureToggles,
|
usageStatsService usagestats.Service, queryDataService *query.Service, toggles featuremgmt.FeatureToggles,
|
||||||
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService, annotationsRepo annotations.Repository,
|
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService, annotationsRepo annotations.Repository,
|
||||||
orgService org.Service) (*GrafanaLive, error) {
|
orgService org.Service) (*GrafanaLive, error) {
|
||||||
@@ -404,7 +404,7 @@ type GrafanaLive struct {
|
|||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
CacheService *localcache.CacheService
|
CacheService *localcache.CacheService
|
||||||
DataSourceCache datasources.CacheService
|
DataSourceCache datasources.CacheService
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
SecretsService secrets.Service
|
SecretsService secrets.Service
|
||||||
pluginStore plugins.Store
|
pluginStore plugins.Store
|
||||||
queryDataService *query.Service
|
queryDataService *query.Service
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/rendering"
|
"github.com/grafana/grafana/pkg/services/rendering"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ type AlertNG struct {
|
|||||||
DataSourceCache datasources.CacheService
|
DataSourceCache datasources.CacheService
|
||||||
DataSourceService datasources.DataSourceService
|
DataSourceService datasources.DataSourceService
|
||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
KVStore kvstore.KVStore
|
KVStore kvstore.KVStore
|
||||||
ExpressionService *expr.Service
|
ExpressionService *expr.Service
|
||||||
DataProxy *datasourceproxy.DataSourceProxyService
|
DataProxy *datasourceproxy.DataSourceProxyService
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func (st DBstore) InsertAlertRules(ctx context.Context, rules []ngmodels.AlertRu
|
|||||||
// not able to fetch the inserted id as it's not supported by xorm
|
// not able to fetch the inserted id as it's not supported by xorm
|
||||||
for i := range newRules {
|
for i := range newRules {
|
||||||
if _, err := sess.Insert(&newRules[i]); err != nil {
|
if _, err := sess.Insert(&newRules[i]); err != nil {
|
||||||
if st.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if st.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return ngmodels.ErrAlertRuleUniqueConstraintViolation
|
return ngmodels.ErrAlertRuleUniqueConstraintViolation
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to create new rules: %w", err)
|
return fmt.Errorf("failed to create new rules: %w", err)
|
||||||
@@ -189,7 +189,7 @@ func (st DBstore) UpdateAlertRules(ctx context.Context, rules []ngmodels.UpdateR
|
|||||||
// no way to update multiple rules at once
|
// no way to update multiple rules at once
|
||||||
if updated, err := sess.ID(r.Existing.ID).AllCols().Update(r.New); err != nil || updated == 0 {
|
if updated, err := sess.ID(r.Existing.ID).AllCols().Update(r.New); err != nil || updated == 0 {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if st.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if st.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return ngmodels.ErrAlertRuleUniqueConstraintViolation
|
return ngmodels.ErrAlertRuleUniqueConstraintViolation
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to update rule [%s] %s: %w", r.New.UID, r.New.Title, err)
|
return fmt.Errorf("failed to update rule [%s] %s: %w", r.New.UID, r.New.Title, err)
|
||||||
|
|||||||
@@ -103,13 +103,13 @@ func (st *DBstore) UpdateAlertmanagerConfiguration(ctx context.Context, cmd *mod
|
|||||||
OrgID: cmd.OrgID,
|
OrgID: cmd.OrgID,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
res, err := sess.Exec(fmt.Sprintf(getInsertQuery(st.SQLStore.Dialect.DriverName()), st.SQLStore.Dialect.Quote("default")),
|
res, err := sess.Exec(fmt.Sprintf(getInsertQuery(st.SQLStore.GetDialect().DriverName()), st.SQLStore.GetDialect().Quote("default")),
|
||||||
config.AlertmanagerConfiguration,
|
config.AlertmanagerConfiguration,
|
||||||
config.ConfigurationHash,
|
config.ConfigurationHash,
|
||||||
config.ConfigurationVersion,
|
config.ConfigurationVersion,
|
||||||
config.OrgID,
|
config.OrgID,
|
||||||
config.CreatedAt,
|
config.CreatedAt,
|
||||||
st.SQLStore.Dialect.BooleanStr(config.Default),
|
st.SQLStore.GetDialect().BooleanStr(config.Default),
|
||||||
cmd.OrgID,
|
cmd.OrgID,
|
||||||
cmd.OrgID,
|
cmd.OrgID,
|
||||||
cmd.FetchedConfigurationHash,
|
cmd.FetchedConfigurationHash,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/folder"
|
"github.com/grafana/grafana/pkg/services/folder"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ type AlertingStore interface {
|
|||||||
type DBstore struct {
|
type DBstore struct {
|
||||||
Cfg setting.UnifiedAlertingSettings
|
Cfg setting.UnifiedAlertingSettings
|
||||||
FeatureToggles featuremgmt.FeatureToggles
|
FeatureToggles featuremgmt.FeatureToggles
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
Logger log.Logger
|
Logger log.Logger
|
||||||
FolderService folder.Service
|
FolderService folder.Service
|
||||||
AccessControl accesscontrol.AccessControl
|
AccessControl accesscontrol.AccessControl
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (st DBstore) SaveAlertInstances(ctx context.Context, cmd ...models.AlertIns
|
|||||||
maxRows := 20
|
maxRows := 20
|
||||||
maxArgs := maxRows * fieldsPerRow
|
maxArgs := maxRows * fieldsPerRow
|
||||||
|
|
||||||
bigUpsertSQL, err := st.SQLStore.Dialect.UpsertMultipleSQL(
|
bigUpsertSQL, err := st.SQLStore.GetDialect().UpsertMultipleSQL(
|
||||||
"alert_instance", keyNames, fieldNames, maxRows)
|
"alert_instance", keyNames, fieldNames, maxRows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -119,7 +119,7 @@ func (st DBstore) SaveAlertInstances(ctx context.Context, cmd ...models.AlertIns
|
|||||||
|
|
||||||
// Write the final batch of up to maxRows in size.
|
// Write the final batch of up to maxRows in size.
|
||||||
if values(args) != 0 && values(args)%fieldsPerRow == 0 {
|
if values(args) != 0 && values(args)%fieldsPerRow == 0 {
|
||||||
upsertSQL, err := st.SQLStore.Dialect.UpsertMultipleSQL(
|
upsertSQL, err := st.SQLStore.GetDialect().UpsertMultipleSQL(
|
||||||
"alert_instance", keyNames, fieldNames, values(args)/fieldsPerRow)
|
"alert_instance", keyNames, fieldNames, values(args)/fieldsPerRow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -154,7 +154,7 @@ func (st DBstore) SaveAlertInstance(ctx context.Context, alertInstance models.Al
|
|||||||
}
|
}
|
||||||
params := append(make([]interface{}, 0), alertInstance.RuleOrgID, alertInstance.RuleUID, labelTupleJSON, alertInstance.LabelsHash, alertInstance.CurrentState, alertInstance.CurrentReason, alertInstance.CurrentStateSince.Unix(), alertInstance.CurrentStateEnd.Unix(), alertInstance.LastEvalTime.Unix())
|
params := append(make([]interface{}, 0), alertInstance.RuleOrgID, alertInstance.RuleUID, labelTupleJSON, alertInstance.LabelsHash, alertInstance.CurrentState, alertInstance.CurrentReason, alertInstance.CurrentStateSince.Unix(), alertInstance.CurrentStateEnd.Unix(), alertInstance.LastEvalTime.Unix())
|
||||||
|
|
||||||
upsertSQL := st.SQLStore.Dialect.UpsertSQL(
|
upsertSQL := st.SQLStore.GetDialect().UpsertSQL(
|
||||||
"alert_instance",
|
"alert_instance",
|
||||||
[]string{"rule_org_id", "rule_uid", "labels_hash"},
|
[]string{"rule_org_id", "rule_uid", "labels_hash"},
|
||||||
[]string{"rule_org_id", "rule_uid", "labels", "labels_hash", "current_state", "current_reason", "current_state_since", "current_state_end", "last_eval_time"})
|
[]string{"rule_org_id", "rule_uid", "labels", "labels_hash", "current_state", "current_reason", "current_state_since", "current_state_end", "last_eval_time"})
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
busmock "github.com/grafana/grafana/pkg/bus/mock"
|
busmock "github.com/grafana/grafana/pkg/bus/mock"
|
||||||
@@ -34,9 +36,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeFeatures struct {
|
type FakeFeatures struct {
|
||||||
@@ -75,7 +74,7 @@ func SetupTestEnv(tb testing.TB, baseInterval time.Duration) (*ngalert.AlertNG,
|
|||||||
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
||||||
sqlStore := sqlstore.InitTestDB(tb)
|
sqlStore := sqlstore.InitTestDB(tb)
|
||||||
secretsService := secretsManager.SetupTestService(tb, database.ProvideSecretsStore(sqlStore))
|
secretsService := secretsManager.SetupTestService(tb, database.ProvideSecretsStore(sqlStore))
|
||||||
dashboardStore := databasestore.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := databasestore.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
|
|
||||||
ac := acmock.New()
|
ac := acmock.New()
|
||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/quota"
|
"github.com/grafana/grafana/pkg/services/quota"
|
||||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(
|
func ProvideService(
|
||||||
ac accesscontrol.AccessControl,
|
ac accesscontrol.AccessControl,
|
||||||
cfg *setting.Cfg,
|
cfg *setting.Cfg,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
pluginStore plugifaces.Store,
|
pluginStore plugifaces.Store,
|
||||||
encryptionService encryption.Internal,
|
encryptionService encryption.Internal,
|
||||||
notificatonService *notifications.NotificationService,
|
notificatonService *notifications.NotificationService,
|
||||||
@@ -121,7 +121,7 @@ func newProvisioningServiceImpl(
|
|||||||
|
|
||||||
type ProvisioningServiceImpl struct {
|
type ProvisioningServiceImpl struct {
|
||||||
Cfg *setting.Cfg
|
Cfg *setting.Cfg
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
orgService org.Service
|
orgService org.Service
|
||||||
ac accesscontrol.AccessControl
|
ac accesscontrol.AccessControl
|
||||||
pluginStore plugifaces.Store
|
pluginStore plugifaces.Store
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
||||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||||
@@ -26,15 +26,14 @@ import (
|
|||||||
dashboardStore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashboardStore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
|
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||||
publicdashboardsStore "github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
publicdashboardsStore "github.com/grafana/grafana/pkg/services/publicdashboards/database"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
publicdashboardsService "github.com/grafana/grafana/pkg/services/publicdashboards/service"
|
publicdashboardsService "github.com/grafana/grafana/pkg/services/publicdashboards/service"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
@@ -618,7 +617,7 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create dashboard
|
// create dashboard
|
||||||
dashboardStoreService := dashboardStore.ProvideDashboardStore(db, featuremgmt.WithFeatures(), tagimpl.ProvideService(db, db.Cfg))
|
dashboardStoreService := dashboardStore.ProvideDashboardStore(db, db.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(db, db.Cfg))
|
||||||
dashboard, err := dashboardStoreService.SaveDashboard(context.Background(), saveDashboardCmd)
|
dashboard, err := dashboardStoreService.SaveDashboard(context.Background(), saveDashboardCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/internal/tokens"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/internal/tokens"
|
||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Define the storage implementation. We're generating the mock implementation
|
// Define the storage implementation. We're generating the mock implementation
|
||||||
// automatically
|
// automatically
|
||||||
type PublicDashboardStoreImpl struct {
|
type PublicDashboardStoreImpl struct {
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
log log.Logger
|
log log.Logger
|
||||||
dialect migrator.Dialect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var LogPrefix = "publicdashboards.store"
|
var LogPrefix = "publicdashboards.store"
|
||||||
@@ -30,11 +29,10 @@ var LogPrefix = "publicdashboards.store"
|
|||||||
var _ publicdashboards.Store = (*PublicDashboardStoreImpl)(nil)
|
var _ publicdashboards.Store = (*PublicDashboardStoreImpl)(nil)
|
||||||
|
|
||||||
// Factory used by wire to dependency injection
|
// Factory used by wire to dependency injection
|
||||||
func ProvideStore(sqlStore *sqlstore.SQLStore) *PublicDashboardStoreImpl {
|
func ProvideStore(sqlStore db.DB) *PublicDashboardStoreImpl {
|
||||||
return &PublicDashboardStoreImpl{
|
return &PublicDashboardStoreImpl{
|
||||||
sqlStore: sqlStore,
|
sqlStore: sqlStore,
|
||||||
log: log.New(LogPrefix),
|
log: log.New(LogPrefix),
|
||||||
dialect: sqlStore.Dialect,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestLogPrefix(t *testing.T) {
|
|||||||
|
|
||||||
func TestIntegrationListPublicDashboard(t *testing.T) {
|
func TestIntegrationListPublicDashboard(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
sqlStore := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := ProvideStore(sqlStore)
|
publicdashboardStore := ProvideStore(sqlStore)
|
||||||
|
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
@@ -71,7 +71,7 @@ func TestIntegrationGetDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ func TestIntegrationAccessTokenExists(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ func TestIntegrationPublicDashboardEnabled(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -221,7 +221,7 @@ func TestIntegrationGetPublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -290,7 +290,7 @@ func TestIntegrationGetPublicDashboardConfig(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
@@ -344,7 +344,7 @@ func TestIntegrationSavePublicDashboardConfig(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, true)
|
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, true)
|
||||||
@@ -406,7 +406,7 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, true)
|
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, true)
|
||||||
@@ -485,7 +485,7 @@ func TestIntegrationGetPublicDashboardOrgId(t *testing.T) {
|
|||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = sqlstore.InitTestDB(t)
|
sqlStore = sqlstore.InitTestDB(t)
|
||||||
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore = dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore = ProvideStore(sqlStore)
|
publicdashboardStore = ProvideStore(sqlStore)
|
||||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func TestGetPublicDashboard(t *testing.T) {
|
|||||||
func TestSavePublicDashboard(t *testing.T) {
|
func TestSavePublicDashboard(t *testing.T) {
|
||||||
t.Run("Saving public dashboard", func(t *testing.T) {
|
t.Run("Saving public dashboard", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash whose dashboard has template variables returns error", func(t *testing.T) {
|
t.Run("Validate pubdash whose dashboard has template variables returns error", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
templateVars := make([]map[string]interface{}, 1)
|
templateVars := make([]map[string]interface{}, 1)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, templateVars)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, templateVars)
|
||||||
@@ -253,7 +253,7 @@ func TestSavePublicDashboard(t *testing.T) {
|
|||||||
func TestUpdatePublicDashboard(t *testing.T) {
|
func TestUpdatePublicDashboard(t *testing.T) {
|
||||||
t.Run("Updating public dashboard", func(t *testing.T) {
|
t.Run("Updating public dashboard", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Updating set empty time settings", func(t *testing.T) {
|
t.Run("Updating set empty time settings", func(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|
||||||
@@ -364,7 +364,7 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildAnonymousUser(t *testing.T) {
|
func TestBuildAnonymousUser(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
service := &PublicDashboardServiceImpl{
|
service := &PublicDashboardServiceImpl{
|
||||||
@@ -385,7 +385,7 @@ func TestBuildAnonymousUser(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetMetricRequest(t *testing.T) {
|
func TestGetMetricRequest(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
publicDashboard := &PublicDashboard{
|
publicDashboard := &PublicDashboard{
|
||||||
@@ -428,7 +428,7 @@ func TestGetMetricRequest(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildMetricRequest(t *testing.T) {
|
func TestBuildMetricRequest(t *testing.T) {
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
sqlStore := sqlstore.InitTestDB(t)
|
||||||
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
dashboardStore := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore, sqlStore.Cfg))
|
||||||
publicdashboardStore := database.ProvideStore(sqlStore)
|
publicdashboardStore := database.ProvideStore(sqlStore)
|
||||||
|
|
||||||
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true, []map[string]interface{}{})
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ func (s QueryHistoryService) starQuery(ctx context.Context, user *user.SignedInU
|
|||||||
|
|
||||||
_, err = session.Insert(&queryHistoryStar)
|
_, err = session.Insert(&queryHistoryStar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.SQLStore.Dialect.IsUniqueConstraintViolation(err) {
|
if s.SQLStore.GetDialect().IsUniqueConstraintViolation(err) {
|
||||||
return ErrQueryAlreadyStarred
|
return ErrQueryAlreadyStarred
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, routeRegister routing.RouteRegister) *QueryHistoryService {
|
func ProvideService(cfg *setting.Cfg, sqlStore db.DB, routeRegister routing.RouteRegister) *QueryHistoryService {
|
||||||
s := &QueryHistoryService{
|
s := &QueryHistoryService{
|
||||||
SQLStore: sqlStore,
|
SQLStore: sqlStore,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
@@ -39,7 +39,7 @@ type Service interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueryHistoryService struct {
|
type QueryHistoryService struct {
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
Cfg *setting.Cfg
|
Cfg *setting.Cfg
|
||||||
RouteRegister routing.RouteRegister
|
RouteRegister routing.RouteRegister
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|||||||
@@ -5,27 +5,28 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeStarredSQL(query SearchInQueryHistoryQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeStarredSQL(query SearchInQueryHistoryQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
if query.OnlyStarred {
|
if query.OnlyStarred {
|
||||||
builder.Write(sqlStore.Dialect.BooleanStr(true) + ` AS starred
|
builder.Write(sqlStore.GetDialect().BooleanStr(true) + ` AS starred
|
||||||
FROM query_history
|
FROM query_history
|
||||||
INNER JOIN query_history_star ON query_history_star.query_uid = query_history.uid
|
INNER JOIN query_history_star ON query_history_star.query_uid = query_history.uid
|
||||||
`)
|
`)
|
||||||
} else {
|
} else {
|
||||||
builder.Write(` CASE WHEN query_history_star.query_uid IS NULL THEN ` + sqlStore.Dialect.BooleanStr(false) + ` ELSE ` + sqlStore.Dialect.BooleanStr(true) + ` END AS starred
|
builder.Write(` CASE WHEN query_history_star.query_uid IS NULL THEN ` + sqlStore.GetDialect().BooleanStr(false) + ` ELSE ` + sqlStore.GetDialect().BooleanStr(true) + ` END AS starred
|
||||||
FROM query_history
|
FROM query_history
|
||||||
LEFT JOIN query_history_star ON query_history_star.query_uid = query_history.uid
|
LEFT JOIN query_history_star ON query_history_star.query_uid = query_history.uid
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeFiltersSQL(query SearchInQueryHistoryQuery, user *user.SignedInUser, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeFiltersSQL(query SearchInQueryHistoryQuery, user *user.SignedInUser, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
params := []interface{}{user.OrgID, user.UserID, query.From, query.To, "%" + query.SearchString + "%", "%" + query.SearchString + "%"}
|
params := []interface{}{user.OrgID, user.UserID, query.From, query.To, "%" + query.SearchString + "%", "%" + query.SearchString + "%"}
|
||||||
var sql bytes.Buffer
|
var sql bytes.Buffer
|
||||||
sql.WriteString(" WHERE query_history.org_id = ? AND query_history.created_by = ? AND query_history.created_at >= ? AND query_history.created_at <= ? AND (query_history.queries " + sqlStore.Dialect.LikeStr() + " ? OR query_history.comment " + sqlStore.Dialect.LikeStr() + " ?) ")
|
sql.WriteString(" WHERE query_history.org_id = ? AND query_history.created_by = ? AND query_history.created_at >= ? AND query_history.created_at <= ? AND (query_history.queries " + sqlStore.GetDialect().LikeStr() + " ? OR query_history.comment " + sqlStore.GetDialect().LikeStr() + " ?) ")
|
||||||
|
|
||||||
if len(query.DatasourceUIDs) > 0 {
|
if len(query.DatasourceUIDs) > 0 {
|
||||||
for _, uid := range query.DatasourceUIDs {
|
for _, uid := range query.DatasourceUIDs {
|
||||||
@@ -36,7 +37,7 @@ func writeFiltersSQL(query SearchInQueryHistoryQuery, user *user.SignedInUser, s
|
|||||||
builder.Write(sql.String(), params...)
|
builder.Write(sql.String(), params...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSortSQL(query SearchInQueryHistoryQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeSortSQL(query SearchInQueryHistoryQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
if query.Sort == "time-asc" {
|
if query.Sort == "time-asc" {
|
||||||
builder.Write(" ORDER BY created_at ASC ")
|
builder.Write(" ORDER BY created_at ASC ")
|
||||||
} else {
|
} else {
|
||||||
@@ -44,10 +45,10 @@ func writeSortSQL(query SearchInQueryHistoryQuery, sqlStore *sqlstore.SQLStore,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeLimitSQL(query SearchInQueryHistoryQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeLimitSQL(query SearchInQueryHistoryQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
builder.Write(" LIMIT ? ", query.Limit)
|
builder.Write(" LIMIT ? ", query.Limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeOffsetSQL(query SearchInQueryHistoryQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
func writeOffsetSQL(query SearchInQueryHistoryQuery, sqlStore db.DB, builder *sqlstore.SQLBuilder) {
|
||||||
builder.Write(" OFFSET ? ", query.Limit*(query.Page-1))
|
builder.Write(" OFFSET ? ", query.Limit*(query.Page-1))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/star"
|
"github.com/grafana/grafana/pkg/services/star"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(cfg *setting.Cfg, sqlstore *sqlstore.SQLStore, starService star.Service, dashboardService dashboards.DashboardService) *SearchService {
|
func ProvideService(cfg *setting.Cfg, sqlstore db.DB, starService star.Service, dashboardService dashboards.DashboardService) *SearchService {
|
||||||
s := &SearchService{
|
s := &SearchService{
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
sortOptions: map[string]models.SortOption{
|
sortOptions: map[string]models.SortOption{
|
||||||
@@ -53,7 +53,7 @@ type Service interface {
|
|||||||
type SearchService struct {
|
type SearchService struct {
|
||||||
Cfg *setting.Cfg
|
Cfg *setting.Cfg
|
||||||
sortOptions map[string]models.SortOption
|
sortOptions map[string]models.SortOption
|
||||||
sqlstore sqlstore.Store
|
sqlstore db.DB
|
||||||
starService star.Service
|
starService star.Service
|
||||||
dashboardService dashboards.DashboardService
|
dashboardService dashboards.DashboardService
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,21 +5,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"xorm.io/xorm"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/kmsproviders"
|
"github.com/grafana/grafana/pkg/services/kmsproviders"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"xorm.io/xorm"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dataKeysTable = "data_keys"
|
const dataKeysTable = "data_keys"
|
||||||
|
|
||||||
type SecretsStoreImpl struct {
|
type SecretsStoreImpl struct {
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideSecretsStore(sqlStore *sqlstore.SQLStore) *SecretsStoreImpl {
|
func ProvideSecretsStore(sqlStore db.DB) *SecretsStoreImpl {
|
||||||
return &SecretsStoreImpl{
|
return &SecretsStoreImpl{
|
||||||
sqlStore: sqlStore,
|
sqlStore: sqlStore,
|
||||||
log: log.New("secrets.store"),
|
log: log.New("secrets.store"),
|
||||||
@@ -56,7 +58,7 @@ func (ss *SecretsStoreImpl) GetCurrentDataKey(ctx context.Context, label string)
|
|||||||
err := ss.sqlStore.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
err := ss.sqlStore.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
var err error
|
var err error
|
||||||
exists, err = sess.Table(dataKeysTable).
|
exists, err = sess.Table(dataKeysTable).
|
||||||
Where("label = ? AND active = ?", label, ss.sqlStore.Dialect.BooleanStr(true)).
|
Where("label = ? AND active = ?", label, ss.sqlStore.GetDialect().BooleanStr(true)).
|
||||||
Get(dataKey)
|
Get(dataKey)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
@@ -102,7 +104,7 @@ func (ss *SecretsStoreImpl) CreateDataKeyWithDBSession(_ context.Context, dataKe
|
|||||||
func (ss *SecretsStoreImpl) DisableDataKeys(ctx context.Context) error {
|
func (ss *SecretsStoreImpl) DisableDataKeys(ctx context.Context) error {
|
||||||
return ss.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
return ss.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
_, err := sess.Table(dataKeysTable).
|
_, err := sess.Table(dataKeysTable).
|
||||||
Where("active = ?", ss.sqlStore.Dialect.BooleanStr(true)).
|
Where("active = ?", ss.sqlStore.GetDialect().BooleanStr(true)).
|
||||||
UseBool("active").Update(&secrets.DataKey{Active: false})
|
UseBool("active").Update(&secrets.DataKey{Active: false})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ProvideService(
|
func ProvideService(
|
||||||
sqlStore sqlstore.Store,
|
sqlStore db.DB,
|
||||||
secretsService secrets.Service,
|
secretsService secrets.Service,
|
||||||
pluginsManager plugins.SecretsPluginManager,
|
pluginsManager plugins.SecretsPluginManager,
|
||||||
kvstore kvstore.KVStore,
|
kvstore kvstore.KVStore,
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SecretsKVStoreSQL provides a key/value store backed by the Grafana database
|
// SecretsKVStoreSQL provides a key/value store backed by the Grafana database
|
||||||
type SecretsKVStoreSQL struct {
|
type SecretsKVStoreSQL struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
sqlStore sqlstore.Store
|
sqlStore db.DB
|
||||||
secretsService secrets.Service
|
secretsService secrets.Service
|
||||||
decryptionCache decryptionCache
|
decryptionCache decryptionCache
|
||||||
}
|
}
|
||||||
@@ -31,7 +32,7 @@ type cachedDecrypted struct {
|
|||||||
|
|
||||||
var b64 = base64.RawStdEncoding
|
var b64 = base64.RawStdEncoding
|
||||||
|
|
||||||
func NewSQLSecretsKVStore(sqlStore sqlstore.Store, secretsService secrets.Service, logger log.Logger) *SecretsKVStoreSQL {
|
func NewSQLSecretsKVStore(sqlStore db.DB, secretsService secrets.Service, logger log.Logger) *SecretsKVStoreSQL {
|
||||||
return &SecretsKVStoreSQL{
|
return &SecretsKVStoreSQL{
|
||||||
sqlStore: sqlStore,
|
sqlStore: sqlStore,
|
||||||
secretsService: secretsService,
|
secretsService: secretsService,
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SecretsMigrator struct {
|
type SecretsMigrator struct {
|
||||||
encryptionSrv encryption.Internal
|
encryptionSrv encryption.Internal
|
||||||
secretsSrv *manager.SecretsService
|
secretsSrv *manager.SecretsService
|
||||||
sqlStore *sqlstore.SQLStore
|
sqlStore db.DB
|
||||||
settings setting.Provider
|
settings setting.Provider
|
||||||
features featuremgmt.FeatureToggles
|
features featuremgmt.FeatureToggles
|
||||||
}
|
}
|
||||||
@@ -24,7 +25,7 @@ type SecretsMigrator struct {
|
|||||||
func ProvideSecretsMigrator(
|
func ProvideSecretsMigrator(
|
||||||
encryptionSrv encryption.Internal,
|
encryptionSrv encryption.Internal,
|
||||||
service *manager.SecretsService,
|
service *manager.SecretsService,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
settings setting.Provider,
|
settings setting.Provider,
|
||||||
features featuremgmt.FeatureToggles,
|
features featuremgmt.FeatureToggles,
|
||||||
) *SecretsMigrator {
|
) *SecretsMigrator {
|
||||||
@@ -44,7 +45,7 @@ func (m *SecretsMigrator) ReEncryptSecrets(ctx context.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toReencrypt := []interface {
|
toReencrypt := []interface {
|
||||||
reencrypt(context.Context, *manager.SecretsService, *sqlstore.SQLStore) bool
|
reencrypt(context.Context, *manager.SecretsService, db.DB) bool
|
||||||
}{
|
}{
|
||||||
simpleSecret{tableName: "dashboard_snapshot", columnName: "dashboard_encrypted"},
|
simpleSecret{tableName: "dashboard_snapshot", columnName: "dashboard_encrypted"},
|
||||||
b64Secret{simpleSecret: simpleSecret{tableName: "user_auth", columnName: "o_auth_access_token"}, encoding: base64.StdEncoding},
|
b64Secret{simpleSecret: simpleSecret{tableName: "user_auth", columnName: "o_auth_access_token"}, encoding: base64.StdEncoding},
|
||||||
@@ -74,7 +75,7 @@ func (m *SecretsMigrator) RollBackSecrets(ctx context.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toRollback := []interface {
|
toRollback := []interface {
|
||||||
rollback(context.Context, *manager.SecretsService, encryption.Internal, *sqlstore.SQLStore, string) bool
|
rollback(context.Context, *manager.SecretsService, encryption.Internal, db.DB, string) bool
|
||||||
}{
|
}{
|
||||||
simpleSecret{tableName: "dashboard_snapshot", columnName: "dashboard_encrypted"},
|
simpleSecret{tableName: "dashboard_snapshot", columnName: "dashboard_encrypted"},
|
||||||
b64Secret{simpleSecret: simpleSecret{tableName: "user_auth", columnName: "o_auth_access_token"}, encoding: base64.StdEncoding},
|
b64Secret{simpleSecret: simpleSecret{tableName: "user_auth", columnName: "o_auth_access_token"}, encoding: base64.StdEncoding},
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/secrets"
|
"github.com/grafana/grafana/pkg/services/secrets"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s simpleSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore *sqlstore.SQLStore) bool {
|
func (s simpleSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore db.DB) bool {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
Id int
|
Id int
|
||||||
Secret []byte
|
Secret []byte
|
||||||
@@ -68,7 +69,7 @@ func (s simpleSecret) reencrypt(ctx context.Context, secretsSrv *manager.Secrets
|
|||||||
return !anyFailure
|
return !anyFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s b64Secret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore *sqlstore.SQLStore) bool {
|
func (s b64Secret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore db.DB) bool {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
Id int
|
Id int
|
||||||
Secret string
|
Secret string
|
||||||
@@ -138,7 +139,7 @@ func (s b64Secret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsSer
|
|||||||
return !anyFailure
|
return !anyFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s jsonSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore *sqlstore.SQLStore) bool {
|
func (s jsonSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore db.DB) bool {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
Id int
|
Id int
|
||||||
SecureJsonData map[string][]byte
|
SecureJsonData map[string][]byte
|
||||||
@@ -198,7 +199,7 @@ func (s jsonSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsSe
|
|||||||
return !anyFailure
|
return !anyFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s alertingSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore *sqlstore.SQLStore) bool {
|
func (s alertingSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsService, sqlStore db.DB) bool {
|
||||||
var results []struct {
|
var results []struct {
|
||||||
Id int
|
Id int
|
||||||
AlertmanagerConfiguration string
|
AlertmanagerConfiguration string
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
||||||
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s simpleSecret) rollback(
|
func (s simpleSecret) rollback(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
secretsSrv *manager.SecretsService,
|
secretsSrv *manager.SecretsService,
|
||||||
encryptionSrv encryption.Internal,
|
encryptionSrv encryption.Internal,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
secretKey string,
|
secretKey string,
|
||||||
) (anyFailure bool) {
|
) (anyFailure bool) {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
@@ -76,7 +77,7 @@ func (s b64Secret) rollback(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
secretsSrv *manager.SecretsService,
|
secretsSrv *manager.SecretsService,
|
||||||
encryptionSrv encryption.Internal,
|
encryptionSrv encryption.Internal,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
secretKey string,
|
secretKey string,
|
||||||
) (anyFailure bool) {
|
) (anyFailure bool) {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
@@ -150,7 +151,7 @@ func (s jsonSecret) rollback(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
secretsSrv *manager.SecretsService,
|
secretsSrv *manager.SecretsService,
|
||||||
encryptionSrv encryption.Internal,
|
encryptionSrv encryption.Internal,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
secretKey string,
|
secretKey string,
|
||||||
) (anyFailure bool) {
|
) (anyFailure bool) {
|
||||||
var rows []struct {
|
var rows []struct {
|
||||||
@@ -214,7 +215,7 @@ func (s alertingSecret) rollback(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
secretsSrv *manager.SecretsService,
|
secretsSrv *manager.SecretsService,
|
||||||
encryptionSrv encryption.Internal,
|
encryptionSrv encryption.Internal,
|
||||||
sqlStore *sqlstore.SQLStore,
|
sqlStore db.DB,
|
||||||
secretKey string,
|
secretKey string,
|
||||||
) (anyFailure bool) {
|
) (anyFailure bool) {
|
||||||
var results []struct {
|
var results []struct {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *ServiceAccountsStoreImpl) GetUsageMetrics(ctx context.Context) (*serviceaccounts.Stats, error) {
|
func (s *ServiceAccountsStoreImpl) GetUsageMetrics(ctx context.Context) (*serviceaccounts.Stats, error) {
|
||||||
dialect := s.sqlStore.Dialect
|
dialect := s.sqlStore.GetDialect()
|
||||||
|
|
||||||
sb := &sqlstore.SQLBuilder{}
|
sb := &sqlstore.SQLBuilder{}
|
||||||
sb.Write("SELECT ")
|
sb.Write("SELECT ")
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package database
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/apikey"
|
"github.com/grafana/grafana/pkg/services/apikey"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxRetrievedTokens = 300
|
const maxRetrievedTokens = 300
|
||||||
@@ -17,7 +18,7 @@ func (s *ServiceAccountsStoreImpl) ListTokens(
|
|||||||
) ([]apikey.APIKey, error) {
|
) ([]apikey.APIKey, error) {
|
||||||
result := make([]apikey.APIKey, 0)
|
result := make([]apikey.APIKey, 0)
|
||||||
err := s.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
err := s.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||||
quotedUser := s.sqlStore.Dialect.Quote("user")
|
quotedUser := s.sqlStore.GetDialect().Quote("user")
|
||||||
sess := dbSession.Limit(maxRetrievedTokens, 0).Where("api_key.service_account_id IS NOT NULL")
|
sess := dbSession.Limit(maxRetrievedTokens, 0).Where("api_key.service_account_id IS NOT NULL")
|
||||||
|
|
||||||
if query.OrgID != nil {
|
if query.OrgID != nil {
|
||||||
@@ -89,7 +90,7 @@ func (s *ServiceAccountsStoreImpl) RevokeServiceAccountToken(ctx context.Context
|
|||||||
rawSQL := "UPDATE api_key SET is_revoked = ? WHERE id=? and org_id=? and service_account_id=?"
|
rawSQL := "UPDATE api_key SET is_revoked = ? WHERE id=? and org_id=? and service_account_id=?"
|
||||||
|
|
||||||
return s.sqlStore.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
return s.sqlStore.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
result, err := sess.Exec(rawSQL, s.sqlStore.Dialect.BooleanStr(true), tokenId, orgId, serviceAccountId)
|
result, err := sess.Exec(rawSQL, s.sqlStore.GetDialect().BooleanStr(true), tokenId, orgId, serviceAccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var getTime = time.Now
|
var getTime = time.Now
|
||||||
|
|
||||||
func ProvideService(sqlStore *sqlstore.SQLStore) *ShortURLService {
|
func ProvideService(sqlStore db.DB) *ShortURLService {
|
||||||
return &ShortURLService{
|
return &ShortURLService{
|
||||||
SQLStore: sqlStore,
|
SQLStore: sqlStore,
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ type Service interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ShortURLService struct {
|
type ShortURLService struct {
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ShortURLService) GetShortURLByUID(ctx context.Context, user *user.SignedInUser, uid string) (*models.ShortUrl, error) {
|
func (s ShortURLService) GetShortURLByUID(ctx context.Context, user *user.SignedInUser, uid string) (*models.ShortUrl, error) {
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package db
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"xorm.io/core"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||||
"xorm.io/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB interface {
|
type DB interface {
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package sqlstore
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"xorm.io/core"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"xorm.io/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TeamGuardianStoreImpl struct {
|
type TeamGuardianStoreImpl struct {
|
||||||
sqlStore sqlstore.Store
|
sqlStore db.DB
|
||||||
teamService team.Service
|
teamService team.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideTeamGuardianStore(sqlStore sqlstore.Store, teamService team.Service) *TeamGuardianStoreImpl {
|
func ProvideTeamGuardianStore(sqlStore db.DB, teamService team.Service) *TeamGuardianStoreImpl {
|
||||||
return &TeamGuardianStoreImpl{sqlStore: sqlStore, teamService: teamService}
|
return &TeamGuardianStoreImpl{sqlStore: sqlStore, teamService: teamService}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user