From 4db688e884bd539f48dc842e0722d95259699004 Mon Sep 17 00:00:00 2001 From: momodedev Date: Tue, 29 Oct 2024 04:38:47 +0000 Subject: [PATCH] Fix ignoring of S3 Glacier type errors bug (#2834) --- cmd/zc_traverser_s3.go | 27 +++++++++++++++++++++++++++ common/azError.go | 5 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cmd/zc_traverser_s3.go b/cmd/zc_traverser_s3.go index 825ad4fcb..e0f4a2fba 100644 --- a/cmd/zc_traverser_s3.go +++ b/cmd/zc_traverser_s3.go @@ -72,7 +72,28 @@ func (t *s3Traverser) Traverse(preprocessor objectMorpher, processor objectProce return strings.HasSuffix(objectKey, ".") || strings.Contains(objectKey, "./") } + + const ( + storageClassKey = "X-Amz-Storage-Class" + deepArchiveClass = "DEEP_ARCHIVE" + ) + + invalidAwsStorageClass := func(minioObject minio.ObjectInfo) bool { + /* S3 object's storage class "DEEP_ARCHIVE" is invalid. + Because S3 Glacier Archive objects cannot be copied to Azure Storage. + */ + storageClasses, ok := minioObject.Metadata[storageClassKey] + if !ok || len(storageClasses) == 0 { + return false + } + + storageClass := storageClasses[0] + + return storageClass == deepArchiveClass + } + invalidNameErrorMsg := "Skipping S3 object %s, as it is not a valid Blob name. Rename the object and retry the transfer" + invalidAwsStorageClassMsg := "Skipping S3 object %s, as it is not a valid AWS storage class: %s" // Check if resource is a single object. if t.s3URLParts.IsObjectSyntactically() && !t.s3URLParts.IsDirectorySyntactically() && !t.s3URLParts.IsBucketSyntactically() { objectPath := strings.Split(t.s3URLParts.ObjectKey, "/") @@ -84,6 +105,12 @@ func (t *s3Traverser) Traverse(preprocessor objectMorpher, processor objectProce return common.EAzError.InvalidBlobName() } + if invalidAwsStorageClass(oi) { + + WarnStdoutAndScanningLog(fmt.Sprintf(invalidAwsStorageClassMsg, t.s3URLParts.ObjectKey, deepArchiveClass)) + return common.EAzError.InvalidAWSStorageClass() + } + // If we actually got object properties, process them. // Otherwise, treat it as a directory. // According to IsDirectorySyntactically, objects and folders can share names diff --git a/common/azError.go b/common/azError.go index 72082bbc3..beb082209 100644 --- a/common/azError.go +++ b/common/azError.go @@ -49,6 +49,9 @@ func (err AzError) Error() string { var EAzError AzError +func (err AzError) InvalidAWSStorageClass() AzError { + return AzError{uint64(2), "Invalid AWS Storage Class: ", "DEEP_ARCHIVE"} +} func (err AzError) LoginCredMissing() AzError { return AzError{uint64(1), "Login Credentials missing. ", ""} } @@ -67,4 +70,4 @@ func (err AzError) InvalidServiceClient() AzError { func ErrInvalidClient(msg string) AzError { return NewAzError(EAzError.InvalidServiceClient(), fmt.Sprintf("Expecting %s client", msg)) -} \ No newline at end of file +}