summaryrefslogtreecommitdiffstats
path: root/utils/file_backend.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-11-16 15:04:27 -0600
committerJonathan <jonfritz@gmail.com>2017-11-16 16:04:27 -0500
commiteb1a00ef5f93b19c2d49b26de057ee2c51c09e45 (patch)
treee63afa695283e15c5cd9ee2a437d74024dcc5c20 /utils/file_backend.go
parentef69d93abfb192bc7a2416f3cf2622d99fd27dd5 (diff)
downloadchat-eb1a00ef5f93b19c2d49b26de057ee2c51c09e45.tar.gz
chat-eb1a00ef5f93b19c2d49b26de057ee2c51c09e45.tar.bz2
chat-eb1a00ef5f93b19c2d49b26de057ee2c51c09e45.zip
Reorganize file util functionality (#7848)
* reorganize file util functionality * fix api test compilation * fix rebase issue
Diffstat (limited to 'utils/file_backend.go')
-rw-r--r--utils/file_backend.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/utils/file_backend.go b/utils/file_backend.go
new file mode 100644
index 000000000..3469a63fb
--- /dev/null
+++ b/utils/file_backend.go
@@ -0,0 +1,44 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package utils
+
+import (
+ "net/http"
+
+ "github.com/mattermost/mattermost-server/model"
+)
+
+type FileBackend interface {
+ TestConnection() *model.AppError
+
+ ReadFile(path string) ([]byte, *model.AppError)
+ MoveFile(oldPath, newPath string) *model.AppError
+ WriteFile(f []byte, path string) *model.AppError
+ RemoveFile(path string) *model.AppError
+
+ ListDirectory(path string) (*[]string, *model.AppError)
+ RemoveDirectory(path string) *model.AppError
+}
+
+func NewFileBackend(settings *model.FileSettings) (FileBackend, *model.AppError) {
+ switch *settings.DriverName {
+ case model.IMAGE_DRIVER_S3:
+ return &S3FileBackend{
+ endpoint: settings.AmazonS3Endpoint,
+ accessKey: settings.AmazonS3AccessKeyId,
+ secretKey: settings.AmazonS3SecretAccessKey,
+ secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL,
+ signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2,
+ region: settings.AmazonS3Region,
+ bucket: settings.AmazonS3Bucket,
+ encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && IsLicensed() && *License().Features.Compliance,
+ trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace,
+ }, nil
+ case model.IMAGE_DRIVER_LOCAL:
+ return &LocalFileBackend{
+ directory: settings.Directory,
+ }, nil
+ }
+ return nil, model.NewAppError("NewFileBackend", "No file driver selected.", nil, "", http.StatusInternalServerError)
+}