MM-9698 Fixing Minio with server side encryption. (#8367)
* Fixig Minio with server side encryption. * Add png file backend test
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
f0f4f68def
Коммит
ae1acbda49
@@ -138,16 +138,14 @@ func (b *S3FileBackend) WriteFile(f []byte, path string) *model.AppError {
|
|||||||
return model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
options := s3.PutObjectOptions{}
|
var contentType string
|
||||||
if b.encrypt {
|
if ext := filepath.Ext(path); model.IsFileExtImage(ext) {
|
||||||
options.UserMetadata["x-amz-server-side-encryption"] = "AES256"
|
contentType = model.GetImageMimeType(ext)
|
||||||
|
} else {
|
||||||
|
contentType = "binary/octet-stream"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ext := filepath.Ext(path); model.IsFileExtImage(ext) {
|
options := s3PutOptions(b.encrypt, contentType)
|
||||||
options.ContentType = model.GetImageMimeType(ext)
|
|
||||||
} else {
|
|
||||||
options.ContentType = "binary/octet-stream"
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = s3Clnt.PutObject(b.bucket, path, bytes.NewReader(f), -1, options); err != nil {
|
if _, err = s3Clnt.PutObject(b.bucket, path, bytes.NewReader(f), -1, options); err != nil {
|
||||||
return model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
@@ -230,6 +228,17 @@ func (b *S3FileBackend) RemoveDirectory(path string) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func s3PutOptions(encrypt bool, contentType string) s3.PutObjectOptions {
|
||||||
|
options := s3.PutObjectOptions{}
|
||||||
|
if encrypt {
|
||||||
|
options.UserMetadata = make(map[string]string)
|
||||||
|
options.UserMetadata["x-amz-server-side-encryption"] = "AES256"
|
||||||
|
}
|
||||||
|
options.ContentType = contentType
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
func s3CopyMetadata(encrypt bool) map[string]string {
|
func s3CopyMetadata(encrypt bool) map[string]string {
|
||||||
metaData := make(map[string]string)
|
metaData := make(map[string]string)
|
||||||
metaData["x-amz-server-side-encryption"] = "AES256"
|
metaData["x-amz-server-side-encryption"] = "AES256"
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ func TestLocalFileBackendTestSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestS3FileBackendTestSuite(t *testing.T) {
|
func TestS3FileBackendTestSuite(t *testing.T) {
|
||||||
|
runBackendTest(t, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestS3FileBackendTestSuiteWithEncryption(t *testing.T) {
|
||||||
|
runBackendTest(t, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runBackendTest(t *testing.T, encrypt bool) {
|
||||||
s3Host := os.Getenv("CI_HOST")
|
s3Host := os.Getenv("CI_HOST")
|
||||||
if s3Host == "" {
|
if s3Host == "" {
|
||||||
s3Host = "dockerhost"
|
s3Host = "dockerhost"
|
||||||
@@ -56,6 +64,7 @@ func TestS3FileBackendTestSuite(t *testing.T) {
|
|||||||
AmazonS3Bucket: model.MINIO_BUCKET,
|
AmazonS3Bucket: model.MINIO_BUCKET,
|
||||||
AmazonS3Endpoint: s3Endpoint,
|
AmazonS3Endpoint: s3Endpoint,
|
||||||
AmazonS3SSL: model.NewBool(false),
|
AmazonS3SSL: model.NewBool(false),
|
||||||
|
AmazonS3SSE: model.NewBool(encrypt),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -86,6 +95,20 @@ func (s *FileBackendTestSuite) TestReadWriteFile() {
|
|||||||
s.EqualValues(readString, "test")
|
s.EqualValues(readString, "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *FileBackendTestSuite) TestReadWriteFileImage() {
|
||||||
|
b := []byte("testimage")
|
||||||
|
path := "tests/" + model.NewId() + ".png"
|
||||||
|
|
||||||
|
s.Nil(s.backend.WriteFile(b, path))
|
||||||
|
defer s.backend.RemoveFile(path)
|
||||||
|
|
||||||
|
read, err := s.backend.ReadFile(path)
|
||||||
|
s.Nil(err)
|
||||||
|
|
||||||
|
readString := string(read)
|
||||||
|
s.EqualValues(readString, "testimage")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *FileBackendTestSuite) TestCopyFile() {
|
func (s *FileBackendTestSuite) TestCopyFile() {
|
||||||
b := []byte("test")
|
b := []byte("test")
|
||||||
path1 := "tests/" + model.NewId()
|
path1 := "tests/" + model.NewId()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user