batch: validate versioning on src/tgt buckets (#16955)

This commit is contained in:
Poorna 2023-04-04 10:50:11 -07:00 committed by GitHub
parent 5fa3665074
commit 699a24f7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -1116,16 +1116,18 @@ func (r *BatchJobReplicateV1) Validate(ctx context.Context, job BatchJobRequest,
if r.Source.Bucket == "" { if r.Source.Bucket == "" {
return errInvalidArgument return errInvalidArgument
} }
var isRemoteToLocal bool
localBkt := r.Source.Bucket localBkt := r.Source.Bucket
if r.Source.Endpoint != "" { if r.Source.Endpoint != "" {
localBkt = r.Target.Bucket localBkt = r.Target.Bucket
isRemoteToLocal = true
} }
info, err := o.GetBucketInfo(ctx, localBkt, BucketOptions{}) info, err := o.GetBucketInfo(ctx, localBkt, BucketOptions{})
if err != nil { if err != nil {
if isErrBucketNotFound(err) { if isErrBucketNotFound(err) {
return batchReplicationJobError{ return batchReplicationJobError{
Code: "NoSuchSourceBucket", Code: "NoSuchSourceBucket",
Description: "The specified source bucket does not exist", Description: fmt.Sprintf("The specified bucket %s does not exist", localBkt),
HTTPStatusCode: http.StatusNotFound, HTTPStatusCode: http.StatusNotFound,
} }
} }
@ -1222,8 +1224,8 @@ func (r *BatchJobReplicateV1) Validate(ctx context.Context, job BatchJobRequest,
} }
return err return err
} }
// If source has versioning enabled, target must have versioning enabled
if info.Versioning && !vcfg.Enabled() { if (info.Versioning && !vcfg.Enabled() && !isRemoteToLocal) || (!info.Versioning && vcfg.Enabled() && isRemoteToLocal) {
return batchReplicationJobError{ return batchReplicationJobError{
Code: "InvalidBucketState", Code: "InvalidBucketState",
Description: fmt.Sprintf("The source '%s' has versioning enabled, target '%s' must have versioning enabled", Description: fmt.Sprintf("The source '%s' has versioning enabled, target '%s' must have versioning enabled",

View File

@ -998,7 +998,7 @@ func (er erasureObjects) putObject(ctx context.Context, bucket string, object st
if opts.CheckPrecondFn != nil { if opts.CheckPrecondFn != nil {
obj, err := er.getObjectInfo(ctx, bucket, object, opts) obj, err := er.getObjectInfo(ctx, bucket, object, opts)
if err != nil && !isErrVersionNotFound(err) { if err != nil && !isErrVersionNotFound(err) && !isErrObjectNotFound(err) {
return objInfo, err return objInfo, err
} }
if opts.CheckPrecondFn(obj) { if opts.CheckPrecondFn(obj) {