move file backend to the platform service (#21365)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b30e511ffe
Коммит
2ce3e81490
@@ -1440,20 +1440,19 @@ func TestPushNotificationRace(t *testing.T) {
|
|||||||
Return(&model.Preference{Value: "test"}, nil)
|
Return(&model.Preference{Value: "test"}, nil)
|
||||||
mockStore.On("Preference").Return(&mockPreferenceStore)
|
mockStore.On("Preference").Return(&mockPreferenceStore)
|
||||||
s := &Server{
|
s := &Server{
|
||||||
products: make(map[string]Product),
|
products: make(map[string]Product),
|
||||||
Router: mux.NewRouter(),
|
Router: mux.NewRouter(),
|
||||||
filestore: &fmocks.FileBackend{},
|
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
s.platform, err = platform.New(platform.ServiceConfig{
|
s.platform, err = platform.New(platform.ServiceConfig{
|
||||||
ConfigStore: memoryStore,
|
ConfigStore: memoryStore,
|
||||||
})
|
}, platform.SetFileStore(&fmocks.FileBackend{}))
|
||||||
s.SetStore(mockStore)
|
s.SetStore(mockStore)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
serviceMap := map[ServiceKey]any{
|
serviceMap := map[ServiceKey]any{
|
||||||
ConfigKey: s.platform,
|
ConfigKey: s.platform,
|
||||||
LicenseKey: &licenseWrapper{s},
|
LicenseKey: &licenseWrapper{s},
|
||||||
FilestoreKey: s.filestore,
|
FilestoreKey: s.FileBackend(),
|
||||||
}
|
}
|
||||||
ch, err := NewChannels(s, serviceMap)
|
ch, err := NewChannels(s, serviceMap)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func ConfigStore(configStore *config.Store) Option {
|
|||||||
|
|
||||||
func SetFileStore(filestore filestore.FileBackend) Option {
|
func SetFileStore(filestore filestore.FileBackend) Option {
|
||||||
return func(s *Server) error {
|
return func(s *Server) error {
|
||||||
s.filestore = filestore
|
s.platformOptions = append(s.platformOptions, platform.SetFileStore(filestore))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/config"
|
"github.com/mattermost/mattermost-server/v6/config"
|
||||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/shared/filestore"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v6/store"
|
"github.com/mattermost/mattermost-server/v6/store"
|
||||||
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
||||||
@@ -74,6 +75,13 @@ func Config(dsn string, readOnly bool, configDefaults *model.Config) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetFileStore(filestore filestore.FileBackend) Option {
|
||||||
|
return func(ps *PlatformService) error {
|
||||||
|
ps.filestore = filestore
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ConfigStore applies the given config store, typically to replace the traditional sources with a memory store for testing.
|
// ConfigStore applies the given config store, typically to replace the traditional sources with a memory store for testing.
|
||||||
func ConfigStore(configStore *config.Store) Option {
|
func ConfigStore(configStore *config.Store) Option {
|
||||||
return func(ps *PlatformService) error {
|
return func(ps *PlatformService) error {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/services/cache"
|
"github.com/mattermost/mattermost-server/v6/services/cache"
|
||||||
"github.com/mattermost/mattermost-server/v6/services/searchengine"
|
"github.com/mattermost/mattermost-server/v6/services/searchengine"
|
||||||
"github.com/mattermost/mattermost-server/v6/services/searchengine/bleveengine"
|
"github.com/mattermost/mattermost-server/v6/services/searchengine/bleveengine"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/shared/filestore"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v6/store"
|
"github.com/mattermost/mattermost-server/v6/store"
|
||||||
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
||||||
@@ -41,6 +42,8 @@ type PlatformService struct {
|
|||||||
|
|
||||||
configStore *config.Store
|
configStore *config.Store
|
||||||
|
|
||||||
|
filestore filestore.FileBackend
|
||||||
|
|
||||||
cacheProvider cache.Provider
|
cacheProvider cache.Provider
|
||||||
statusCache cache.Cache
|
statusCache cache.Cache
|
||||||
sessionCache cache.Cache
|
sessionCache cache.Cache
|
||||||
@@ -213,6 +216,18 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
license := ps.License()
|
||||||
|
// Step 3: Initialize filestore
|
||||||
|
if ps.filestore == nil {
|
||||||
|
insecure := ps.Config().ServiceSettings.EnableInsecureOutgoingConnections
|
||||||
|
backend, err2 := filestore.NewFileBackend(ps.Config().FileSettings.ToFileBackendSettings(license != nil && *license.Features.Compliance, insecure != nil && *insecure))
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, fmt.Errorf("failed to initialize filebackend: %w", err2)
|
||||||
|
}
|
||||||
|
|
||||||
|
ps.filestore = backend
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
ps.Store, err = ps.newStore()
|
ps.Store, err = ps.newStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -431,3 +446,7 @@ func (ps *PlatformService) GetPluginStatuses() (model.PluginStatuses, *model.App
|
|||||||
|
|
||||||
return pluginStatuses, nil
|
return pluginStatuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ps *PlatformService) FileBackend() filestore.FileBackend {
|
||||||
|
return ps.filestore
|
||||||
|
}
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ type Server struct {
|
|||||||
openGraphDataCache cache.Cache
|
openGraphDataCache cache.Cache
|
||||||
clusterLeaderListenerId string
|
clusterLeaderListenerId string
|
||||||
loggerLicenseListenerId string
|
loggerLicenseListenerId string
|
||||||
filestore filestore.FileBackend
|
|
||||||
|
|
||||||
platform *platform.PlatformService
|
platform *platform.PlatformService
|
||||||
platformOptions []platform.Option
|
platformOptions []platform.Option
|
||||||
@@ -239,15 +238,6 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
s.LoadLicense()
|
s.LoadLicense()
|
||||||
}
|
}
|
||||||
|
|
||||||
license := s.License()
|
|
||||||
insecure := s.platform.Config().ServiceSettings.EnableInsecureOutgoingConnections
|
|
||||||
// Step 3: Initialize filestore
|
|
||||||
backend, err := filestore.NewFileBackend(s.platform.Config().FileSettings.ToFileBackendSettings(license != nil && *license.Features.Compliance, insecure != nil && *insecure))
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to initialize filebackend")
|
|
||||||
}
|
|
||||||
s.filestore = backend
|
|
||||||
|
|
||||||
s.licenseWrapper = &licenseWrapper{
|
s.licenseWrapper = &licenseWrapper{
|
||||||
srv: s,
|
srv: s,
|
||||||
}
|
}
|
||||||
@@ -272,7 +262,7 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
ChannelKey: &channelsWrapper{srv: s},
|
ChannelKey: &channelsWrapper{srv: s},
|
||||||
ConfigKey: s.platform,
|
ConfigKey: s.platform,
|
||||||
LicenseKey: s.licenseWrapper,
|
LicenseKey: s.licenseWrapper,
|
||||||
FilestoreKey: s.filestore,
|
FilestoreKey: s.platform.FileBackend(),
|
||||||
FileInfoStoreKey: &fileInfoWrapper{srv: s},
|
FileInfoStoreKey: &fileInfoWrapper{srv: s},
|
||||||
ClusterKey: s.platform,
|
ClusterKey: s.platform,
|
||||||
UserKey: New(ServerConnector(s.Channels())),
|
UserKey: New(ServerConnector(s.Channels())),
|
||||||
@@ -439,6 +429,7 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
mlog.Info("Printing current working", mlog.String("directory", pwd))
|
mlog.Info("Printing current working", mlog.String("directory", pwd))
|
||||||
mlog.Info("Loaded config", mlog.String("source", s.platform.DescribeConfig()))
|
mlog.Info("Loaded config", mlog.String("source", s.platform.DescribeConfig()))
|
||||||
|
|
||||||
|
license := s.License()
|
||||||
allowAdvancedLogging := license != nil && *license.Features.AdvancedLogging
|
allowAdvancedLogging := license != nil && *license.Features.AdvancedLogging
|
||||||
|
|
||||||
if s.Audit == nil {
|
if s.Audit == nil {
|
||||||
@@ -1425,7 +1416,7 @@ func (s *Server) SendRemoveExpiredLicenseEmail(email string, renewalLink, locale
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) FileBackend() filestore.FileBackend {
|
func (s *Server) FileBackend() filestore.FileBackend {
|
||||||
return s.filestore
|
return s.platform.FileBackend()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) TotalWebsocketConnections() int {
|
func (s *Server) TotalWebsocketConnections() int {
|
||||||
|
|||||||
@@ -90,28 +90,29 @@ func TestStartServerNoS3Bucket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s3Endpoint := fmt.Sprintf("%s:%s", s3Host, s3Port)
|
s3Endpoint := fmt.Sprintf("%s:%s", s3Host, s3Port)
|
||||||
|
configStore, _ := config.NewFileStore("config.json", true)
|
||||||
|
store, _ := config.NewStoreFromBacking(configStore, nil, false)
|
||||||
|
|
||||||
|
cfg := store.Get()
|
||||||
|
cfg.FileSettings = model.FileSettings{
|
||||||
|
DriverName: model.NewString(model.ImageDriverS3),
|
||||||
|
AmazonS3AccessKeyId: model.NewString(model.MinioAccessKey),
|
||||||
|
AmazonS3SecretAccessKey: model.NewString(model.MinioSecretKey),
|
||||||
|
AmazonS3Bucket: model.NewString("nosuchbucket"),
|
||||||
|
AmazonS3Endpoint: model.NewString(s3Endpoint),
|
||||||
|
AmazonS3Region: model.NewString(""),
|
||||||
|
AmazonS3PathPrefix: model.NewString(""),
|
||||||
|
AmazonS3SSL: model.NewBool(false),
|
||||||
|
}
|
||||||
|
*cfg.ServiceSettings.ListenAddress = ":0"
|
||||||
|
_, _, err := store.Set(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
s, err := NewServer(func(server *Server) error {
|
s, err := NewServer(func(server *Server) error {
|
||||||
configStore, _ := config.NewFileStore("config.json", true)
|
var err2 error
|
||||||
store, _ := config.NewStoreFromBacking(configStore, nil, false)
|
server.platform, err2 = platform.New(platform.ServiceConfig{}, platform.ConfigStore(store))
|
||||||
var err error
|
require.NoError(t, err2)
|
||||||
server.platform, err = platform.New(platform.ServiceConfig{
|
|
||||||
ConfigStore: store,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
server.platform.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
cfg.FileSettings = model.FileSettings{
|
|
||||||
DriverName: model.NewString(model.ImageDriverS3),
|
|
||||||
AmazonS3AccessKeyId: model.NewString(model.MinioAccessKey),
|
|
||||||
AmazonS3SecretAccessKey: model.NewString(model.MinioSecretKey),
|
|
||||||
AmazonS3Bucket: model.NewString("nosuchbucket"),
|
|
||||||
AmazonS3Endpoint: model.NewString(s3Endpoint),
|
|
||||||
AmazonS3Region: model.NewString(""),
|
|
||||||
AmazonS3PathPrefix: model.NewString(""),
|
|
||||||
AmazonS3SSL: model.NewBool(false),
|
|
||||||
}
|
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -120,6 +121,8 @@ func TestStartServerNoS3Bucket(t *testing.T) {
|
|||||||
defer s.Shutdown()
|
defer s.Shutdown()
|
||||||
|
|
||||||
// ensure that a new bucket was created
|
// ensure that a new bucket was created
|
||||||
|
require.IsType(t, &filestore.S3FileBackend{}, s.FileBackend())
|
||||||
|
|
||||||
err = s.FileBackend().(*filestore.S3FileBackend).TestConnection()
|
err = s.FileBackend().(*filestore.S3FileBackend).TestConnection()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user