config

package
v5.33.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: AGPL-3.0, Apache-2.0 Imports: 24 Imported by: 0

README

config.json

This is the system configuration file for your Mattermost server. Settings are specific to different editions of Mattermost. Please read the documentation before making changes: https://about.mattermost.com/default-config-docs/

Documentation

Index

Constants

View Source
const MaxWriteLength = 4 * 1024 * 1024

MaxWriteLength defines the maximum length accepted for write to the Configurations or ConfigurationFiles table.

It is imposed by MySQL's default max_allowed_packet value of 4Mb.

Variables

View Source
var (
	// ErrReadOnlyConfiguration is returned when an attempt to modify a read-only configuration is made.
	ErrReadOnlyConfiguration = errors.New("configuration is read-only")
)
View Source
var (
	// ErrReadOnlyStore is returned when an attempt to modify a read-only
	// configuration store is made.
	ErrReadOnlyStore = errors.New("configuration store is read-only")
)

Functions

func FixInvalidLocales

func FixInvalidLocales(cfg *model.Config) bool

FixInvalidLocales checks and corrects the given config for invalid locale-related settings.

Ideally, this function would be completely internal, but it's currently exposed to allow the cli to test the config change before allowing the save.

func GenerateClientConfig

func GenerateClientConfig(c *model.Config, telemetryID string, license *model.License) map[string]string

GenerateClientConfig renders the given configuration for a client.

func GenerateLimitedClientConfig

func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *model.License) map[string]string

GenerateLimitedClientConfig renders the given configuration for an untrusted client.

func GetEnvironment

func GetEnvironment() map[string]string

func GetValueByPath

func GetValueByPath(path []string, obj interface{}) (interface{}, bool)

func IsDatabaseDSN

func IsDatabaseDSN(dsn string) bool

func IsJsonMap

func IsJsonMap(data string) bool

func JSONToLogTargetCfg

func JSONToLogTargetCfg(data []byte) (mlog.LogTargetCfg, error)

func Merge

func Merge(cfg *model.Config, patch *model.Config, mergeConfig *utils.MergeConfig) (*model.Config, error)

Merge merges two configs together. The receiver's values are overwritten with the patch's values except when the patch's values are nil.

func Migrate

func Migrate(from, to string) error

Migrate migrates SAML keys, certificates, and other config files from one store to another given their data source names.

Types

type BackingStore

type BackingStore interface {
	// Set replaces the current configuration in its entirety and updates the backing store.
	Set(*model.Config) error

	// Load retrieves the configuration stored. If there is no configuration stored
	// the io.ReadCloser will be nil
	Load() ([]byte, error)

	// GetFile fetches the contents of a previously persisted configuration file.
	// If no such file exists, an empty byte array will be returned without error.
	GetFile(name string) ([]byte, error)

	// SetFile sets or replaces the contents of a configuration file.
	SetFile(name string, data []byte) error

	// HasFile returns true if the given file was previously persisted.
	HasFile(name string) (bool, error)

	// RemoveFile removes a previously persisted configuration file.
	RemoveFile(name string) error

	// String describes the backing store for the config.
	String() string

	Watch(callback func()) error

	// Close cleans up resources associated with the store.
	Close() error
}

type DatabaseStore

type DatabaseStore struct {
	// contains filtered or unexported fields
}

DatabaseStore is a config store backed by a database. Not to be used directly. Only to be used as a backing store for config.Store

func NewDatabaseStore

func NewDatabaseStore(dsn string) (ds *DatabaseStore, err error)

NewDatabaseStore creates a new instance of a config store backed by the given database.

func (*DatabaseStore) Close

func (ds *DatabaseStore) Close() error

Close cleans up resources associated with the store.

func (*DatabaseStore) GetFile

func (ds *DatabaseStore) GetFile(name string) ([]byte, error)

GetFile fetches the contents of a previously persisted configuration file.

func (*DatabaseStore) HasFile

func (ds *DatabaseStore) HasFile(name string) (bool, error)

HasFile returns true if the given file was previously persisted.

func (*DatabaseStore) Load

func (ds *DatabaseStore) Load() ([]byte, error)

Load updates the current configuration from the backing store.

func (*DatabaseStore) RemoveFile

func (ds *DatabaseStore) RemoveFile(name string) error

RemoveFile remoevs a previously persisted configuration file.

func (*DatabaseStore) Set

func (ds *DatabaseStore) Set(newCfg *model.Config) error

Set replaces the current configuration in its entirety and updates the backing store.

