From caa6c4eda2ce359d34cda51c7a183083799fc24b Mon Sep 17 00:00:00 2001 From: Hugo <10965479+hugoghx@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:06:56 +0100 Subject: [PATCH] feat(storage): Make checksum verification optional Some 3rd party services the MinIO SDK can connect with do not return a checksum whenever a file is uploaded. Before this change, this would lead to an error, rendering it impossible to operate with those 3rd party services. With this change, we'll continue to verify checksums if they come through, however we won't error out if they don't and the PutObject call is successful. Note: There are no new tests with this change as this behaviour is not unit-testeable at the moment. I suggest we could have end-to-end tests for this. --- plugin/service/storage/plugin.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/service/storage/plugin.go b/plugin/service/storage/plugin.go index 24ff6ef..a5f3165 100644 --- a/plugin/service/storage/plugin.go +++ b/plugin/service/storage/plugin.go @@ -496,13 +496,18 @@ func (sp *StoragePlugin) PutObject(ctx context.Context, req *pb.PutObjectRequest return nil, status.Errorf(codes.Internal, "failed to put object into minio: %v", err) } - if res.ChecksumSHA256 == "" { - return nil, status.Error(codes.Internal, "missing checksum response from minio") + resChecksum := res.ChecksumSHA256 + if resChecksum == "" { + // We were successful in putting the object but we didn't get a file + // SHA256 checksum from the server. Given that the call was successful, + // assume everything went ok and force the checksum to match so we can + // send it correctly back to Boundary. + resChecksum = checksum } - if checksum != res.ChecksumSHA256 { + if checksum != resChecksum { return nil, status.Error(codes.Internal, "mismatched checksum") } - decodedChecksum, err := base64.StdEncoding.DecodeString(res.ChecksumSHA256) + decodedChecksum, err := base64.StdEncoding.DecodeString(resChecksum) if err != nil { return nil, status.Errorf(codes.Internal, "failed to decode checksum value from minio: %v", err) }