mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Add secure JSON fields to plugin setting DTO (#55313)
* add secure JSON fields to plugin setting DTO * add nil pointer fix * adding secureJsonFields to the plugin meta. Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
This commit is contained in:
@@ -397,9 +397,21 @@ type pluginsSettingsServiceMock struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (s *pluginsSettingsServiceMock) GetPluginSettings(_ context.Context, args *pluginsettings.GetArgs) ([]*pluginsettings.DTO, error) {
|
||||
func (s *pluginsSettingsServiceMock) GetPluginSettings(_ context.Context, args *pluginsettings.GetArgs) ([]*pluginsettings.InfoDTO, error) {
|
||||
s.getPluginSettingsArgs = append(s.getPluginSettingsArgs, args.OrgID)
|
||||
return s.storedPluginSettings, s.err
|
||||
|
||||
var res []*pluginsettings.InfoDTO
|
||||
for _, ps := range s.storedPluginSettings {
|
||||
res = append(res, &pluginsettings.InfoDTO{
|
||||
PluginID: ps.PluginID,
|
||||
OrgID: ps.OrgID,
|
||||
Enabled: ps.Enabled,
|
||||
Pinned: ps.Pinned,
|
||||
PluginVersion: ps.PluginVersion,
|
||||
})
|
||||
}
|
||||
|
||||
return res, s.err
|
||||
}
|
||||
|
||||
func (s *pluginsSettingsServiceMock) GetPluginSettingByPluginID(_ context.Context, args *pluginsettings.GetByPluginIDArgs) (*pluginsettings.DTO, error) {
|
||||
|
||||
@@ -16,6 +16,14 @@ type DTO struct {
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
type InfoDTO struct {
|
||||
PluginID string
|
||||
OrgID int64
|
||||
Enabled bool
|
||||
Pinned bool
|
||||
PluginVersion string
|
||||
}
|
||||
|
||||
type UpdateArgs struct {
|
||||
Enabled bool
|
||||
Pinned bool
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
type Service interface {
|
||||
// GetPluginSettings returns all Plugin Settings for the provided Org
|
||||
GetPluginSettings(ctx context.Context, args *GetArgs) ([]*DTO, error)
|
||||
GetPluginSettings(ctx context.Context, args *GetArgs) ([]*InfoDTO, error)
|
||||
// GetPluginSettingByPluginID returns a Plugin Settings by Plugin ID
|
||||
GetPluginSettingByPluginID(ctx context.Context, args *GetByPluginIDArgs) (*DTO, error)
|
||||
// UpdatePluginSetting updates a Plugin Setting
|
||||
|
||||
@@ -44,24 +44,20 @@ type secureJSONDecryptionCache struct {
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (s *Service) GetPluginSettings(ctx context.Context, args *pluginsettings.GetArgs) ([]*pluginsettings.DTO, error) {
|
||||
ps, err := s.getPluginSettings(ctx, args.OrgID)
|
||||
func (s *Service) GetPluginSettings(ctx context.Context, args *pluginsettings.GetArgs) ([]*pluginsettings.InfoDTO, error) {
|
||||
ps, err := s.getPluginSettingsInfo(ctx, args.OrgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []*pluginsettings.DTO
|
||||
var result []*pluginsettings.InfoDTO
|
||||
for _, p := range ps {
|
||||
result = append(result, &pluginsettings.DTO{
|
||||
ID: p.Id,
|
||||
OrgID: p.OrgId,
|
||||
PluginID: p.PluginId,
|
||||
PluginVersion: p.PluginVersion,
|
||||
JSONData: p.JsonData,
|
||||
SecureJSONData: p.SecureJsonData,
|
||||
Enabled: p.Enabled,
|
||||
Pinned: p.Pinned,
|
||||
Updated: p.Updated,
|
||||
result = append(result, &pluginsettings.InfoDTO{
|
||||
OrgID: p.OrgID,
|
||||
PluginID: p.PluginID,
|
||||
PluginVersion: p.PluginVersion,
|
||||
Enabled: p.Enabled,
|
||||
Pinned: p.Pinned,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -140,7 +136,7 @@ func (s *Service) DecryptedValues(ps *pluginsettings.DTO) map[string]string {
|
||||
return json
|
||||
}
|
||||
|
||||
func (s *Service) getPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSetting, error) {
|
||||
func (s *Service) getPluginSettingsInfo(ctx context.Context, orgID int64) ([]*models.PluginSettingInfo, error) {
|
||||
sql := `SELECT org_id, plugin_id, enabled, pinned, plugin_version FROM plugin_setting `
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -149,7 +145,7 @@ func (s *Service) getPluginSettings(ctx context.Context, orgID int64) ([]*models
|
||||
params = append(params, orgID)
|
||||
}
|
||||
|
||||
var rslt []*models.PluginSetting
|
||||
var rslt []*models.PluginSettingInfo
|
||||
err := s.db.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
return sess.SQL(sql, params...).Find(&rslt)
|
||||
})
|
||||
|
||||
@@ -137,8 +137,6 @@ func TestIntegrationPluginSettings(t *testing.T) {
|
||||
require.Equal(t, existing.OrgId, ps.OrgID)
|
||||
require.Equal(t, existing.PluginId, ps.PluginID)
|
||||
require.False(t, ps.Enabled)
|
||||
require.Nil(t, ps.JSONData)
|
||||
require.Nil(t, ps.SecureJSONData)
|
||||
})
|
||||
|
||||
t.Run("GetPluginSettings with orgID=1 should return all existing plugin settings", func(t *testing.T) {
|
||||
@@ -149,8 +147,6 @@ func TestIntegrationPluginSettings(t *testing.T) {
|
||||
require.Equal(t, existing.OrgId, ps.OrgID)
|
||||
require.Equal(t, existing.PluginId, ps.PluginID)
|
||||
require.False(t, ps.Enabled)
|
||||
require.Nil(t, ps.JSONData)
|
||||
require.Nil(t, ps.SecureJSONData)
|
||||
})
|
||||
|
||||
t.Run("GetPluginSettingById should return existing plugin settings", func(t *testing.T) {
|
||||
|
||||
@@ -106,7 +106,7 @@ func (m *mockStore) UpdatePluginSettingPluginVersion(_ context.Context, _ *plugi
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockStore) GetPluginSettings(_ context.Context, _ *pluginsettings.GetArgs) ([]*pluginsettings.DTO, error) {
|
||||
func (m *mockStore) GetPluginSettings(_ context.Context, _ *pluginsettings.GetArgs) ([]*pluginsettings.InfoDTO, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user