func (*DatabaseStore) SetFile

func (ds *DatabaseStore) SetFile(name string, data []byte) error

SetFile sets or replaces the contents of a configuration file.

func (*DatabaseStore) String

func (ds *DatabaseStore) String() string

String returns the path to the database backing the config, masking the password.

func (*DatabaseStore) Watch

func (ds *DatabaseStore) Watch(_ func()) error

Watch nothing on memory store

type FeatureFlagSyncParams

type FeatureFlagSyncParams struct {
	ServerID            string
	SplitKey            string
	SyncIntervalSeconds int
	Log                 *mlog.Logger
}

type FeatureFlagSynchronizer

type FeatureFlagSynchronizer struct {
	FeatureFlagSyncParams
	// contains filtered or unexported fields
}

func NewFeatureFlagSynchronizer

func NewFeatureFlagSynchronizer(params FeatureFlagSyncParams) (*FeatureFlagSynchronizer, error)

func (*FeatureFlagSynchronizer) Close

func (f *FeatureFlagSynchronizer) Close()

func (*FeatureFlagSynchronizer) EnsureReady

func (f *FeatureFlagSynchronizer) EnsureReady() error

ensureReady blocks until the syncronizer is ready to update feature flag values

func (*FeatureFlagSynchronizer) UpdateFeatureFlagValues

func (f *FeatureFlagSynchronizer) UpdateFeatureFlagValues(base model.FeatureFlags) model.FeatureFlags

type FileGetter

type FileGetter interface {
	GetFile(name string) ([]byte, error)
}

type FileStore

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore is a config store backed by a file such as config/config.json.

It also uses the folder containing the configuration file for storing other configuration files. Not to be used directly. Only to be used as a backing store for config.Store

func NewFileStore

func NewFileStore(path string, watch bool) (fs *FileStore, err error)

NewFileStore creates a new instance of a config store backed by the given file path.

If watch is true, any external changes to the file will force a reload.

func (*FileStore) Close

func (fs *FileStore) Close() error

Close cleans up resources associated with the store.

func (*FileStore) GetFile

func (fs *FileStore) GetFile(name string) ([]byte, error)

GetFile fetches the contents of a previously persisted configuration file.

func (*FileStore) GetFilePath

func (fs *FileStore) GetFilePath(name string) string

GetFilePath returns the resolved path of a configuration file. The file may not necessarily exist.

func (*FileStore) HasFile

func (fs *FileStore) HasFile(name string) (bool, error)

HasFile returns true if the given file was previously persisted.

func (*FileStore) Load

func (fs *FileStore) Load() ([]byte, error)

Load updates the current configuration from the backing store.

func (*FileStore) RemoveFile

func (fs *FileStore) RemoveFile(name string) error

RemoveFile removes a previously persisted configuration file.

func (*FileStore) Set

func (fs *FileStore) Set(newCfg *model.Config) error

Set replaces the current configuration in its entirety and updates the backing store.

func (*FileStore) SetFile

func (fs *FileStore) SetFile(name string, data []byte) error

SetFile sets or replaces the contents of a configuration file.

func (*FileStore) String

func (fs *FileStore) String() string

String returns the path to the file backing the config.

func (*FileStore) Watch

func (fs *FileStore) Watch(callback func()) error

type Listener

type Listener func(oldConfig *model.Config, newConfig *model.Config)

Listener is a callback function invoked when the configuration changes.

type LogConfigSrc

type LogConfigSrc interface {
	// Get fetches the current, cached configuration.
	Get() mlog.LogTargetCfg

	// Set updates the dsn specifying the source and reloads
	Set(dsn string, fget FileGetter) (err error)

	// AddListener adds a callback function to invoke when the configuration is modified.
	AddListener(listener LogSrcListener) string

	// RemoveListener removes a callback function using an id returned from AddListener.
	RemoveListener(id string)

	// Close cleans up resources.
	Close() error
}

LogConfigSrc abstracts the Advanced Logging configuration so that implementations can fetch from file, database, etc.

func NewLogConfigSrc

func NewLogConfigSrc(dsn string, isJSON bool, fget FileGetter) (LogConfigSrc, error)

NewLogConfigSrc creates an advanced logging configuration source, backed by a file, JSON string, or database.

type LogSrcListener

type LogSrcListener func(old, new mlog.LogTargetCfg)

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore implements the Store interface. It is meant primarily for testing. Not to be used directly. Only to be used as a backing store for config.Store

