Documentation ¶
Index ¶
- Constants
- Variables
- func FixInvalidLocales(cfg *model.Config) bool
- func GenerateClientConfig(c *model.Config, telemetryID string, license *model.License) map[string]string
- func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *model.License) map[string]string
- func GetEnvironment() map[string]string
- func GetLogFileLocation(fileLocation string) string
- func GetLogSettingsFromNotificationsLogSettings(notificationLogSettings *model.NotificationLogSettings) *model.LogSettings
- func GetNotificationsLogFileLocation(fileLocation string) string
- func GetValueByPath(path []string, obj interface{}) (interface{}, bool)
- func IsDatabaseDSN(dsn string) bool
- func Merge(cfg *model.Config, patch *model.Config, mergeConfig *utils.MergeConfig) (*model.Config, error)
- func Migrate(from, to string) error
- func MloggerConfigFromAuditConfig(auditSettings model.ExperimentalAuditSettings, configSrc LogConfigSrc) (mlog.LoggerConfiguration, error)
- func MloggerConfigFromLoggerConfig(s *model.LogSettings, configSrc LogConfigSrc, getFileFunc fileLocationFunc) (mlog.LoggerConfiguration, error)
- type BackingStore
- type ConfigDiff
- type ConfigDiffs
- type DatabaseStore
- func (ds *DatabaseStore) Close() error
- func (ds *DatabaseStore) GetFile(name string) ([]byte, error)
- func (ds *DatabaseStore) HasFile(name string) (bool, error)
- func (ds *DatabaseStore) Load() ([]byte, error)
- func (ds *DatabaseStore) RemoveFile(name string) error
- func (ds *DatabaseStore) Set(newCfg *model.Config) error
- func (ds *DatabaseStore) SetFile(name string, data []byte) error
- func (ds *DatabaseStore) String() string
- type FileStore
- func (fs *FileStore) Close() error
- func (fs *FileStore) GetFile(name string) ([]byte, error)
- func (fs *FileStore) GetFilePath(name string) string
- func (fs *FileStore) HasFile(name string) (bool, error)
- func (fs *FileStore) Load() ([]byte, error)
- func (fs *FileStore) RemoveFile(name string) error
- func (fs *FileStore) Set(newCfg *model.Config) error
- func (fs *FileStore) SetFile(name string, data []byte) error
- func (fs *FileStore) String() string
- type Listener
- type LogConfigSrc
- type LogSrcListener
- type MemoryStore
- func (ms *MemoryStore) Close() error
- func (ms *MemoryStore) GetFile(name string) ([]byte, error)
- func (ms *MemoryStore) HasFile(name string) (bool, error)
- func (ms *MemoryStore) Load() ([]byte, error)
- func (ms *MemoryStore) RemoveFile(name string) error
- func (ms *MemoryStore) Set(newCfg *model.Config) error
- func (ms *MemoryStore) SetFile(name string, data []byte) error
- func (ms *MemoryStore) String() string
- type MemoryStoreOptions
- type Store
- func (e *Store) AddListener(listener Listener) string
- func (s *Store) CleanUp() error
- func (s *Store) Close() error
- func (s *Store) Get() *model.Config
- func (s *Store) GetEnvironmentOverrides() map[string]interface{}
- func (s *Store) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]interface{}
- func (s *Store) GetFile(name string) ([]byte, error)
- func (s *Store) GetNoEnv() *model.Config
- func (s *Store) HasFile(name string) (bool, error)
- func (s *Store) IsReadOnly() bool
- func (s *Store) Load() error
- func (s *Store) RemoveEnvironmentOverrides(cfg *model.Config) *model.Config
- func (s *Store) RemoveFile(name string) error
- func (e *Store) RemoveListener(id string)
- func (s *Store) Set(newCfg *model.Config) (*model.Config, *model.Config, error)
- func (s *Store) SetFile(name string, data []byte) error
- func (s *Store) SetReadOnlyFF(readOnly bool)
- func (s *Store) String() string
Constants ¶
const ( LogRotateSizeMB = 100 LogCompress = true LogRotateMaxAge = 0 LogRotateMaxBackups = 0 LogFilename = "mattermost.log" LogNotificationFilename = "notifications.log" LogMinLevelLen = 5 LogMinMsgLen = 45 LogDelim = " " LogEnableCaller = true )
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 ¶
var ( // ErrReadOnlyConfiguration is returned when an attempt to modify a read-only configuration is made. ErrReadOnlyConfiguration = errors.New("configuration is read-only") )
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 ¶
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 GetLogFileLocation ¶
func GetLogSettingsFromNotificationsLogSettings ¶
func GetLogSettingsFromNotificationsLogSettings(notificationLogSettings *model.NotificationLogSettings) *model.LogSettings
func GetValueByPath ¶
func IsDatabaseDSN ¶
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 ¶
Migrate migrates SAML keys, certificates, and other config files from one store to another given their data source names.
func MloggerConfigFromAuditConfig ¶
func MloggerConfigFromAuditConfig(auditSettings model.ExperimentalAuditSettings, configSrc LogConfigSrc) (mlog.LoggerConfiguration, error)
func MloggerConfigFromLoggerConfig ¶
func MloggerConfigFromLoggerConfig(s *model.LogSettings, configSrc LogConfigSrc, getFileFunc fileLocationFunc) (mlog.LoggerConfiguration, error)
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 // Close cleans up resources associated with the store. Close() error }
BackingStore defines the behaviour exposed by the underlying store implementation (e.g. file, database).
type ConfigDiff ¶
type ConfigDiff struct { Path string `json:"path"` BaseVal interface{} `json:"base_val"` ActualVal interface{} `json:"actual_val"` }
type ConfigDiffs ¶
type ConfigDiffs []ConfigDiff
func (ConfigDiffs) Sanitize ¶
func (cd ConfigDiffs) Sanitize() ConfigDiffs
Sanitize replaces sensitive config values in the diff with asterisks filled strings.
func (ConfigDiffs) String ¶
func (cd ConfigDiffs) String() string
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.
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 ¶
NewFileStore creates a new instance of a config store backed by the given file path.
func (*FileStore) GetFile ¶
GetFile fetches the contents of a previously persisted configuration file.
func (*FileStore) GetFilePath ¶
GetFilePath returns the resolved path of a configuration file. The file may not necessarily exist.
func (*FileStore) RemoveFile ¶
RemoveFile removes a previously persisted configuration file.
func (*FileStore) Set ¶
Set replaces the current configuration in its entirety and updates the backing store.
type LogConfigSrc ¶
type LogConfigSrc interface { // Get fetches the current, cached configuration. Get() mlog.LoggerConfiguration // Set updates the dsn specifying the source and reloads Set(dsn string, configStore *Store) (err error) // 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, configStore *Store) (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.LoggerConfiguration)
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.
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
}
Store is the higher level object that handles storing and retrieval of config data. To do so it relies on a variety of backing stores (e.g. file, database, memory).
func NewStoreFromBacking ¶
func NewStoreFromBacking(backingStore BackingStore, customDefaults *model.Config, readOnly bool) (*Store, error)
NewStoreFromBacking creates and returns a new config store given a backing store.
func NewStoreFromDSN ¶
func NewStoreFromDSN(dsn string, readOnly bool, customDefaults *model.Config, createFileIfNotExist bool) (*Store, error)
NewStoreFromDSN creates and returns a new config store backed by either a database or file store depending on the value of the given data source name string.
func NewTestMemoryStore ¶
func NewTestMemoryStore() *Store
NewTestMemoryStore returns a new config store backed by a memory store to be used for testing purposes.
func (*Store) AddListener ¶
AddListener adds a callback function to invoke when the configuration is modified.
func (*Store) CleanUp ¶
Cleanup removes outdated configurations from the database. this is a no-op function for FileStore type backing store.
func (*Store) GetEnvironmentOverrides ¶
GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.
func (*Store) GetEnvironmentOverridesWithFilter ¶
func (s *Store) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]interface{}
GetEnvironmentOverridesWithFilter fetches the configuration fields overridden by environment variables. If filter is not nil and returns false for a struct field, that field will be omitted.
func (*Store) GetFile ¶
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 ¶
GetNoEnv fetches the current cached configuration without environment variable overrides.
func (*Store) IsReadOnly ¶
IsReadOnly returns whether or not the store is read-only.
func (*Store) Load ¶
Load updates the current configuration from the backing store, possibly initializing.
func (*Store) RemoveEnvironmentOverrides ¶
RemoveEnvironmentOverrides returns a new config without the environment overrides.
func (*Store) RemoveFile ¶
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 ¶
Set replaces the current configuration in its entirety and updates the backing store. It returns both old and new versions of the config.
func (*Store) SetReadOnlyFF ¶
SetReadOnlyFF sets whether feature flags should be written out to config or treated as read-only.