[PLT-8186] add support for ec2 instance profile authentication (#8243)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2018-03-01 00:12:11 +01:00
коммит произвёл Joram Wilander
родитель d2b70b8671
Коммит 6e024c45b5
6 изменённых файлов: 173 добавлений и 1 удалений

Просмотреть файл

@@ -37,7 +37,10 @@ type S3FileBackend struct {
// disables automatic region lookup.
func (b *S3FileBackend) s3New() (*s3.Client, error) {
var creds *credentials.Credentials
if b.signV2 {
if b.accessKey == "" && b.secretKey == "" {
creds = credentials.NewIAM("")
} else if b.signV2 {
creds = credentials.NewStatic(b.accessKey, b.secretKey, "", credentials.SignatureV2)
} else {
creds = credentials.NewStatic(b.accessKey, b.secretKey, "", credentials.SignatureV4)
@@ -244,3 +247,19 @@ func s3CopyMetadata(encrypt bool) map[string]string {
metaData["x-amz-server-side-encryption"] = "AES256"
return metaData
}
func CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError {
if len(settings.AmazonS3Bucket) == 0 {
return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_bucket", nil, "", http.StatusBadRequest)
}
if len(settings.AmazonS3Endpoint) == 0 {
return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_endpoint", nil, "", http.StatusBadRequest)
}
if len(settings.AmazonS3Region) == 0 {
return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_region", nil, "", http.StatusBadRequest)
}
return nil
}

32
utils/file_backend_s3_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,32 @@
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package utils
import (
"testing"
"github.com/mattermost/mattermost-server/model"
)
func TestCheckMandatoryS3Fields(t *testing.T) {
cfg := model.FileSettings{}
err := CheckMandatoryS3Fields(&cfg)
if err == nil || err.Message != "api.admin.test_s3.missing_s3_bucket" {
t.Fatal("should've failed with missing s3 bucket")
}
cfg.AmazonS3Bucket = "test-mm"
err = CheckMandatoryS3Fields(&cfg)
if err == nil || err.Message != "api.admin.test_s3.missing_s3_endpoint" {
t.Fatal("should've failed with missing s3 endpoint")
}
cfg.AmazonS3Endpoint = "s3.newendpoint.com"
err = CheckMandatoryS3Fields(&cfg)
if err == nil || err.Message != "api.admin.test_s3.missing_s3_region" {
t.Fatal("should've failed with missing s3 region")
}
}