github.com/levb/mattermost-server@v5.3.1+incompatible/utils/file_backend.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package utils 5 6 import ( 7 "io" 8 "net/http" 9 10 "github.com/mattermost/mattermost-server/model" 11 ) 12 13 type FileBackend interface { 14 TestConnection() *model.AppError 15 16 Reader(path string) (io.ReadCloser, *model.AppError) 17 ReadFile(path string) ([]byte, *model.AppError) 18 FileExists(path string) (bool, *model.AppError) 19 CopyFile(oldPath, newPath string) *model.AppError 20 MoveFile(oldPath, newPath string) *model.AppError 21 WriteFile(fr io.Reader, path string) (int64, *model.AppError) 22 RemoveFile(path string) *model.AppError 23 24 ListDirectory(path string) (*[]string, *model.AppError) 25 RemoveDirectory(path string) *model.AppError 26 } 27 28 func NewFileBackend(settings *model.FileSettings, enableComplianceFeatures bool) (FileBackend, *model.AppError) { 29 switch *settings.DriverName { 30 case model.IMAGE_DRIVER_S3: 31 return &S3FileBackend{ 32 endpoint: settings.AmazonS3Endpoint, 33 accessKey: settings.AmazonS3AccessKeyId, 34 secretKey: settings.AmazonS3SecretAccessKey, 35 secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL, 36 signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2, 37 region: settings.AmazonS3Region, 38 bucket: settings.AmazonS3Bucket, 39 encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures, 40 trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace, 41 }, nil 42 case model.IMAGE_DRIVER_LOCAL: 43 return &LocalFileBackend{ 44 directory: settings.Directory, 45 }, nil 46 } 47 return nil, model.NewAppError("NewFileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError) 48 }