fix: improve error messages returned during replication setup (#13261)

This commit is contained in:
Poorna Krishnamoorthy 2021-09-21 16:03:20 -04:00 committed by GitHub
parent 1fa0553c71
commit 806b10b934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 24 deletions

View File

@ -1967,8 +1967,6 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
apiErr = ErrReplicationConfigurationNotFoundError apiErr = ErrReplicationConfigurationNotFoundError
case BucketRemoteDestinationNotFound: case BucketRemoteDestinationNotFound:
apiErr = ErrRemoteDestinationNotFoundError apiErr = ErrRemoteDestinationNotFoundError
case BucketReplicationDestinationMissingLock:
apiErr = ErrReplicationDestinationMissingLock
case BucketRemoteTargetNotFound: case BucketRemoteTargetNotFound:
apiErr = ErrRemoteTargetNotFoundError apiErr = ErrRemoteTargetNotFoundError
case BucketRemoteConnectionErr: case BucketRemoteConnectionErr:

View File

@ -1525,9 +1525,9 @@ func (api objectAPIHandlers) PutBucketReplicationConfigHandler(w http.ResponseWr
writeErrorResponse(ctx, w, apiErr, r.URL) writeErrorResponse(ctx, w, apiErr, r.URL)
return return
} }
sameTarget, err := validateReplicationDestination(ctx, bucket, replicationConfig) sameTarget, apiErr := validateReplicationDestination(ctx, bucket, replicationConfig)
if err != nil { if apiErr != noError {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) writeErrorResponse(ctx, w, apiErr, r.URL)
return return
} }
// Validate the received bucket replication config // Validate the received bucket replication config

View File

@ -79,7 +79,7 @@ func getReplicationConfig(ctx context.Context, bucketName string) (rc *replicati
// validateReplicationDestination returns error if replication destination bucket missing or not configured // validateReplicationDestination returns error if replication destination bucket missing or not configured
// It also returns true if replication destination is same as this server. // It also returns true if replication destination is same as this server.
func validateReplicationDestination(ctx context.Context, bucket string, rCfg *replication.Config) (bool, error) { func validateReplicationDestination(ctx context.Context, bucket string, rCfg *replication.Config) (bool, APIError) {
var arns []string var arns []string
if rCfg.RoleArn != "" { if rCfg.RoleArn != "" {
arns = append(arns, rCfg.RoleArn) arns = append(arns, rCfg.RoleArn)
@ -91,23 +91,23 @@ func validateReplicationDestination(ctx context.Context, bucket string, rCfg *re
for _, arnStr := range arns { for _, arnStr := range arns {
arn, err := madmin.ParseARN(arnStr) arn, err := madmin.ParseARN(arnStr)
if err != nil { if err != nil {
return false, BucketRemoteArnInvalid{} return false, errorCodes.ToAPIErrWithErr(ErrBucketRemoteArnInvalid, err)
} }
if arn.Type != madmin.ReplicationService { if arn.Type != madmin.ReplicationService {
return false, BucketRemoteArnTypeInvalid{} return false, toAPIError(ctx, BucketRemoteArnTypeInvalid{Bucket: bucket})
} }
clnt := globalBucketTargetSys.GetRemoteTargetClient(ctx, arnStr) clnt := globalBucketTargetSys.GetRemoteTargetClient(ctx, arnStr)
if clnt == nil { if clnt == nil {
return false, BucketRemoteTargetNotFound{Bucket: bucket} return false, toAPIError(ctx, BucketRemoteTargetNotFound{Bucket: bucket})
} }
if found, _ := clnt.BucketExists(ctx, arn.Bucket); !found { if found, err := clnt.BucketExists(ctx, arn.Bucket); !found {
return false, BucketRemoteDestinationNotFound{Bucket: arn.Bucket} return false, errorCodes.ToAPIErrWithErr(ErrRemoteDestinationNotFoundError, err)
} }
if ret, err := globalBucketObjectLockSys.Get(bucket); err == nil { if ret, err := globalBucketObjectLockSys.Get(bucket); err == nil {
if ret.LockEnabled { if ret.LockEnabled {
lock, _, _, _, err := clnt.GetObjectLockConfig(ctx, arn.Bucket) lock, _, _, _, err := clnt.GetObjectLockConfig(ctx, arn.Bucket)
if err != nil || lock != "Enabled" { if err != nil || lock != "Enabled" {
return false, BucketReplicationDestinationMissingLock{Bucket: arn.Bucket} return false, errorCodes.ToAPIErrWithErr(ErrReplicationDestinationMissingLock, err)
} }
} }
} }
@ -116,11 +116,11 @@ func validateReplicationDestination(ctx context.Context, bucket string, rCfg *re
if ok { if ok {
if c.EndpointURL().String() == clnt.EndpointURL().String() { if c.EndpointURL().String() == clnt.EndpointURL().String() {
sameTarget, _ := isLocalHost(clnt.EndpointURL().Hostname(), clnt.EndpointURL().Port(), globalMinioPort) sameTarget, _ := isLocalHost(clnt.EndpointURL().Hostname(), clnt.EndpointURL().Port(), globalMinioPort)
return sameTarget, nil return sameTarget, toAPIError(ctx, nil)
} }
} }
} }
return false, BucketRemoteTargetNotFound{Bucket: bucket} return false, toAPIError(ctx, BucketRemoteTargetNotFound{Bucket: bucket})
} }
type mustReplicateOptions struct { type mustReplicateOptions struct {

View File

@ -400,13 +400,6 @@ func (e BucketRemoteDestinationNotFound) Error() string {
return "Destination bucket does not exist: " + e.Bucket return "Destination bucket does not exist: " + e.Bucket
} }
// BucketReplicationDestinationMissingLock bucket does not have object lock enabled.
type BucketReplicationDestinationMissingLock GenericError
func (e BucketReplicationDestinationMissingLock) Error() string {
return "Destination bucket does not have object lock enabled: " + e.Bucket
}
// BucketRemoteTargetNotFound remote target does not exist. // BucketRemoteTargetNotFound remote target does not exist.
type BucketRemoteTargetNotFound GenericError type BucketRemoteTargetNotFound GenericError

2
go.mod
View File

@ -46,7 +46,7 @@ require (
github.com/minio/highwayhash v1.0.2 github.com/minio/highwayhash v1.0.2
github.com/minio/kes v0.14.0 github.com/minio/kes v0.14.0
github.com/minio/madmin-go v1.1.6-0.20210917204419-f12dc0d0a8bd github.com/minio/madmin-go v1.1.6-0.20210917204419-f12dc0d0a8bd
github.com/minio/minio-go/v7 v7.0.15-0.20210917235750-a16dfb14e6f6 github.com/minio/minio-go/v7 v7.0.15-0.20210921183434-174b4c070788
github.com/minio/parquet-go v1.0.0 github.com/minio/parquet-go v1.0.0
github.com/minio/pkg v1.1.3 github.com/minio/pkg v1.1.3
github.com/minio/selfupdate v0.3.1 github.com/minio/selfupdate v0.3.1

4
go.sum
View File

@ -1033,8 +1033,8 @@ github.com/minio/minio-go/v7 v7.0.10/go.mod h1:td4gW1ldOsj1PbSNS+WYK43j+P1XVhX/8
github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78/go.mod h1:mTh2uJuAbEqdhMVl6CMIIZLUeiMiWtJR4JB8/5g2skw= github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78/go.mod h1:mTh2uJuAbEqdhMVl6CMIIZLUeiMiWtJR4JB8/5g2skw=
github.com/minio/minio-go/v7 v7.0.11-0.20210607181445-e162fdb8e584/go.mod h1:WoyW+ySKAKjY98B9+7ZbI8z8S3jaxaisdcvj9TGlazA= github.com/minio/minio-go/v7 v7.0.11-0.20210607181445-e162fdb8e584/go.mod h1:WoyW+ySKAKjY98B9+7ZbI8z8S3jaxaisdcvj9TGlazA=
github.com/minio/minio-go/v7 v7.0.14/go.mod h1:S23iSP5/gbMwtxeY5FM71R+TkAYyzEdoNEDDwpt8yWs= github.com/minio/minio-go/v7 v7.0.14/go.mod h1:S23iSP5/gbMwtxeY5FM71R+TkAYyzEdoNEDDwpt8yWs=
github.com/minio/minio-go/v7 v7.0.15-0.20210917235750-a16dfb14e6f6 h1:vkarc8wO5ozZavEJilw4O3gzhPRJFEkHxCzZU8f+PiE= github.com/minio/minio-go/v7 v7.0.15-0.20210921183434-174b4c070788 h1:O+/N9vxhoObjuCuQczycuzdG240SoLrrdnyipJ5JJc0=
github.com/minio/minio-go/v7 v7.0.15-0.20210917235750-a16dfb14e6f6/go.mod h1:X6NObIqnx2xvri7kLQSDB3GD1Nt0vtF9WG5oMVEKhLc= github.com/minio/minio-go/v7 v7.0.15-0.20210921183434-174b4c070788/go.mod h1:pUV0Pc+hPd1nccgmzQF/EXh48l/Z/yps6QPF1aaie4g=
github.com/minio/operator v0.0.0-20210812082324-26350f153661 h1:dGAJHpfmhNukFg0M0wDqH+G1OB2YPgZCcT6uv4n9YQk= github.com/minio/operator v0.0.0-20210812082324-26350f153661 h1:dGAJHpfmhNukFg0M0wDqH+G1OB2YPgZCcT6uv4n9YQk=
github.com/minio/operator v0.0.0-20210812082324-26350f153661/go.mod h1:zQqn6VGT46xlSpVXh1I/VZRv+eSgHtVu6URdg71YKX8= github.com/minio/operator v0.0.0-20210812082324-26350f153661/go.mod h1:zQqn6VGT46xlSpVXh1I/VZRv+eSgHtVu6URdg71YKX8=
github.com/minio/operator/logsearchapi v0.0.0-20210812082324-26350f153661 h1:tJw15hS3b1dVTf5PwA4roXZ/oRNnHyZ/8Y+yNTmQ5rA= github.com/minio/operator/logsearchapi v0.0.0-20210812082324-26350f153661 h1:tJw15hS3b1dVTf5PwA4roXZ/oRNnHyZ/8Y+yNTmQ5rA=