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:
@@ -5,21 +5,23 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/kmsproviders"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"xorm.io/xorm"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
)
|
||||
|
||||
const dataKeysTable = "data_keys"
|
||||
|
||||
type SecretsStoreImpl struct {
|
||||
sqlStore *sqlstore.SQLStore
|
||||
sqlStore db.DB
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func ProvideSecretsStore(sqlStore *sqlstore.SQLStore) *SecretsStoreImpl {
|
||||
func ProvideSecretsStore(sqlStore db.DB) *SecretsStoreImpl {
|
||||
return &SecretsStoreImpl{
|
||||
sqlStore: sqlStore,
|
||||
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 {
|
||||
var err error
|
||||
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)
|
||||
return err
|
||||
})
|
||||
@@ -102,7 +104,7 @@ func (ss *SecretsStoreImpl) CreateDataKeyWithDBSession(_ context.Context, dataKe
|
||||
func (ss *SecretsStoreImpl) DisableDataKeys(ctx context.Context) error {
|
||||
return ss.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
_, 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})
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
)
|
||||
|
||||
func ProvideService(
|
||||
sqlStore sqlstore.Store,
|
||||
sqlStore db.DB,
|
||||
secretsService secrets.Service,
|
||||
pluginsManager plugins.SecretsPluginManager,
|
||||
kvstore kvstore.KVStore,
|
||||
|
||||
@@ -9,12 +9,13 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
"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
|
||||
type SecretsKVStoreSQL struct {
|
||||
log log.Logger
|
||||
sqlStore sqlstore.Store
|
||||
sqlStore db.DB
|
||||
secretsService secrets.Service
|
||||
decryptionCache decryptionCache
|
||||
}
|
||||
@@ -31,7 +32,7 @@ type cachedDecrypted struct {
|
||||
|
||||
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{
|
||||
sqlStore: sqlStore,
|
||||
secretsService: secretsService,
|
||||
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
type SecretsMigrator struct {
|
||||
encryptionSrv encryption.Internal
|
||||
secretsSrv *manager.SecretsService
|
||||
sqlStore *sqlstore.SQLStore
|
||||
sqlStore db.DB
|
||||
settings setting.Provider
|
||||
features featuremgmt.FeatureToggles
|
||||
}
|
||||
@@ -24,7 +25,7 @@ type SecretsMigrator struct {
|
||||
func ProvideSecretsMigrator(
|
||||
encryptionSrv encryption.Internal,
|
||||
service *manager.SecretsService,
|
||||
sqlStore *sqlstore.SQLStore,
|
||||
sqlStore db.DB,
|
||||
settings setting.Provider,
|
||||
features featuremgmt.FeatureToggles,
|
||||
) *SecretsMigrator {
|
||||
@@ -44,7 +45,7 @@ func (m *SecretsMigrator) ReEncryptSecrets(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
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"},
|
||||
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 {
|
||||
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"},
|
||||
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/manager"
|
||||
"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 {
|
||||
Id int
|
||||
Secret []byte
|
||||
@@ -68,7 +69,7 @@ func (s simpleSecret) reencrypt(ctx context.Context, secretsSrv *manager.Secrets
|
||||
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 {
|
||||
Id int
|
||||
Secret string
|
||||
@@ -138,7 +139,7 @@ func (s b64Secret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsSer
|
||||
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 {
|
||||
Id int
|
||||
SecureJsonData map[string][]byte
|
||||
@@ -198,7 +199,7 @@ func (s jsonSecret) reencrypt(ctx context.Context, secretsSrv *manager.SecretsSe
|
||||
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 {
|
||||
Id int
|
||||
AlertmanagerConfiguration string
|
||||
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
)
|
||||
|
||||
func (s simpleSecret) rollback(
|
||||
ctx context.Context,
|
||||
secretsSrv *manager.SecretsService,
|
||||
encryptionSrv encryption.Internal,
|
||||
sqlStore *sqlstore.SQLStore,
|
||||
sqlStore db.DB,
|
||||
secretKey string,
|
||||
) (anyFailure bool) {
|
||||
var rows []struct {
|
||||
@@ -76,7 +77,7 @@ func (s b64Secret) rollback(
|
||||
ctx context.Context,
|
||||
secretsSrv *manager.SecretsService,
|
||||
encryptionSrv encryption.Internal,
|
||||
sqlStore *sqlstore.SQLStore,
|
||||
sqlStore db.DB,
|
||||
secretKey string,
|
||||
) (anyFailure bool) {
|
||||
var rows []struct {
|
||||
@@ -150,7 +151,7 @@ func (s jsonSecret) rollback(
|
||||
ctx context.Context,
|
||||
secretsSrv *manager.SecretsService,
|
||||
encryptionSrv encryption.Internal,
|
||||
sqlStore *sqlstore.SQLStore,
|
||||
sqlStore db.DB,
|
||||
secretKey string,
|
||||
) (anyFailure bool) {
|
||||
var rows []struct {
|
||||
@@ -214,7 +215,7 @@ func (s alertingSecret) rollback(
|
||||
ctx context.Context,
|
||||
secretsSrv *manager.SecretsService,
|
||||
encryptionSrv encryption.Internal,
|
||||
sqlStore *sqlstore.SQLStore,
|
||||
sqlStore db.DB,
|
||||
secretKey string,
|
||||
) (anyFailure bool) {
|
||||
var results []struct {
|
||||
|
||||
Reference in New Issue
Block a user