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)
|
||||
mockStore.On("Preference").Return(&mockPreferenceStore)
|
||||
s := &Server{
|
||||
products: make(map[string]Product),
|
||||
Router: mux.NewRouter(),
|
||||
filestore: &fmocks.FileBackend{},
|
||||
products: make(map[string]Product),
|
||||
Router: mux.NewRouter(),
|
||||
}
|
||||
var err error
|
||||
s.platform, err = platform.New(platform.ServiceConfig{
|
||||
ConfigStore: memoryStore,
|
||||
})
|
||||
}, platform.SetFileStore(&fmocks.FileBackend{}))
|
||||
s.SetStore(mockStore)
|
||||
require.NoError(t, err)
|
||||
serviceMap := map[ServiceKey]any{
|
||||
ConfigKey: s.platform,
|
||||
LicenseKey: &licenseWrapper{s},
|
||||
FilestoreKey: s.filestore,
|
||||
FilestoreKey: s.FileBackend(),
|
||||
}
|
||||
ch, err := NewChannels(s, serviceMap)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -54,7 +54,7 @@ func ConfigStore(configStore *config.Store) Option {
|
||||
|
||||
func SetFileStore(filestore filestore.FileBackend) Option {
|
||||
return func(s *Server) error {
|
||||
s.filestore = filestore
|
||||
s.platformOptions = append(s.platformOptions, platform.SetFileStore(filestore))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/config"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
"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/store"
|
||||
"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.
|
||||
func ConfigStore(configStore *config.Store) Option {
|
||||
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/searchengine"
|
||||
"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/store"
|
||||
"github.com/mattermost/mattermost-server/v6/store/localcachelayer"
|
||||
@@ -41,6 +42,8 @@ type PlatformService struct {
|
||||
|
||||
configStore *config.Store
|
||||
|
||||
filestore filestore.FileBackend
|
||||
|
||||
cacheProvider cache.Provider
|
||||
statusCache 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
|
||||
ps.Store, err = ps.newStore()
|
||||
if err != nil {
|
||||
@@ -431,3 +446,7 @@ func (ps *PlatformService) GetPluginStatuses() (model.PluginStatuses, *model.App
|
||||
|
||||
return pluginStatuses, nil
|
||||
}
|
||||
|
||||
func (ps *PlatformService) FileBackend() filestore.FileBackend {
|
||||
return ps.filestore
|
||||
}
|
||||
|
||||
@@ -137,7 +137,6 @@ type Server struct {
|
||||
openGraphDataCache cache.Cache
|
||||
clusterLeaderListenerId string
|
||||
loggerLicenseListenerId string
|
||||
filestore filestore.FileBackend
|
||||
|
||||
platform *platform.PlatformService
|
||||
platformOptions []platform.Option
|
||||
@@ -239,15 +238,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
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{
|
||||
srv: s,
|
||||
}
|
||||
@@ -272,7 +262,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
ChannelKey: &channelsWrapper{srv: s},
|
||||
ConfigKey: s.platform,
|
||||
LicenseKey: s.licenseWrapper,
|
||||
FilestoreKey: s.filestore,
|
||||
FilestoreKey: s.platform.FileBackend(),
|
||||
FileInfoStoreKey: &fileInfoWrapper{srv: s},
|
||||
ClusterKey: s.platform,
|
||||
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("Loaded config", mlog.String("source", s.platform.DescribeConfig()))
|
||||
|
||||
license := s.License()
|
||||
allowAdvancedLogging := license != nil && *license.Features.AdvancedLogging
|
||||
|
||||
if s.Audit == nil {
|
||||
@@ -1425,7 +1416,7 @@ func (s *Server) SendRemoveExpiredLicenseEmail(email string, renewalLink, locale
|
||||
}
|
||||
|
||||
func (s *Server) FileBackend() filestore.FileBackend {
|
||||
return s.filestore
|
||||
return s.platform.FileBackend()
|
||||
}
|
||||
|
||||
func (s *Server) TotalWebsocketConnections() int {
|
||||
|
||||
@@ -90,28 +90,29 @@ func TestStartServerNoS3Bucket(t *testing.T) {
|
||||
}
|
||||
|
||||
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 {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
store, _ := config.NewStoreFromBacking(configStore, nil, false)
|
||||
var err error
|
||||
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"
|
||||
})
|
||||
var err2 error
|
||||
server.platform, err2 = platform.New(platform.ServiceConfig{}, platform.ConfigStore(store))
|
||||
require.NoError(t, err2)
|
||||
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -120,6 +121,8 @@ func TestStartServerNoS3Bucket(t *testing.T) {
|
||||
defer s.Shutdown()
|
||||
|
||||
// ensure that a new bucket was created
|
||||
require.IsType(t, &filestore.S3FileBackend{}, s.FileBackend())
|
||||
|
||||
err = s.FileBackend().(*filestore.S3FileBackend).TestConnection()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user