[MM-19711] - Get plugin configuration without removing secrets (#11928)
* Method GetUnsanitizedConfig() exposed to API (Plugin) interface and his implementations * improvements with some suggestions * Fix documentation (final period added) Co-Authored-By: Ali Farooq <25732808+ali-farooq0@users.noreply.github.com> * Added some test for Plugin.GetConfig and Plugin.GetUnsanitizedConfig * Removed empty lines
Этот коммит содержится в:
коммит произвёл
Ali Farooq
родитель
5aa24aedc8
Коммит
65f03de1ee
@@ -81,6 +81,11 @@ func (api *PluginAPI) GetConfig() *model.Config {
|
||||
return api.app.GetSanitizedConfig()
|
||||
}
|
||||
|
||||
// GetUnsanitizedConfig gets the configuration for a system admin without removing secrets.
|
||||
func (api *PluginAPI) GetUnsanitizedConfig() *model.Config {
|
||||
return api.app.Config().Clone()
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SaveConfig(config *model.Config) *model.AppError {
|
||||
return api.app.SaveConfig(config, true)
|
||||
}
|
||||
|
||||
@@ -1331,3 +1331,77 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, model.StringArray{fileInfo.Id}, actualPost.FileIds)
|
||||
}
|
||||
|
||||
func TestPluginAPIGetConfig(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
config := api.GetConfig()
|
||||
if config.LdapSettings.BindPassword != nil && len(*config.LdapSettings.BindPassword) > 0 {
|
||||
assert.Equal(t, *config.LdapSettings.BindPassword, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
assert.Equal(t, *config.FileSettings.PublicLinkSalt, model.FAKE_SETTING)
|
||||
|
||||
if len(*config.FileSettings.AmazonS3SecretAccessKey) > 0 {
|
||||
assert.Equal(t, *config.FileSettings.AmazonS3SecretAccessKey, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
if config.EmailSettings.SMTPPassword != nil && len(*config.EmailSettings.SMTPPassword) > 0 {
|
||||
assert.Equal(t, *config.EmailSettings.SMTPPassword, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
if len(*config.GitLabSettings.Secret) > 0 {
|
||||
assert.Equal(t, *config.GitLabSettings.Secret, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
assert.Equal(t, *config.SqlSettings.DataSource, model.FAKE_SETTING)
|
||||
assert.Equal(t, *config.SqlSettings.AtRestEncryptKey, model.FAKE_SETTING)
|
||||
assert.Equal(t, *config.ElasticsearchSettings.Password, model.FAKE_SETTING)
|
||||
|
||||
for i := range config.SqlSettings.DataSourceReplicas {
|
||||
assert.Equal(t, config.SqlSettings.DataSourceReplicas[i], model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
for i := range config.SqlSettings.DataSourceSearchReplicas {
|
||||
assert.Equal(t, config.SqlSettings.DataSourceSearchReplicas[i], model.FAKE_SETTING)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginAPIGetUnsanitizedConfig(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
config := api.GetUnsanitizedConfig()
|
||||
if config.LdapSettings.BindPassword != nil && len(*config.LdapSettings.BindPassword) > 0 {
|
||||
assert.NotEqual(t, *config.LdapSettings.BindPassword, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
assert.NotEqual(t, *config.FileSettings.PublicLinkSalt, model.FAKE_SETTING)
|
||||
|
||||
if len(*config.FileSettings.AmazonS3SecretAccessKey) > 0 {
|
||||
assert.NotEqual(t, *config.FileSettings.AmazonS3SecretAccessKey, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
if config.EmailSettings.SMTPPassword != nil && len(*config.EmailSettings.SMTPPassword) > 0 {
|
||||
assert.NotEqual(t, *config.EmailSettings.SMTPPassword, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
if len(*config.GitLabSettings.Secret) > 0 {
|
||||
assert.NotEqual(t, *config.GitLabSettings.Secret, model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
assert.NotEqual(t, *config.SqlSettings.DataSource, model.FAKE_SETTING)
|
||||
assert.NotEqual(t, *config.SqlSettings.AtRestEncryptKey, model.FAKE_SETTING)
|
||||
assert.NotEqual(t, *config.ElasticsearchSettings.Password, model.FAKE_SETTING)
|
||||
|
||||
for i := range config.SqlSettings.DataSourceReplicas {
|
||||
assert.NotEqual(t, config.SqlSettings.DataSourceReplicas[i], model.FAKE_SETTING)
|
||||
}
|
||||
|
||||
for i := range config.SqlSettings.DataSourceSearchReplicas {
|
||||
assert.NotEqual(t, config.SqlSettings.DataSourceSearchReplicas[i], model.FAKE_SETTING)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ type API interface {
|
||||
// GetConfig fetches the currently persisted config
|
||||
GetConfig() *model.Config
|
||||
|
||||
// GetUnsanitizedConfig fetches the currently persisted config without removing secrets.
|
||||
//
|
||||
// Minimum server version: 5.16
|
||||
GetUnsanitizedConfig() *model.Config
|
||||
|
||||
// SaveConfig sets the given config and persists the changes
|
||||
SaveConfig(config *model.Config) *model.AppError
|
||||
|
||||
|
||||
@@ -588,6 +588,33 @@ func (s *apiRPCServer) GetConfig(args *Z_GetConfigArgs, returns *Z_GetConfigRetu
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_GetUnsanitizedConfigArgs struct {
|
||||
}
|
||||
|
||||
type Z_GetUnsanitizedConfigReturns struct {
|
||||
A *model.Config
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) GetUnsanitizedConfig() *model.Config {
|
||||
_args := &Z_GetUnsanitizedConfigArgs{}
|
||||
_returns := &Z_GetUnsanitizedConfigReturns{}
|
||||
if err := g.client.Call("Plugin.GetUnsanitizedConfig", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to GetUnsanitizedConfig API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) GetUnsanitizedConfig(args *Z_GetUnsanitizedConfigArgs, returns *Z_GetUnsanitizedConfigReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
GetUnsanitizedConfig() *model.Config
|
||||
}); ok {
|
||||
returns.A = hook.GetUnsanitizedConfig()
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API GetUnsanitizedConfig called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_SaveConfigArgs struct {
|
||||
A *model.Config
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
package plugintest
|
||||
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import (
|
||||
model "github.com/mattermost/mattermost-server/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// API is an autogenerated mock type for the API type
|
||||
type API struct {
|
||||
@@ -1636,6 +1638,22 @@ func (_m *API) GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetUnsanitizedConfig provides a mock function with given fields:
|
||||
func (_m *API) GetUnsanitizedConfig() *model.Config {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 *model.Config
|
||||
if rf, ok := ret.Get(0).(func() *model.Config); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Config)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetUser provides a mock function with given fields: userId
|
||||
func (_m *API) GetUser(userId string) (*model.User, *model.AppError) {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
package plugintest
|
||||
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import (
|
||||
model "github.com/mattermost/mattermost-server/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// Helpers is an autogenerated mock type for the Helpers type
|
||||
type Helpers struct {
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
|
||||
package plugintest
|
||||
|
||||
import http "net/http"
|
||||
import io "io"
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import plugin "github.com/mattermost/mattermost-server/plugin"
|
||||
import (
|
||||
io "io"
|
||||
http "net/http"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
model "github.com/mattermost/mattermost-server/model"
|
||||
|
||||
plugin "github.com/mattermost/mattermost-server/plugin"
|
||||
)
|
||||
|
||||
// Hooks is an autogenerated mock type for the Hooks type
|
||||
type Hooks struct {
|
||||
|
||||
Ссылка в новой задаче
Block a user