From c9cc16936caec64df95bb48ae9169c58ac452022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20L=C3=B3pez?= Date: Tue, 30 Mar 2021 06:44:59 -0700 Subject: [PATCH] blob: remove s3Storage.needMD5 (#917) --- repo/blob/s3/s3_storage.go | 29 +------------------ repo/blob/s3/s3_storage_test.go | 49 --------------------------------- 2 files changed, 1 insertion(+), 77 deletions(-) diff --git a/repo/blob/s3/s3_storage.go b/repo/blob/s3/s3_storage.go index 631112506..c74da82ab 100644 --- a/repo/blob/s3/s3_storage.go +++ b/repo/blob/s3/s3_storage.go @@ -20,15 +20,12 @@ "github.com/kopia/kopia/repo/blob" "github.com/kopia/kopia/repo/blob/retrying" - "github.com/kopia/kopia/repo/logging" ) const ( s3storageType = "s3" ) -var log = logging.GetContextLoggerFunc(s3storageType) - type s3Storage struct { sendMD5 int32 Options @@ -220,24 +217,6 @@ func getCustomTransport(insecureSkipVerify bool) (transport *http.Transport) { return customTransport } -// returns whether put blob requires sending the content's MD5. -func needMD5(ctx context.Context, cli *minio.Client, bucketName string) bool { - var er minio.ErrorResponse - - mode, _, _, err := cli.GetBucketObjectLockConfig(ctx, bucketName) - if err == nil { - return mode != nil && mode.IsValid() - } - - if !errors.As(err, &er) || er.Code != "ObjectLockConfigurationNotFoundError" { - // Not all S3 stores implement the S3 API for bucket object-locking - // configuration and return an invalid response here. - log(ctx).Debugf("Could not get object-locking configuration, assuming MD5 is not needed for put blob: %v", err) - } - - return false -} - // New creates new S3-backed storage with specified options: // // - the 'BucketName' field is required and all other parameters are optional. @@ -273,16 +252,10 @@ func New(ctx context.Context, opt *Options) (blob.Storage, error) { return nil, errors.Errorf("bucket %q does not exist", opt.BucketName) } - var sendMD5 int32 - - if needMD5(ctx, cli, opt.BucketName) { - sendMD5 = 1 - } - return retrying.NewWrapper(&s3Storage{ Options: *opt, cli: cli, - sendMD5: sendMD5, + sendMD5: 0, downloadThrottler: downloadThrottler, uploadThrottler: uploadThrottler, }), nil diff --git a/repo/blob/s3/s3_storage_test.go b/repo/blob/s3/s3_storage_test.go index 3ac90168d..a77c06597 100644 --- a/repo/blob/s3/s3_storage_test.go +++ b/repo/blob/s3/s3_storage_test.go @@ -337,10 +337,6 @@ func TestNeedMD5AWS(t *testing.T) { err := cli.SetBucketObjectLockConfig(ctx, options.BucketName, &lockingMode, &unit, &days) noError(t, err, "could not set object lock config") - if !needMD5(ctx, cli, options.BucketName) { - t.Fatal("expected bucket to require MD5 for PUT blob, but got not required") - } - options.Prefix = uuid.NewString() + "/" s, err := New(ctx, options) @@ -356,51 +352,6 @@ func TestNeedMD5AWS(t *testing.T) { }) } -func TestNoNeedMD5Minio(t *testing.T) { - t.Parallel() - - ctx := testlogging.Context(t) - minioEndpoint := startDockerMinioOrSkip(t) - - var cli *minio.Client - - options := &Options{ - Endpoint: minioEndpoint, - AccessKeyID: minioAccessKeyID, - SecretAccessKey: minioSecretAccessKey, - BucketName: minioBucketName, - Region: minioRegion, - DoNotUseTLS: !minioUseSSL, - } - - testutil.Retry(t, func(t *testutil.RetriableT) { - cli = createClient(t, options) - makeBucket(t, cli, options, false) - - if needMD5(ctx, cli, minioBucketName) { - t.Fatal("expected bucket to not require MD5 for PUT blob, but got required") - } - }) -} - -func TestNoNeedMD5Providers(t *testing.T) { - t.Parallel() - - for k, env := range providerCreds { - env := env - - t.Run(k, func(t *testing.T) { - ctx := testlogging.Context(t) - options := getProviderOptions(t, env) - cli := createClient(t, options) - - if needMD5(ctx, cli, options.BucketName) { - t.Fatal("expected bucket to not require MD5 for PUT blob, but got required") - } - }) - } -} - func testStorage(t *testutil.RetriableT, options *Options) { ctx := testlogging.Context(t)