From c9c688b122ffa88e9c2b39d0311914a78842c4a0 Mon Sep 17 00:00:00 2001 From: lvtu <37565148+tongtongyin@users.noreply.github.com> Date: Mon, 20 Dec 2021 18:09:46 +0800 Subject: [PATCH] br: fix S3 backup endpoint suffix (#30530) close pingcap/tidb#30104 --- pkg/storage/parse_test.go | 2 +- pkg/storage/s3.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/storage/parse_test.go b/pkg/storage/parse_test.go index fc3ee47a0..542b5dde3 100644 --- a/pkg/storage/parse_test.go +++ b/pkg/storage/parse_test.go @@ -57,7 +57,7 @@ func (r *testStorageSuite) TestCreateStorage(c *C) { c.Assert(s3, NotNil) c.Assert(s3.Bucket, Equals, "bucket2") c.Assert(s3.Prefix, Equals, "prefix") - c.Assert(s3.Endpoint, Equals, "https://s3.example.com/") + c.Assert(s3.Endpoint, Equals, "https://s3.example.com") c.Assert(s3.ForcePathStyle, IsFalse) // nolint:lll diff --git a/pkg/storage/s3.go b/pkg/storage/s3.go index 6accafee7..f0a8a2a3a 100644 --- a/pkg/storage/s3.go +++ b/pkg/storage/s3.go @@ -155,7 +155,7 @@ func (options *S3BackendOptions) Apply(s3 *backuppb.S3) error { return errors.Annotate(berrors.ErrStorageInvalidConfig, "secret_access_key not found") } - s3.Endpoint = options.Endpoint + s3.Endpoint = strings.TrimSuffix(options.Endpoint, "/") s3.Region = options.Region // StorageClass, SSE and ACL are acceptable to be empty s3.StorageClass = options.StorageClass @@ -189,6 +189,7 @@ func (options *S3BackendOptions) parseFromFlags(flags *pflag.FlagSet) error { if err != nil { return errors.Trace(err) } + options.Endpoint = strings.TrimSuffix(options.Endpoint, "/") options.Region, err = flags.GetString(s3RegionOption) if err != nil { return errors.Trace(err)