Golint fix config (#13544)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
57167f4c72
Коммит
a4c4437681
@@ -39,4 +39,4 @@ issues:
|
|||||||
- linters:
|
- linters:
|
||||||
# ignore golint error for a lot of packages for now
|
# ignore golint error for a lot of packages for now
|
||||||
- golint
|
- golint
|
||||||
path: "api4|app|cmd|config|einterface|enterprise|imports|jobs|manualtesting|migrations|mlog|model|testlib|services|store|utils|web|wsapi|plugin/api.go|plugin/context.go|plugin/client.go|plugin/client_rpc.go|plugin/environment.go|plugin/health_check.go|plugin/hooks.go|plugin/supervisor.go|plugin/valid.go"
|
path: "api4|app|cmd|einterface|enterprise|imports|jobs|manualtesting|migrations|mlog|model|testlib|services|store|utils|web|wsapi|plugin/api.go|plugin/context.go|plugin/client.go|plugin/client_rpc.go|plugin/environment.go|plugin/health_check.go|plugin/hooks.go|plugin/supervisor.go|plugin/valid.go"
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GenerateClientConfig renders the given configuration for a client.
|
// GenerateClientConfig renders the given configuration for a client.
|
||||||
func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string {
|
func GenerateClientConfig(c *model.Config, diagnosticID string, license *model.License) map[string]string {
|
||||||
props := GenerateLimitedClientConfig(c, diagnosticId, license)
|
props := GenerateLimitedClientConfig(c, diagnosticID, license)
|
||||||
|
|
||||||
props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/")
|
props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/")
|
||||||
props["EnableUserDeactivation"] = strconv.FormatBool(*c.TeamSettings.EnableUserDeactivation)
|
props["EnableUserDeactivation"] = strconv.FormatBool(*c.TeamSettings.EnableUserDeactivation)
|
||||||
@@ -198,7 +198,7 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerateLimitedClientConfig renders the given configuration for an untrusted client.
|
// GenerateLimitedClientConfig renders the given configuration for an untrusted client.
|
||||||
func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *model.License) map[string]string {
|
func GenerateLimitedClientConfig(c *model.Config, diagnosticID string, license *model.License) map[string]string {
|
||||||
props := make(map[string]string)
|
props := make(map[string]string)
|
||||||
|
|
||||||
props["Version"] = model.CurrentVersion
|
props["Version"] = model.CurrentVersion
|
||||||
@@ -250,7 +250,7 @@ func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *
|
|||||||
props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink
|
props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink
|
||||||
props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink
|
props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink
|
||||||
|
|
||||||
props["DiagnosticId"] = diagnosticId
|
props["DiagnosticId"] = diagnosticID
|
||||||
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
||||||
|
|
||||||
props["HasImageProxy"] = strconv.FormatBool(*c.ImageProxySettings.Enable)
|
props["HasImageProxy"] = strconv.FormatBool(*c.ImageProxySettings.Enable)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestGetClientConfig(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
config *model.Config
|
config *model.Config
|
||||||
diagnosticId string
|
diagnosticID string
|
||||||
license *model.License
|
license *model.License
|
||||||
expectedFields map[string]string
|
expectedFields map[string]string
|
||||||
}{
|
}{
|
||||||
@@ -177,7 +177,7 @@ func TestGetClientConfig(t *testing.T) {
|
|||||||
testCase.license.Features.SetDefaults()
|
testCase.license.Features.SetDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
configMap := config.GenerateClientConfig(testCase.config, testCase.diagnosticId, testCase.license)
|
configMap := config.GenerateClientConfig(testCase.config, testCase.diagnosticID, testCase.license)
|
||||||
for expectedField, expectedValue := range testCase.expectedFields {
|
for expectedField, expectedValue := range testCase.expectedFields {
|
||||||
actualValue, ok := configMap[expectedField]
|
actualValue, ok := configMap[expectedField]
|
||||||
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
|
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
|
||||||
@@ -193,7 +193,7 @@ func TestGetLimitedClientConfig(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
config *model.Config
|
config *model.Config
|
||||||
diagnosticId string
|
diagnosticID string
|
||||||
license *model.License
|
license *model.License
|
||||||
expectedFields map[string]string
|
expectedFields map[string]string
|
||||||
}{
|
}{
|
||||||
@@ -235,7 +235,7 @@ func TestGetLimitedClientConfig(t *testing.T) {
|
|||||||
testCase.license.Features.SetDefaults()
|
testCase.license.Features.SetDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
configMap := config.GenerateLimitedClientConfig(testCase.config, testCase.diagnosticId, testCase.license)
|
configMap := config.GenerateLimitedClientConfig(testCase.config, testCase.diagnosticID, testCase.license)
|
||||||
for expectedField, expectedValue := range testCase.expectedFields {
|
for expectedField, expectedValue := range testCase.expectedFields {
|
||||||
actualValue, ok := configMap[expectedField]
|
actualValue, ok := configMap[expectedField]
|
||||||
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
|
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GenerateDefaultConfig writes default config to outputFile.
|
||||||
func GenerateDefaultConfig(outputFile *os.File) error {
|
func GenerateDefaultConfig(outputFile *os.File) error {
|
||||||
defaultCfg := &model.Config{}
|
defaultCfg := &model.Config{}
|
||||||
defaultCfg.SetDefaults()
|
defaultCfg.SetDefaults()
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func getActualDatabaseConfig(t *testing.T) (string, *model.Config) {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
var actual struct {
|
var actual struct {
|
||||||
Id string `db:"Id"`
|
ID string `db:"Id"`
|
||||||
Value []byte `db:"Value"`
|
Value []byte `db:"Value"`
|
||||||
}
|
}
|
||||||
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *mainHelper.GetSqlSettings().DriverName)
|
db := sqlx.NewDb(mainHelper.GetSqlSupplier().GetMaster().Db, *mainHelper.GetSqlSettings().DriverName)
|
||||||
@@ -71,7 +71,7 @@ func getActualDatabaseConfig(t *testing.T) (string, *model.Config) {
|
|||||||
actualCfg, _, err := config.UnmarshalConfig(bytes.NewReader(actual.Value), false)
|
actualCfg, _, err := config.UnmarshalConfig(bytes.NewReader(actual.Value), false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
return actual.Id, actualCfg
|
return actual.ID, actualCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertDatabaseEqualsConfig verifies the active in-database configuration equals the given config.
|
// assertDatabaseEqualsConfig verifies the active in-database configuration equals the given config.
|
||||||
@@ -399,12 +399,12 @@ func TestDatabaseStoreSet(t *testing.T) {
|
|||||||
_, err = ds.Set(ds.Get())
|
_, err = ds.Set(ds.Get())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
beforeId, _ := getActualDatabaseConfig(t)
|
beforeID, _ := getActualDatabaseConfig(t)
|
||||||
_, err = ds.Set(ds.Get())
|
_, err = ds.Set(ds.Get())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
afterId, _ := getActualDatabaseConfig(t)
|
afterID, _ := getActualDatabaseConfig(t)
|
||||||
assert.Equal(t, beforeId, afterId, "new record should not have been written")
|
assert.Equal(t, beforeID, afterID, "new record should not have been written")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("read-only ignored", func(t *testing.T) {
|
t.Run("read-only ignored", func(t *testing.T) {
|
||||||
@@ -489,7 +489,7 @@ func TestDatabaseStoreSet(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("listeners notified", func(t *testing.T) {
|
t.Run("listeners notified", func(t *testing.T) {
|
||||||
activeId, tearDown := setupConfigDatabase(t, emptyConfig, nil)
|
activeID, tearDown := setupConfigDatabase(t, emptyConfig, nil)
|
||||||
defer tearDown()
|
defer tearDown()
|
||||||
|
|
||||||
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
|
ds, err := config.NewDatabaseStore(fmt.Sprintf("%s://%s", *sqlSettings.DriverName, *sqlSettings.DataSource))
|
||||||
@@ -511,7 +511,7 @@ func TestDatabaseStoreSet(t *testing.T) {
|
|||||||
assert.Equal(t, oldCfg, retCfg)
|
assert.Equal(t, oldCfg, retCfg)
|
||||||
|
|
||||||
id, _ := getActualDatabaseConfig(t)
|
id, _ := getActualDatabaseConfig(t)
|
||||||
assert.NotEqual(t, activeId, id, "new record should have been written")
|
assert.NotEqual(t, activeID, id, "new record should have been written")
|
||||||
|
|
||||||
require.True(t, wasCalled(called, 5*time.Second), "callback should have been called when config written")
|
require.True(t, wasCalled(called, 5*time.Second), "callback should have been called when config written")
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrReadOnlyConfiguration is returned when an attempt to modify a read-only configuration is made.
|
||||||
ErrReadOnlyConfiguration = errors.New("configuration is read-only")
|
ErrReadOnlyConfiguration = errors.New("configuration is read-only")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// memoryStore implements the Store interface. It is meant primarily for testing.
|
// MemoryStore implements the Store interface. It is meant primarily for testing.
|
||||||
type memoryStore struct {
|
type MemoryStore struct {
|
||||||
commonStore
|
commonStore
|
||||||
|
|
||||||
allowEnvironmentOverrides bool
|
allowEnvironmentOverrides bool
|
||||||
@@ -31,13 +31,13 @@ type MemoryStoreOptions struct {
|
|||||||
InitialFiles map[string][]byte
|
InitialFiles map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMemoryStore creates a new memoryStore instance with default options.
|
// NewMemoryStore creates a new MemoryStore instance with default options.
|
||||||
func NewMemoryStore() (*memoryStore, error) {
|
func NewMemoryStore() (*MemoryStore, error) {
|
||||||
return NewMemoryStoreWithOptions(&MemoryStoreOptions{})
|
return NewMemoryStoreWithOptions(&MemoryStoreOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMemoryStoreWithOptions creates a new memoryStore instance.
|
// NewMemoryStoreWithOptions creates a new MemoryStore instance.
|
||||||
func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*memoryStore, error) {
|
func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*MemoryStore, error) {
|
||||||
savedConfig := options.InitialConfig
|
savedConfig := options.InitialConfig
|
||||||
if savedConfig == nil {
|
if savedConfig == nil {
|
||||||
savedConfig = &model.Config{}
|
savedConfig = &model.Config{}
|
||||||
@@ -49,7 +49,7 @@ func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*memoryStore, error
|
|||||||
initialFiles = make(map[string][]byte)
|
initialFiles = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
ms := &memoryStore{
|
ms := &MemoryStore{
|
||||||
allowEnvironmentOverrides: !options.IgnoreEnvironmentOverrides,
|
allowEnvironmentOverrides: !options.IgnoreEnvironmentOverrides,
|
||||||
validate: !options.SkipValidation,
|
validate: !options.SkipValidation,
|
||||||
files: initialFiles,
|
files: initialFiles,
|
||||||
@@ -67,7 +67,7 @@ func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*memoryStore, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set replaces the current configuration in its entirety.
|
// Set replaces the current configuration in its entirety.
|
||||||
func (ms *memoryStore) Set(newCfg *model.Config) (*model.Config, error) {
|
func (ms *MemoryStore) Set(newCfg *model.Config) (*model.Config, error) {
|
||||||
validate := ms.commonStore.validate
|
validate := ms.commonStore.validate
|
||||||
if !ms.validate {
|
if !ms.validate {
|
||||||
validate = nil
|
validate = nil
|
||||||
@@ -77,14 +77,14 @@ func (ms *memoryStore) Set(newCfg *model.Config) (*model.Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// persist copies the active config to the saved config.
|
// persist copies the active config to the saved config.
|
||||||
func (ms *memoryStore) persist(cfg *model.Config) error {
|
func (ms *MemoryStore) persist(cfg *model.Config) error {
|
||||||
ms.savedConfig = cfg.Clone()
|
ms.savedConfig = cfg.Clone()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load applies environment overrides to the default config as if a re-load had occurred.
|
// Load applies environment overrides to the default config as if a re-load had occurred.
|
||||||
func (ms *memoryStore) Load() (err error) {
|
func (ms *MemoryStore) Load() (err error) {
|
||||||
var cfgBytes []byte
|
var cfgBytes []byte
|
||||||
cfgBytes, err = marshalConfig(ms.savedConfig)
|
cfgBytes, err = marshalConfig(ms.savedConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -102,7 +102,7 @@ func (ms *memoryStore) Load() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetFile fetches the contents of a previously persisted configuration file.
|
// GetFile fetches the contents of a previously persisted configuration file.
|
||||||
func (ms *memoryStore) GetFile(name string) ([]byte, error) {
|
func (ms *MemoryStore) GetFile(name string) ([]byte, error) {
|
||||||
ms.configLock.RLock()
|
ms.configLock.RLock()
|
||||||
defer ms.configLock.RUnlock()
|
defer ms.configLock.RUnlock()
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ func (ms *memoryStore) GetFile(name string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetFile sets or replaces the contents of a configuration file.
|
// SetFile sets or replaces the contents of a configuration file.
|
||||||
func (ms *memoryStore) SetFile(name string, data []byte) error {
|
func (ms *MemoryStore) SetFile(name string, data []byte) error {
|
||||||
ms.configLock.Lock()
|
ms.configLock.Lock()
|
||||||
defer ms.configLock.Unlock()
|
defer ms.configLock.Unlock()
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ func (ms *memoryStore) SetFile(name string, data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasFile returns true if the given file was previously persisted.
|
// HasFile returns true if the given file was previously persisted.
|
||||||
func (ms *memoryStore) HasFile(name string) (bool, error) {
|
func (ms *MemoryStore) HasFile(name string) (bool, error) {
|
||||||
ms.configLock.RLock()
|
ms.configLock.RLock()
|
||||||
defer ms.configLock.RUnlock()
|
defer ms.configLock.RUnlock()
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ func (ms *memoryStore) HasFile(name string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveFile removes a previously persisted configuration file.
|
// RemoveFile removes a previously persisted configuration file.
|
||||||
func (ms *memoryStore) RemoveFile(name string) error {
|
func (ms *MemoryStore) RemoveFile(name string) error {
|
||||||
ms.configLock.Lock()
|
ms.configLock.Lock()
|
||||||
defer ms.configLock.Unlock()
|
defer ms.configLock.Unlock()
|
||||||
|
|
||||||
@@ -144,11 +144,11 @@ func (ms *memoryStore) RemoveFile(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns a hard-coded description, as there is no backing store.
|
// String returns a hard-coded description, as there is no backing store.
|
||||||
func (ms *memoryStore) String() string {
|
func (ms *MemoryStore) String() string {
|
||||||
return "memory://"
|
return "memory://"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close does nothing for a memory store.
|
// Close does nothing for a memory store.
|
||||||
func (ms *memoryStore) Close() error {
|
func (ms *MemoryStore) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package config
|
|||||||
|
|
||||||
import "github.com/pkg/errors"
|
import "github.com/pkg/errors"
|
||||||
|
|
||||||
|
// Migrate migrates SAML keys and certificates from one store to another given their data source names.
|
||||||
func Migrate(from, to string) error {
|
func Migrate(from, to string) error {
|
||||||
source, err := NewStore(from, false)
|
source, err := NewStore(from, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ func TestDesanitize(t *testing.T) {
|
|||||||
target.SqlSettings.DataSourceReplicas = append(target.SqlSettings.DataSourceReplicas, "old_replica0")
|
target.SqlSettings.DataSourceReplicas = append(target.SqlSettings.DataSourceReplicas, "old_replica0")
|
||||||
target.SqlSettings.DataSourceSearchReplicas = append(target.SqlSettings.DataSourceReplicas, "old_search_replica0")
|
target.SqlSettings.DataSourceSearchReplicas = append(target.SqlSettings.DataSourceReplicas, "old_search_replica0")
|
||||||
|
|
||||||
actual_clone := actual.Clone()
|
actualClone := actual.Clone()
|
||||||
desanitize(actual, target)
|
desanitize(actual, target)
|
||||||
assert.Equal(t, actual_clone, actual, "actual should not have been changed")
|
assert.Equal(t, actualClone, actual, "actual should not have been changed")
|
||||||
|
|
||||||
// Verify the settings that should have been left untouched in target
|
// Verify the settings that should have been left untouched in target
|
||||||
assert.True(t, *target.LdapSettings.Enable, "LdapSettings.Enable should not have changed")
|
assert.True(t, *target.LdapSettings.Enable, "LdapSettings.Enable should not have changed")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user