History

Validate object lock when setting replication config. (#10200)

Check if object lock is enabled on destination bucket while setting replication configuration on a object lock enabled bucket.

poornas committed 6 years ago

Commit 88daaef1 parent 1cdaced3 files · +23 −0Browse files

Unified · Split

3 files
  1. cmd/api-errors.go +8 −0
  2. cmd/bucket-replication.go +8 −0
  3. cmd/object-api-errors.go +7 −0
cmd/api-errors.go+8−0
@@ -107,6 +107,7 @@ const ( · 106 unmodified lines
107107 ErrNoSuchWebsiteConfiguration
108108 ErrReplicationConfigurationNotFoundError
109109 ErrReplicationDestinationNotFoundError
110+ ErrReplicationDestinationMissingLock
110111 ErrReplicationTargetNotFoundError
111112 ErrBucketRemoteIdenticalToSource
112113 ErrBucketRemoteAlreadyExists
@@ -830,6 +831,11 @@ var errorCodes = errorCodeMap{ · 717 unmodified lines
830831 Description: "The replication destination bucket does not exist",
831832 HTTPStatusCode: http.StatusNotFound,
832833 },
834+ ErrReplicationDestinationMissingLock: {
835+ Code: "ReplicationDestinationMissingLockError",
836+ Description: "The replication destination bucket does not have object locking enabled",
837+ HTTPStatusCode: http.StatusBadRequest,
838+ },
833839 ErrReplicationTargetNotFoundError: {
834840 Code: "XminioAdminReplicationTargetNotFoundError",
835841 Description: "The replication target does not exist",
@@ -1909,6 +1915,8 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) { · 1073 unmodified lines
19091915 apiErr = ErrReplicationConfigurationNotFoundError
19101916 case BucketReplicationDestinationNotFound:
19111917 apiErr = ErrReplicationDestinationNotFoundError
1918+ case BucketReplicationDestinationMissingLock:
1919+ apiErr = ErrReplicationDestinationMissingLock
19121920 case BucketRemoteTargetNotFound:
19131921 apiErr = ErrReplicationTargetNotFoundError
19141922 case BucketRemoteAlreadyExists:
cmd/bucket-replication.go+8−0
@@ -56,6 +56,14 @@ func validateReplicationDestination(ctx context.Context, bucket string, rCfg *re · 55 unmodified lines
5656 if found, _ := clnt.BucketExists(ctx, rCfg.GetDestination().Bucket); !found {
5757 return false, BucketReplicationDestinationNotFound{Bucket: rCfg.GetDestination().Bucket}
5858 }
59+ if ret, err := globalBucketObjectLockSys.Get(bucket); err == nil {
60+ if ret.LockEnabled {
61+ lock, _, _, _, err := clnt.GetObjectLockConfig(ctx, rCfg.GetDestination().Bucket)
62+ if err != nil || lock != "Enabled" {
63+ return false, BucketReplicationDestinationMissingLock{Bucket: rCfg.GetDestination().Bucket}
64+ }
65+ }
66+ }
5967 // validate replication ARN against target endpoint
6068 c, ok := globalBucketTargetSys.arnRemotesMap[rCfg.ReplicationArn]
6169 if ok {
cmd/object-api-errors.go+7−0
@@ -362,6 +362,13 @@ func (e BucketReplicationDestinationNotFound) Error() string { · 361 unmodified lines
362362 return "Destination bucket does not exist: " + e.Bucket
363363 }
364364
365+// BucketReplicationDestinationMissingLock bucket does not have object lock enabled.
366+type BucketReplicationDestinationMissingLock GenericError
367+
368+func (e BucketReplicationDestinationMissingLock) Error() string {
369+ return "Destination bucket does not have object lock enabled: " + e.Bucket
370+}
371+
365372 // BucketRemoteTargetNotFound remote target does not exist.
366373 type BucketRemoteTargetNotFound GenericError
367374

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t