github.com/psyb0t/mattermost-server@v4.6.1-0.20180125161845-5503a1351abf+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  	"net/http"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  )
    11  
    12  type FileBackend interface {
    13  	TestConnection() *model.AppError
    14  
    15  	ReadFile(path string) ([]byte, *model.AppError)
    16  	CopyFile(oldPath, newPath string) *model.AppError
    17  	MoveFile(oldPath, newPath string) *model.AppError
    18  	WriteFile(f []byte, path string) *model.AppError
    19  	RemoveFile(path string) *model.AppError
    20  
    21  	ListDirectory(path string) (*[]string, *model.AppError)
    22  	RemoveDirectory(path string) *model.AppError
    23  }
    24  
    25  func NewFileBackend(settings *model.FileSettings) (FileBackend, *model.AppError) {
    26  	switch *settings.DriverName {
    27  	case model.IMAGE_DRIVER_S3:
    28  		return &S3FileBackend{
    29  			endpoint:  settings.AmazonS3Endpoint,
    30  			accessKey: settings.AmazonS3AccessKeyId,
    31  			secretKey: settings.AmazonS3SecretAccessKey,
    32  			secure:    settings.AmazonS3SSL == nil || *settings.AmazonS3SSL,
    33  			signV2:    settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2,
    34  			region:    settings.AmazonS3Region,
    35  			bucket:    settings.AmazonS3Bucket,
    36  			encrypt:   settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && IsLicensed() && *License().Features.Compliance,
    37  			trace:     settings.AmazonS3Trace != nil && *settings.AmazonS3Trace,
    38  		}, nil
    39  	case model.IMAGE_DRIVER_LOCAL:
    40  		return &LocalFileBackend{
    41  			directory: settings.Directory,
    42  		}, nil
    43  	}
    44  	return nil, model.NewAppError("NewFileBackend", "No file driver selected.", nil, "", http.StatusInternalServerError)
    45  }