From f4809def7822318d1a929519a2b43e7f0ae9468b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20V=C3=A9lez=20Vidal?= Date: Wed, 5 Jan 2022 10:04:16 +0100 Subject: [PATCH] MM-40752 - set encryption when copying files to minio honoring config defined value (#19251) Co-authored-by: Pablo Velez Vidal --- shared/filestore/s3store.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/shared/filestore/s3store.go b/shared/filestore/s3store.go index f938f4d53e..c45f626ad5 100644 --- a/shared/filestore/s3store.go +++ b/shared/filestore/s3store.go @@ -255,18 +255,25 @@ func (b *S3FileBackend) CopyFile(oldPath, newPath string) error { oldPath = filepath.Join(b.pathPrefix, oldPath) newPath = filepath.Join(b.pathPrefix, newPath) srcOpts := s3.CopySrcOptions{ - Bucket: b.bucket, - Object: oldPath, - Encryption: encrypt.NewSSE(), + Bucket: b.bucket, + Object: oldPath, } + if b.encrypt { + srcOpts.Encryption = encrypt.NewSSE() + } + dstOpts := s3.CopyDestOptions{ - Bucket: b.bucket, - Object: newPath, - Encryption: encrypt.NewSSE(), + Bucket: b.bucket, + Object: newPath, } + if b.encrypt { + dstOpts.Encryption = encrypt.NewSSE() + } + if _, err := b.client.CopyObject(context.Background(), dstOpts, srcOpts); err != nil { return errors.Wrapf(err, "unable to copy file from %s to %s", oldPath, newPath) } + return nil } @@ -274,14 +281,19 @@ func (b *S3FileBackend) MoveFile(oldPath, newPath string) error { oldPath = filepath.Join(b.pathPrefix, oldPath) newPath = filepath.Join(b.pathPrefix, newPath) srcOpts := s3.CopySrcOptions{ - Bucket: b.bucket, - Object: oldPath, - Encryption: encrypt.NewSSE(), + Bucket: b.bucket, + Object: oldPath, } + if b.encrypt { + srcOpts.Encryption = encrypt.NewSSE() + } + dstOpts := s3.CopyDestOptions{ - Bucket: b.bucket, - Object: newPath, - Encryption: encrypt.NewSSE(), + Bucket: b.bucket, + Object: newPath, + } + if b.encrypt { + dstOpts.Encryption = encrypt.NewSSE() } if _, err := b.client.CopyObject(context.Background(), dstOpts, srcOpts); err != nil {