From d5bca3af2d555e7f857b92a420711e3c1e1fe932 Mon Sep 17 00:00:00 2001 From: baoloongmao Date: Tue, 17 Nov 2020 10:13:21 +0800 Subject: [PATCH] Add a new isAws flag to enable aws v2 api. --- api/common/conf_s3.go | 1 + api/common/config.go | 1 + internal/backend_s3.go | 2 +- internal/flags.go | 6 ++++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/common/conf_s3.go b/api/common/conf_s3.go index 2401119f..3cb5e830 100644 --- a/api/common/conf_s3.go +++ b/api/common/conf_s3.go @@ -55,6 +55,7 @@ type S3Config struct { Session *session.Session BucketOwner string + IsAws bool } var s3Session *session.Session diff --git a/api/common/config.go b/api/common/config.go index e4f23ad5..74099343 100644 --- a/api/common/config.go +++ b/api/common/config.go @@ -40,6 +40,7 @@ type FlagStorage struct { // Common Backend Config UseContentType bool + IsAws bool Endpoint string Backend interface{} diff --git a/internal/backend_s3.go b/internal/backend_s3.go index 3ee2d489..027f48d0 100644 --- a/internal/backend_s3.go +++ b/internal/backend_s3.go @@ -175,7 +175,7 @@ func (s *S3Backend) detectBucketLocationByHEAD() (err error, isAws bool) { s3Log.Debugf("%v = %v", k, v) } } - if server != nil && server[0] == "AmazonS3" { + if s.flags.IsAws || (server != nil && server[0] == "AmazonS3") { isAws = true } diff --git a/internal/flags.go b/internal/flags.go index f18633a8..df105857 100644 --- a/internal/flags.go +++ b/internal/flags.go @@ -180,6 +180,11 @@ func NewApp() (app *cli.App) { Usage: "Set Content-Type according to file extension and /etc/mime.types (default: off)", }, + cli.BoolFlag{ + Name: "isAws", + Usage: "Enable v2 aws api (default: off)", + }, + /// http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html /// See http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html cli.BoolFlag{ @@ -335,6 +340,7 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) { // Common Backend Config Endpoint: c.String("endpoint"), + IsAws: c.Bool("isAws"), UseContentType: c.Bool("use-content-type"), // Debugging,