Mm 29605 read permission s3 bucket (#16977)

Automatic Merge
Этот коммит содержится в:
Max Erenberg
2021-03-16 10:48:32 -04:00
коммит произвёл GitHub
родитель f0ccaa89bf
Коммит 4699845c0a
6 изменённых файлов: 116 добавлений и 12 удалений

Просмотреть файл

@@ -529,8 +529,14 @@ func NewServer(options ...Option) (*Server, error) {
if appErr != nil {
mlog.Error("Problem with file storage settings", mlog.Err(appErr))
} else {
if nErr := backend.TestConnection(); nErr != nil {
mlog.Error("Problem with file storage settings", mlog.Err(nErr))
nErr := backend.TestConnection()
if nErr != nil {
if errors.Is(nErr, filestore.ErrNoS3Bucket) {
nErr = backend.(*filestore.S3FileBackend).MakeBucket()
}
if nErr != nil {
mlog.Error("Problem with file storage settings", mlog.Err(nErr))
}
}
}

Просмотреть файл

@@ -26,6 +26,7 @@ import (
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/filestore"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
"github.com/mattermost/mattermost-server/v5/store/storetest"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
@@ -138,6 +139,46 @@ func TestStartServerPortUnavailable(t *testing.T) {
require.Error(t, serverErr)
}
func TestStartServerNoS3Bucket(t *testing.T) {
s3Host := os.Getenv("CI_MINIO_HOST")
if s3Host == "" {
s3Host = "localhost"
}
s3Port := os.Getenv("CI_MINIO_PORT")
if s3Port == "" {
s3Port = "9000"
}
s3Endpoint := fmt.Sprintf("%s:%s", s3Host, s3Port)
s, err := NewServer(func(server *Server) error {
configStore, _ := config.NewFileStore("config.json", true)
store, _ := config.NewStoreFromBacking(configStore, nil, false)
server.configStore = store
server.UpdateConfig(func(cfg *model.Config) {
cfg.FileSettings = model.FileSettings{
DriverName: model.NewString(model.IMAGE_DRIVER_S3),
AmazonS3AccessKeyId: model.NewString(model.MINIO_ACCESS_KEY),
AmazonS3SecretAccessKey: model.NewString(model.MINIO_SECRET_KEY),
AmazonS3Bucket: model.NewString("nosuchbucket"),
AmazonS3Endpoint: model.NewString(s3Endpoint),
AmazonS3Region: model.NewString(""),
AmazonS3PathPrefix: model.NewString(""),
AmazonS3SSL: model.NewBool(false),
}
})
return nil
})
require.NoError(t, err)
// ensure that a new bucket was created
backend, err := s.FileBackend()
require.Nil(t, err)
err = backend.(*filestore.S3FileBackend).TestConnection()
require.Nil(t, err)
}
func TestStartServerTLSSuccess(t *testing.T) {
s, err := NewServer()
require.NoError(t, err)