diff --git a/app/plugin_key_value_store.go b/app/plugin_key_value_store.go index c86b3493cc..85a62b48c0 100644 --- a/app/plugin_key_value_store.go +++ b/app/plugin_key_value_store.go @@ -14,6 +14,14 @@ import ( "github.com/mattermost/mattermost-server/v6/store" ) +type kvStoreWrapper struct { + srv *Server +} + +func (k *kvStoreWrapper) SetPluginKeyWithOptions(pluginID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) { + return k.srv.setPluginKeyWithOptions(pluginID, key, value, options) +} + func getKeyHash(key string) string { hash := sha256.New() hash.Write([]byte(key)) diff --git a/app/server.go b/app/server.go index 9880959da3..39e490a209 100644 --- a/app/server.go +++ b/app/server.go @@ -101,6 +101,7 @@ const ( BotKey ServiceKey = "bot" LogKey ServiceKey = "log" HooksKey ServiceKey = "hooks" + KVStoreKey ServiceKey = "kvstore" ) type Server struct { @@ -369,10 +370,6 @@ func NewServer(options ...Option) (*Server, error) { } s.filestore = backend - channelWrapper := &channelsWrapper{ - srv: s, - } - s.licenseWrapper = &licenseWrapper{ srv: s, } @@ -381,14 +378,6 @@ func NewServer(options ...Option) (*Server, error) { srv: s, } - fileInfoWrapper := &fileInfoWrapper{ - srv: s, - } - - cloudWrapper := &cloudWrapper{ - cloud: s.Cloud, - } - s.teamService, err = teams.New(teams.ServiceConfig{ TeamStore: s.Store.Team(), ChannelStore: s.Store.Channel(), @@ -403,15 +392,16 @@ func NewServer(options ...Option) (*Server, error) { } serviceMap := map[ServiceKey]interface{}{ - ChannelKey: channelWrapper, + ChannelKey: &channelsWrapper{srv: s}, ConfigKey: s.configStore, LicenseKey: s.licenseWrapper, FilestoreKey: s.filestore, - FileInfoStoreKey: fileInfoWrapper, + FileInfoStoreKey: &fileInfoWrapper{srv: s}, ClusterKey: s.clusterWrapper, UserKey: New(ServerConnector(s.Channels())), LogKey: s.GetLogger(), - CloudKey: cloudWrapper, + CloudKey: &cloudWrapper{cloud: s.Cloud}, + KVStoreKey: &kvStoreWrapper{srv: s}, } // Step 8: Initialize products. diff --git a/product/api.go b/product/api.go index ab711edbae..c9ae90db34 100644 --- a/product/api.go +++ b/product/api.go @@ -11,6 +11,7 @@ import ( "github.com/mattermost/mattermost-server/v6/app/request" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/filestore" + "github.com/mattermost/mattermost-server/v6/shared/mlog" ) // RouterService enables registering the product router to the server. After registering the @@ -48,7 +49,6 @@ type PermissionService interface { type ClusterService interface { PublishPluginClusterEvent(productID string, ev model.PluginClusterEvent, opts model.PluginClusterEventSendOptions) error PublishWebSocketEvent(productID string, event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) - SetPluginKeyWithOptions(productID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) } // ChannelService provides channel related API The service implementation is provided by @@ -153,3 +153,17 @@ type FileInfoStoreService interface { type CloudService interface { GetCloudLimits() (*model.ProductLimits, error) } + +// KVStoreService is the API for accessing the KVStore service APIs. +// +// The service shall be registered via app.KVStoreKey service key. +type KVStoreService interface { + SetPluginKeyWithOptions(pluginID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) +} + +// LogService is the API for accessing the log service APIs. +// +// The service shall be registered via app.LogKey service key. +type LogService interface { + mlog.LoggerIFace +} diff --git a/shared/mlog/mlog.go b/shared/mlog/mlog.go index 368df6f53e..8618b28352 100644 --- a/shared/mlog/mlog.go +++ b/shared/mlog/mlog.go @@ -30,14 +30,18 @@ const ( type LoggerIFace interface { IsLevelEnabled(Level) bool + Trace(string, ...Field) Debug(string, ...Field) Info(string, ...Field) Warn(string, ...Field) Error(string, ...Field) Critical(string, ...Field) + Fatal(string, ...Field) Log(Level, string, ...Field) LogM([]Level, string, ...Field) With(fields ...Field) *Logger + Flush() error + StdLogger(level Level) *log.Logger } // Type and function aliases from Logr to limit the spread of dependencies.