func NewMemoryStore

func NewMemoryStore() (*MemoryStore, error)

NewMemoryStore creates a new MemoryStore instance with default options.

func NewMemoryStoreWithOptions

func NewMemoryStoreWithOptions(options *MemoryStoreOptions) (*MemoryStore, error)

NewMemoryStoreWithOptions creates a new MemoryStore instance.

func (*MemoryStore) Close

func (ms *MemoryStore) Close() error

Close does nothing for a memory store.

func (*MemoryStore) GetFile

func (ms *MemoryStore) GetFile(name string) ([]byte, error)

GetFile fetches the contents of a previously persisted configuration file.

func (*MemoryStore) HasFile

func (ms *MemoryStore) HasFile(name string) (bool, error)

HasFile returns true if the given file was previously persisted.

func (*MemoryStore) Load

func (ms *MemoryStore) Load() ([]byte, error)

Load applies environment overrides to the default config as if a re-load had occurred.

func (*MemoryStore) RemoveFile

func (ms *MemoryStore) RemoveFile(name string) error

RemoveFile removes a previously persisted configuration file.

func (*MemoryStore) Set

func (ms *MemoryStore) Set(newCfg *model.Config) error

Set replaces the current configuration in its entirety.

func (*MemoryStore) SetFile

func (ms *MemoryStore) SetFile(name string, data []byte) error

SetFile sets or replaces the contents of a configuration file.

func (*MemoryStore) String

func (ms *MemoryStore) String() string

String returns a hard-coded description, as there is no backing store.

func (*MemoryStore) Watch

func (ms *MemoryStore) Watch(_ func()) error

Watch nothing on memory store

type MemoryStoreOptions

type MemoryStoreOptions struct {
	IgnoreEnvironmentOverrides bool
	SkipValidation             bool
	InitialConfig              *model.Config
	InitialFiles               map[string][]byte
}

MemoryStoreOptions makes configuration of the memory store explicit.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(dsn string, watch, readOnly bool, customDefaults *model.Config) (*Store, error)

NewStore creates a database or file store given a data source name by which to connect.

func NewStoreFromBacking

func NewStoreFromBacking(backingStore BackingStore, customDefaults *model.Config, readOnly bool) (*Store, error)

func NewTestMemoryStore

func NewTestMemoryStore() *Store

func (*Store) AddListener

func (e *Store) AddListener(listener Listener) string

AddListener adds a callback function to invoke when the configuration is modified.

func (*Store) Close

func (s *Store) Close() error

Close cleans up resources associated with the store.

func (*Store) Get

func (s *Store) Get() *model.Config

Get fetches the current, cached configuration.

func (*Store) GetEnvironmentOverrides

func (s *Store) GetEnvironmentOverrides() map[string]interface{}

GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.

func (*Store) GetFile

func (s *Store) GetFile(name string) ([]byte, error)

GetFile fetches the contents of a previously persisted configuration file. If no such file exists, an empty byte array will be returned without error.

func (*Store) GetNoEnv

func (s *Store) GetNoEnv() *model.Config

Get fetches the current, cached configuration without environment variable overrides.

func (*Store) HasFile

func (s *Store) HasFile(name string) (bool, error)

HasFile returns true if the given file was previously persisted.

func (*Store) IsReadOnly

func (s *Store) IsReadOnly() bool

IsReadOnly returns whether or not the store is read-only.

func (*Store) Load

func (s *Store) Load() error

Load updates the current configuration from the backing store, possibly initializing.

func (*Store) PersistFeatures

func (s *Store) PersistFeatures(persist bool)

PersistFeatures sets if the store should persist feature flags.

func (*Store) RemoveEnvironmentOverrides

func (s *Store) RemoveEnvironmentOverrides(cfg *model.Config) *model.Config

RemoveEnvironmentOverrides returns a new config without the environment overrides

func (*Store) RemoveFile

func (s *Store) RemoveFile(name string) error

RemoveFile removes a previously persisted configuration file.

func (*Store) RemoveListener

func (e *Store) RemoveListener(id string)

RemoveListener removes a callback function using an id returned from AddListener.

func (*Store) Set

func (s *Store) Set(newCfg *model.Config) (*model.Config, error)

Set replaces the current configuration in its entirety and updates the backing store.

func (*Store) SetFile

func (s *Store) SetFile(name string, data []byte) error

SetFile sets or replaces the contents of a configuration file.

func (*Store) String

func (s *Store) String() string

String describes the backing store for the config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL