Skip to content

Commit

Permalink
Fix File Backend Initialisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
grundleborg committed Dec 18, 2023
1 parent 1efd516 commit b8cd1b4
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/mattermost/mattermost-server/v6/shared/filestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -149,7 +150,8 @@ func (p *Plugin) Reconfigure() error {
}

// Reinitialise the filestore backend
filesBackendSettings := p.Client.Configuration.GetConfig().FileSettings.ToFileBackendSettings(true, false)
// FIXME: Boolean flags shouldn't be hard coded.
filesBackendSettings := FixedFileSettingsToFileBackendSettings(p.Client.Configuration.GetUnsanitizedConfig().FileSettings, false, true)
filesBackend, err := filestore.NewFileBackend(filesBackendSettings)
if err != nil {
p.Client.Log.Error("unable to initialize the files storage", "err", err)
Expand Down Expand Up @@ -177,3 +179,43 @@ func (p *Plugin) Reconfigure() error {

return nil
}

func FixedFileSettingsToFileBackendSettings(fileSettings model.FileSettings, enableComplianceFeature bool, skipVerify bool) filestore.FileBackendSettings {
if *fileSettings.DriverName == model.ImageDriverLocal {
return filestore.FileBackendSettings{
DriverName: *fileSettings.DriverName,
Directory: *fileSettings.Directory,
}
}

amazonS3Bucket := ""
if fileSettings.AmazonS3Bucket != nil {
amazonS3Bucket = *fileSettings.AmazonS3Bucket
}

amazonS3PathPrefix := ""
if fileSettings.AmazonS3PathPrefix != nil {
amazonS3PathPrefix = *fileSettings.AmazonS3PathPrefix
}

amazonS3Region := ""
if fileSettings.AmazonS3Region != nil {
amazonS3Region = *fileSettings.AmazonS3Region
}

return filestore.FileBackendSettings{
DriverName: *fileSettings.DriverName,
AmazonS3AccessKeyId: *fileSettings.AmazonS3AccessKeyId,
AmazonS3SecretAccessKey: *fileSettings.AmazonS3SecretAccessKey,
AmazonS3Bucket: amazonS3Bucket,
AmazonS3PathPrefix: amazonS3PathPrefix,
AmazonS3Region: amazonS3Region,
AmazonS3Endpoint: *fileSettings.AmazonS3Endpoint,
AmazonS3SSL: fileSettings.AmazonS3SSL != nil && *fileSettings.AmazonS3SSL,
AmazonS3SignV2: fileSettings.AmazonS3SignV2 != nil && *fileSettings.AmazonS3SignV2,
AmazonS3SSE: fileSettings.AmazonS3SSE != nil && *fileSettings.AmazonS3SSE && enableComplianceFeature,
AmazonS3Trace: fileSettings.AmazonS3Trace != nil && *fileSettings.AmazonS3Trace,
AmazonS3RequestTimeoutMilliseconds: *fileSettings.AmazonS3RequestTimeoutMilliseconds,
SkipVerify: skipVerify,
}
}

0 comments on commit b8cd1b4

Please sign in to comment.