Use PluginSettingsService instead of SQLStore methods in plugins (#45480)

* Use PluginSettingsService instead of SQLStore in plugins

* Fix pluginproxy use of pluginsettings methods

* Fix additional pluginsettings methods

* Remove dispatch from plugindashboards

* Fix lint and adjust mock

* Remove unused pluginsettings

* Rename pluginsetting Service and ServiceImpl and add binding to wire

* Move pluginsettings binding in wire file
This commit is contained in:
idafurjes
2022-02-25 11:29:18 +01:00
committed by GitHub
parent ab0bbf6715
commit 2334b98802
10 changed files with 102 additions and 77 deletions
+13 -7
View File
@@ -12,7 +12,7 @@ import (
"github.com/grafana/grafana/pkg/services/sqlstore"
)
type Service struct {
type ServiceImpl struct {
Bus bus.Bus
SQLStore *sqlstore.SQLStore
SecretsService secrets.Service
@@ -21,6 +21,12 @@ type Service struct {
pluginSettingDecryptionCache secureJSONDecryptionCache
}
type Service interface {
GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error
UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error
UpdatePluginSettingVersion(ctx context.Context, cmd *models.UpdatePluginSettingVersionCmd) error
}
type cachedDecryptedJSON struct {
updated time.Time
json map[string]string
@@ -31,8 +37,8 @@ type secureJSONDecryptionCache struct {
sync.Mutex
}
func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secrets.Service) *Service {
s := &Service{
func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secrets.Service) *ServiceImpl {
s := &ServiceImpl{
Bus: bus,
SQLStore: store,
SecretsService: secretsService,
@@ -49,11 +55,11 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secret
return s
}
func (s *Service) GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
func (s *ServiceImpl) GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
return s.SQLStore.GetPluginSettingById(ctx, query)
}
func (s *Service) UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error {
func (s *ServiceImpl) UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error {
var err error
cmd.EncryptedSecureJsonData, err = s.SecretsService.EncryptJsonData(ctx, cmd.SecureJsonData, secrets.WithoutScope())
if err != nil {
@@ -63,11 +69,11 @@ func (s *Service) UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePlu
return s.SQLStore.UpdatePluginSetting(ctx, cmd)
}
func (s *Service) UpdatePluginSettingVersion(ctx context.Context, cmd *models.UpdatePluginSettingVersionCmd) error {
func (s *ServiceImpl) UpdatePluginSettingVersion(ctx context.Context, cmd *models.UpdatePluginSettingVersionCmd) error {
return s.SQLStore.UpdatePluginSettingVersion(ctx, cmd)
}
func (s *Service) DecryptedValues(ps *models.PluginSetting) map[string]string {
func (s *ServiceImpl) DecryptedValues(ps *models.PluginSetting) map[string]string {
s.pluginSettingDecryptionCache.Lock()
defer s.pluginSettingDecryptionCache.Unlock()