config

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	// BotUserID used to post messages.
	BotUserID string
}

Configuration captures the plugin's external configuration as exposed in the Mattermost server configuration, as well as values computed from the configuration. Any public fields will be deserialized from the Mattermost server configuration in OnConfigurationChange.

As plugins are inherently concurrent (hooks being called asynchronously), and the plugin configuration can change at any time, access to the configuration must be synchronized. The strategy used in this plugin is to guard a pointer to the configuration, and clone the entire struct whenever it changes. You may replace this with whatever strategy you choose.

If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep copy appropriate for your types.

func (*Configuration) Clone

func (c *Configuration) Clone() *Configuration

Clone shallow copies the configuration. Your implementation may require a deep copy if your configuration has reference types.

type Service

type Service interface {
	// GetConfiguration retrieves the active configuration under lock, making it safe to use
	// concurrently. The active configuration may change underneath the client of this method, but
	// the struct returned by this API call is considered immutable.
	GetConfiguration() *Configuration

	// UpdateConfiguration updates the config. Any parts of the config that are persisted in the plugin's
	// section in the server's config will be saved to the server.
	UpdateConfiguration(f func(*Configuration)) error

	// RegisterConfigChangeListener registers a function that will called when the config might have
	// been changed. Returns an id which can be used to unregister the listener.
	RegisterConfigChangeListener(listener func()) string

	// UnregisterConfigChangeListener unregisters the listener function identified by id.
	UnregisterConfigChangeListener(id string)

	// GetManifest gets the plugin manifest.
	GetManifest() *model.Manifest

	// IsConfiguredForDevelopmentAndTesting returns true when the server has `EnableDeveloper` and
	// `EnableTesting` configuration settings enabled.
	IsConfiguredForDevelopmentAndTesting() bool

	// IsCloud returns true when the server has a Cloud license.
	IsCloud() bool

	// SupportsGivingFeedback returns nil when the nps plugin is installed and enabled, thus enabling giving feedback.
	SupportsGivingFeedback() error
}

Service is the config.Service interface. NOTE: for now we are defining this here for simplicity. It will be mocked by multiple consumers, so keep the definition in one place -- here. In the future we may move to a consumer-defines-the-interface style (and mocks it themselves), but since this is used internally, at this point the trade-off is not worth it.

type ServiceImpl

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

ServiceImpl holds access to the plugin's Configuration.

func NewConfigService

func NewConfigService(api *pluginapi.Client, manifest *model.Manifest) *ServiceImpl

NewConfigService Creates a new ServiceImpl struct.

func (*ServiceImpl) GetConfiguration

func (c *ServiceImpl) GetConfiguration() *Configuration

GetConfiguration retrieves the active configuration under lock, making it safe to use concurrently. The active configuration may change underneath the client of this method, but the struct returned by this API call is considered immutable.

func (*ServiceImpl) GetManifest

func (c *ServiceImpl) GetManifest() *model.Manifest

GetManifest gets the plugin manifest.

func (*ServiceImpl) IsCloud

func (c *ServiceImpl) IsCloud() bool

IsCloud returns true when the server is on cloud, and false otherwise

func (*ServiceImpl) IsConfiguredForDevelopmentAndTesting

func (c *ServiceImpl) IsConfiguredForDevelopmentAndTesting() bool

IsConfiguredForDevelopmentAndTesting returns true when the server has `EnableDeveloper` and `EnableTesting` configuration settings enabled.

func (*ServiceImpl) OnConfigurationChange

func (c *ServiceImpl) OnConfigurationChange() error

OnConfigurationChange is invoked when configuration changes may have been made. This method satisfies the interface expected by the server. Embed config.Config in the plugin.

func (*ServiceImpl) RegisterConfigChangeListener

func (c *ServiceImpl) RegisterConfigChangeListener(listener func()) string

RegisterConfigChangeListener registers a function that will called when the config might have been changed. Returns an id which can be used to unregister the listener.

func (*ServiceImpl) SupportsGivingFeedback

func (c *ServiceImpl) SupportsGivingFeedback() error

SupportsGivingFeedback returns nil when the nps plugin is installed and enabled, thus enabling giving feedback.

func (*ServiceImpl) UnregisterConfigChangeListener

func (c *ServiceImpl) UnregisterConfigChangeListener(id string)

UnregisterConfigChangeListener unregisters the listener function identified by id.

func (*ServiceImpl) UpdateConfiguration

func (c *ServiceImpl) UpdateConfiguration(f func(*Configuration)) error

UpdateConfiguration updates the config. Any parts of the config that are persisted in the plugin's section in the server's config will be saved to the server.

Jump to

Keyboard shortcuts

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