Check if object lock is enabled on destination bucket while setting replication configuration on a object lock enabled bucket.
Unified · Split
| @@ -107,6 +107,7 @@ const ( · 106 unmodified lines | ||
| 107 | 107 | ErrNoSuchWebsiteConfiguration |
| 108 | 108 | ErrReplicationConfigurationNotFoundError |
| 109 | 109 | ErrReplicationDestinationNotFoundError |
| 110 | + ErrReplicationDestinationMissingLock | |
| 110 | 111 | ErrReplicationTargetNotFoundError |
| 111 | 112 | ErrBucketRemoteIdenticalToSource |
| 112 | 113 | ErrBucketRemoteAlreadyExists |
| @@ -830,6 +831,11 @@ var errorCodes = errorCodeMap{ · 717 unmodified lines | ||
| 830 | 831 | Description: "The replication destination bucket does not exist", |
| 831 | 832 | HTTPStatusCode: http.StatusNotFound, |
| 832 | 833 | }, |
| 834 | + ErrReplicationDestinationMissingLock: { | |
| 835 | + Code: "ReplicationDestinationMissingLockError", | |
| 836 | + Description: "The replication destination bucket does not have object locking enabled", | |
| 837 | + HTTPStatusCode: http.StatusBadRequest, | |
| 838 | + }, | |
| 833 | 839 | ErrReplicationTargetNotFoundError: { |
| 834 | 840 | Code: "XminioAdminReplicationTargetNotFoundError", |
| 835 | 841 | Description: "The replication target does not exist", |
| @@ -1909,6 +1915,8 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) { · 1073 unmodified lines | ||
| 1909 | 1915 | apiErr = ErrReplicationConfigurationNotFoundError |
| 1910 | 1916 | case BucketReplicationDestinationNotFound: |
| 1911 | 1917 | apiErr = ErrReplicationDestinationNotFoundError |
| 1918 | + case BucketReplicationDestinationMissingLock: | |
| 1919 | + apiErr = ErrReplicationDestinationMissingLock | |
| 1912 | 1920 | case BucketRemoteTargetNotFound: |
| 1913 | 1921 | apiErr = ErrReplicationTargetNotFoundError |
| 1914 | 1922 | case BucketRemoteAlreadyExists: |
| @@ -56,6 +56,14 @@ func validateReplicationDestination(ctx context.Context, bucket string, rCfg *re · 55 unmodified lines | ||
| 56 | 56 | if found, _ := clnt.BucketExists(ctx, rCfg.GetDestination().Bucket); !found { |
| 57 | 57 | return false, BucketReplicationDestinationNotFound{Bucket: rCfg.GetDestination().Bucket} |
| 58 | 58 | } |
| 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 | + } | |
| 59 | 67 | // validate replication ARN against target endpoint |
| 60 | 68 | c, ok := globalBucketTargetSys.arnRemotesMap[rCfg.ReplicationArn] |
| 61 | 69 | if ok { |
| @@ -362,6 +362,13 @@ func (e BucketReplicationDestinationNotFound) Error() string { · 361 unmodified lines | ||
| 362 | 362 | return "Destination bucket does not exist: " + e.Bucket |
| 363 | 363 | } |
| 364 | 364 | |
| 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 | + | |
| 365 | 372 | // BucketRemoteTargetNotFound remote target does not exist. |
| 366 | 373 | type BucketRemoteTargetNotFound GenericError |
| 367 | 374 | |