github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+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 ReadFile(path string) ([]byte, *model.AppError) 17 CopyFile(oldPath, newPath string) *model.AppError 18 MoveFile(oldPath, newPath string) *model.AppError 19 WriteFile(fr io.Reader, path string) (int64, *model.AppError) 20 RemoveFile(path string) *model.AppError 21 22 ListDirectory(path string) (*[]string, *model.AppError) 23 RemoveDirectory(path string) *model.AppError 24 } 25 26 func NewFileBackend(settings *model.FileSettings, enableComplianceFeatures bool) (FileBackend, *model.AppError) { 27 switch *settings.DriverName { 28 case model.IMAGE_DRIVER_S3: 29 return &S3FileBackend{ 30 endpoint: settings.AmazonS3Endpoint, 31 accessKey: settings.AmazonS3AccessKeyId, 32 secretKey: settings.AmazonS3SecretAccessKey, 33 secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL, 34 signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2, 35 region: settings.AmazonS3Region, 36 bucket: settings.AmazonS3Bucket, 37 encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures, 38 trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace, 39 }, nil 40 case model.IMAGE_DRIVER_LOCAL: 41 return &LocalFileBackend{ 42 directory: settings.Directory, 43 }, nil 44 } 45 return nil, model.NewAppError("NewFileBackend", "No file driver selected.", nil, "", http.StatusInternalServerError) 46 }