From fba1762a57761b64dd18a67f3a5009dc26b6fcb0 Mon Sep 17 00:00:00 2001 From: Javier Cortejoso Date: Tue, 8 Oct 2024 23:03:09 +0200 Subject: [PATCH] Disable chunk encoding for `put` requests to Google Cloud Storage (#167) * Set DisableContentSha256=true for Put() requests to Google * Move putObjectOptions to s3 Store struct --- store/precomputed_key/s3/s3.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/store/precomputed_key/s3/s3.go b/store/precomputed_key/s3/s3.go index 16bccf5..eb8db66 100644 --- a/store/precomputed_key/s3/s3.go +++ b/store/precomputed_key/s3/s3.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "errors" "io" + "net/url" "path" "time" @@ -14,6 +15,7 @@ import ( "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" + "github.com/minio/minio-go/v7/pkg/s3utils" ) const ( @@ -50,12 +52,22 @@ type Config struct { } type Store struct { - cfg Config - client *minio.Client - stats *store.Stats + cfg Config + client *minio.Client + putObjectOptions minio.PutObjectOptions + stats *store.Stats } func NewS3(cfg Config) (*Store, error) { + endpointURL, err := url.Parse(cfg.Endpoint) + if err != nil { + return nil, err + } + putObjectOptions := minio.PutObjectOptions{} + if s3utils.IsGoogleEndpoint(*endpointURL) { + putObjectOptions.DisableContentSha256 = true // Avoid chunk signatures on GCS: https://github.com/minio/minio-go/issues/1922 + } + client, err := minio.New(cfg.Endpoint, &minio.Options{ Creds: creds(cfg), Secure: cfg.EnableTLS, @@ -65,8 +77,9 @@ func NewS3(cfg Config) (*Store, error) { } return &Store{ - cfg: cfg, - client: client, + cfg: cfg, + client: client, + putObjectOptions: putObjectOptions, stats: &store.Stats{ Entries: 0, Reads: 0, @@ -97,7 +110,7 @@ func (s *Store) Get(ctx context.Context, key []byte) ([]byte, error) { } func (s *Store) Put(ctx context.Context, key []byte, value []byte) error { - _, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), minio.PutObjectOptions{}) + _, err := s.client.PutObject(ctx, s.cfg.Bucket, path.Join(s.cfg.Path, hex.EncodeToString(key)), bytes.NewReader(value), int64(len(value)), s.putObjectOptions) if err != nil { return err }