2313 lines · 81.0 KB · Go
RawDownload
// Copyright (c) 2015-2021 MinIO, Inc.//// This file is part of MinIO Object Storage stack//// This program is free software: you can redistribute it and/or modify// it under the terms of the GNU Affero General Public License as published by// the Free Software Foundation, either version 3 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Affero General Public License for more details.//// You should have received a copy of the GNU Affero General Public License// along with this program.  If not, see <http://www.gnu.org/licenses/>. package cmd import (	"context"	"encoding/xml"	"errors"	"fmt"	"net/http"	"net/url"	"strconv"	"strings" 	"github.com/Azure/azure-storage-blob-go/azblob"	"google.golang.org/api/googleapi" 	minio "github.com/minio/minio-go/v7"	"github.com/minio/minio-go/v7/pkg/tags"	"github.com/minio/minio/internal/auth"	"github.com/minio/minio/internal/bucket/lifecycle"	"github.com/minio/minio/internal/bucket/replication"	"github.com/minio/minio/internal/config/dns"	"github.com/minio/minio/internal/crypto"	"github.com/minio/minio/internal/logger" 	objectlock "github.com/minio/minio/internal/bucket/object/lock"	"github.com/minio/minio/internal/bucket/versioning"	"github.com/minio/minio/internal/event"	"github.com/minio/minio/internal/hash"	"github.com/minio/pkg/bucket/policy") // APIError structuretype APIError struct {	Code           string	Description    string	HTTPStatusCode int} // APIErrorResponse - error response formattype APIErrorResponse struct {	XMLName    xml.Name `xml:"Error" json:"-"`	Code       string	Message    string	Key        string `xml:"Key,omitempty" json:"Key,omitempty"`	BucketName string `xml:"BucketName,omitempty" json:"BucketName,omitempty"`	Resource   string	Region     string `xml:"Region,omitempty" json:"Region,omitempty"`	RequestID  string `xml:"RequestId" json:"RequestId"`	HostID     string `xml:"HostId" json:"HostId"`} // APIErrorCode type of error status.type APIErrorCode int //go:generate stringer -type=APIErrorCode -trimprefix=Err $GOFILE // Error codes, non exhaustive list - http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.htmlconst (	ErrNone APIErrorCode = iota	ErrAccessDenied	ErrBadDigest	ErrEntityTooSmall	ErrEntityTooLarge	ErrPolicyTooLarge	ErrIncompleteBody	ErrInternalError	ErrInvalidAccessKeyID	ErrAccessKeyDisabled	ErrInvalidBucketName	ErrInvalidDigest	ErrInvalidRange	ErrInvalidRangePartNumber	ErrInvalidCopyPartRange	ErrInvalidCopyPartRangeSource	ErrInvalidMaxKeys	ErrInvalidEncodingMethod	ErrInvalidMaxUploads	ErrInvalidMaxParts	ErrInvalidPartNumberMarker	ErrInvalidPartNumber	ErrInvalidRequestBody	ErrInvalidCopySource	ErrInvalidMetadataDirective	ErrInvalidCopyDest	ErrInvalidPolicyDocument	ErrInvalidObjectState	ErrMalformedXML	ErrMissingContentLength	ErrMissingContentMD5	ErrMissingRequestBodyError	ErrMissingSecurityHeader	ErrNoSuchBucket	ErrNoSuchBucketPolicy	ErrNoSuchBucketLifecycle	ErrNoSuchLifecycleConfiguration	ErrInvalidLifecycleWithObjectLock	ErrNoSuchBucketSSEConfig	ErrNoSuchCORSConfiguration	ErrNoSuchWebsiteConfiguration	ErrReplicationConfigurationNotFoundError	ErrRemoteDestinationNotFoundError	ErrReplicationDestinationMissingLock	ErrRemoteTargetNotFoundError	ErrReplicationRemoteConnectionError	ErrReplicationBandwidthLimitError	ErrBucketRemoteIdenticalToSource	ErrBucketRemoteAlreadyExists	ErrBucketRemoteLabelInUse	ErrBucketRemoteArnTypeInvalid	ErrBucketRemoteArnInvalid	ErrBucketRemoteRemoveDisallowed	ErrRemoteTargetNotVersionedError	ErrReplicationSourceNotVersionedError	ErrReplicationNeedsVersioningError	ErrReplicationBucketNeedsVersioningError	ErrReplicationDenyEditError	ErrReplicationNoMatchingRuleError	ErrObjectRestoreAlreadyInProgress	ErrNoSuchKey	ErrNoSuchUpload	ErrInvalidVersionID	ErrNoSuchVersion	ErrNotImplemented	ErrPreconditionFailed	ErrRequestTimeTooSkewed	ErrSignatureDoesNotMatch	ErrMethodNotAllowed	ErrInvalidPart	ErrInvalidPartOrder	ErrAuthorizationHeaderMalformed	ErrMalformedPOSTRequest	ErrPOSTFileRequired	ErrSignatureVersionNotSupported	ErrBucketNotEmpty	ErrAllAccessDisabled	ErrMalformedPolicy	ErrMissingFields	ErrMissingCredTag	ErrCredMalformed	ErrInvalidRegion	ErrInvalidServiceS3	ErrInvalidServiceSTS	ErrInvalidRequestVersion	ErrMissingSignTag	ErrMissingSignHeadersTag	ErrMalformedDate	ErrMalformedPresignedDate	ErrMalformedCredentialDate	ErrMalformedCredentialRegion	ErrMalformedExpires	ErrNegativeExpires	ErrAuthHeaderEmpty	ErrExpiredPresignRequest	ErrRequestNotReadyYet	ErrUnsignedHeaders	ErrMissingDateHeader	ErrInvalidQuerySignatureAlgo	ErrInvalidQueryParams	ErrBucketAlreadyOwnedByYou	ErrInvalidDuration	ErrBucketAlreadyExists	ErrMetadataTooLarge	ErrUnsupportedMetadata	ErrMaximumExpires	ErrSlowDown	ErrInvalidPrefixMarker	ErrBadRequest	ErrKeyTooLongError	ErrInvalidBucketObjectLockConfiguration	ErrObjectLockConfigurationNotFound	ErrObjectLockConfigurationNotAllowed	ErrNoSuchObjectLockConfiguration	ErrObjectLocked	ErrInvalidRetentionDate	ErrPastObjectLockRetainDate	ErrUnknownWORMModeDirective	ErrBucketTaggingNotFound	ErrObjectLockInvalidHeaders	ErrInvalidTagDirective	// Add new error codes here. 	// SSE-S3 related API errors	ErrInvalidEncryptionMethod 	// Server-Side-Encryption (with Customer provided key) related API errors.	ErrInsecureSSECustomerRequest	ErrSSEMultipartEncrypted	ErrSSEEncryptedObject	ErrInvalidEncryptionParameters	ErrInvalidSSECustomerAlgorithm	ErrInvalidSSECustomerKey	ErrMissingSSECustomerKey	ErrMissingSSECustomerKeyMD5	ErrSSECustomerKeyMD5Mismatch	ErrInvalidSSECustomerParameters	ErrIncompatibleEncryptionMethod	ErrKMSNotConfigured	ErrKMSKeyNotFoundException 	ErrNoAccessKey	ErrInvalidToken 	// Bucket notification related errors.	ErrEventNotification	ErrARNNotification	ErrRegionNotification	ErrOverlappingFilterNotification	ErrFilterNameInvalid	ErrFilterNamePrefix	ErrFilterNameSuffix	ErrFilterValueInvalid	ErrOverlappingConfigs	ErrUnsupportedNotification 	// S3 extended errors.	ErrContentSHA256Mismatch 	// Add new extended error codes here. 	// MinIO extended errors.	ErrReadQuorum	ErrWriteQuorum	ErrStorageFull	ErrRequestBodyParse	ErrObjectExistsAsDirectory	ErrInvalidObjectName	ErrInvalidObjectNamePrefixSlash	ErrInvalidResourceName	ErrServerNotInitialized	ErrOperationTimedOut	ErrClientDisconnected	ErrOperationMaxedOut	ErrInvalidRequest	ErrTransitionStorageClassNotFoundError	// MinIO storage class error codes	ErrInvalidStorageClass	ErrBackendDown	// Add new extended error codes here.	// Please open a https://github.com/minio/minio/issues before adding	// new error codes here. 	ErrMalformedJSON	ErrAdminNoSuchUser	ErrAdminNoSuchGroup	ErrAdminGroupNotEmpty	ErrAdminNoSuchPolicy	ErrAdminInvalidArgument	ErrAdminInvalidAccessKey	ErrAdminInvalidSecretKey	ErrAdminConfigNoQuorum	ErrAdminConfigTooLarge	ErrAdminConfigBadJSON	ErrAdminConfigDuplicateKeys	ErrAdminCredentialsMismatch	ErrInsecureClientRequest	ErrObjectTampered 	// Site-Replication errors	ErrSiteReplicationInvalidRequest	ErrSiteReplicationPeerResp	ErrSiteReplicationBackendIssue	ErrSiteReplicationServiceAccountError	ErrSiteReplicationBucketConfigError	ErrSiteReplicationBucketMetaError	ErrSiteReplicationIAMError 	// Bucket Quota error codes	ErrAdminBucketQuotaExceeded	ErrAdminNoSuchQuotaConfiguration 	ErrHealNotImplemented	ErrHealNoSuchProcess	ErrHealInvalidClientToken	ErrHealMissingBucket	ErrHealAlreadyRunning	ErrHealOverlappingPaths	ErrIncorrectContinuationToken 	// S3 Select Errors	ErrEmptyRequestBody	ErrUnsupportedFunction	ErrInvalidExpressionType	ErrBusy	ErrUnauthorizedAccess	ErrExpressionTooLong	ErrIllegalSQLFunctionArgument	ErrInvalidKeyPath	ErrInvalidCompressionFormat	ErrInvalidFileHeaderInfo	ErrInvalidJSONType	ErrInvalidQuoteFields	ErrInvalidRequestParameter	ErrInvalidDataType	ErrInvalidTextEncoding	ErrInvalidDataSource	ErrInvalidTableAlias	ErrMissingRequiredParameter	ErrObjectSerializationConflict	ErrUnsupportedSQLOperation	ErrUnsupportedSQLStructure	ErrUnsupportedSyntax	ErrUnsupportedRangeHeader	ErrLexerInvalidChar	ErrLexerInvalidOperator	ErrLexerInvalidLiteral	ErrLexerInvalidIONLiteral	ErrParseExpectedDatePart	ErrParseExpectedKeyword	ErrParseExpectedTokenType	ErrParseExpected2TokenTypes	ErrParseExpectedNumber	ErrParseExpectedRightParenBuiltinFunctionCall	ErrParseExpectedTypeName	ErrParseExpectedWhenClause	ErrParseUnsupportedToken	ErrParseUnsupportedLiteralsGroupBy	ErrParseExpectedMember	ErrParseUnsupportedSelect	ErrParseUnsupportedCase	ErrParseUnsupportedCaseClause	ErrParseUnsupportedAlias	ErrParseUnsupportedSyntax	ErrParseUnknownOperator	ErrParseMissingIdentAfterAt	ErrParseUnexpectedOperator	ErrParseUnexpectedTerm	ErrParseUnexpectedToken	ErrParseUnexpectedKeyword	ErrParseExpectedExpression	ErrParseExpectedLeftParenAfterCast	ErrParseExpectedLeftParenValueConstructor	ErrParseExpectedLeftParenBuiltinFunctionCall	ErrParseExpectedArgumentDelimiter	ErrParseCastArity	ErrParseInvalidTypeParam	ErrParseEmptySelect	ErrParseSelectMissingFrom	ErrParseExpectedIdentForGroupName	ErrParseExpectedIdentForAlias	ErrParseUnsupportedCallWithStar	ErrParseNonUnaryAgregateFunctionCall	ErrParseMalformedJoin	ErrParseExpectedIdentForAt	ErrParseAsteriskIsNotAloneInSelectList	ErrParseCannotMixSqbAndWildcardInSelectList	ErrParseInvalidContextForWildcardInSelectList	ErrIncorrectSQLFunctionArgumentType	ErrValueParseFailure	ErrEvaluatorInvalidArguments	ErrIntegerOverflow	ErrLikeInvalidInputs	ErrCastFailed	ErrInvalidCast	ErrEvaluatorInvalidTimestampFormatPattern	ErrEvaluatorInvalidTimestampFormatPatternSymbolForParsing	ErrEvaluatorTimestampFormatPatternDuplicateFields	ErrEvaluatorTimestampFormatPatternHourClockAmPmMismatch	ErrEvaluatorUnterminatedTimestampFormatPatternToken	ErrEvaluatorInvalidTimestampFormatPatternToken	ErrEvaluatorInvalidTimestampFormatPatternSymbol	ErrEvaluatorBindingDoesNotExist	ErrMissingHeaders	ErrInvalidColumnIndex 	ErrAdminConfigNotificationTargetsFailed	ErrAdminProfilerNotEnabled	ErrInvalidDecompressedSize	ErrAddUserInvalidArgument	ErrAdminAccountNotEligible	ErrAccountNotEligible	ErrAdminServiceAccountNotFound	ErrPostPolicyConditionInvalidFormat) type errorCodeMap map[APIErrorCode]APIError func (e errorCodeMap) ToAPIErrWithErr(errCode APIErrorCode, err error) APIError {	apiErr, ok := e[errCode]	if !ok {		apiErr = e[ErrInternalError]	}	if err != nil {		apiErr.Description = fmt.Sprintf("%s (%s)", apiErr.Description, err)	}	if globalSite.Region != "" {		switch errCode {		case ErrAuthorizationHeaderMalformed:			apiErr.Description = fmt.Sprintf("The authorization header is malformed; the region is wrong; expecting '%s'.", globalSite.Region)			return apiErr		}	}	return apiErr} func (e errorCodeMap) ToAPIErr(errCode APIErrorCode) APIError {	return e.ToAPIErrWithErr(errCode, nil)} // error code to APIError structure, these fields carry respective// descriptions for all the error responses.var errorCodes = errorCodeMap{	ErrInvalidCopyDest: {		Code:           "InvalidRequest",		Description:    "This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidCopySource: {		Code:           "InvalidArgument",		Description:    "Copy Source must mention the source bucket and key: sourcebucket/sourcekey.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidMetadataDirective: {		Code:           "InvalidArgument",		Description:    "Unknown metadata directive.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidStorageClass: {		Code:           "InvalidStorageClass",		Description:    "Invalid storage class.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidRequestBody: {		Code:           "InvalidArgument",		Description:    "Body shouldn't be set for this request.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidMaxUploads: {		Code:           "InvalidArgument",		Description:    "Argument max-uploads must be an integer between 0 and 2147483647",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidMaxKeys: {		Code:           "InvalidArgument",		Description:    "Argument maxKeys must be an integer between 0 and 2147483647",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidEncodingMethod: {		Code:           "InvalidArgument",		Description:    "Invalid Encoding Method specified in Request",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidMaxParts: {		Code:           "InvalidArgument",		Description:    "Part number must be an integer between 1 and 10000, inclusive",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidPartNumberMarker: {		Code:           "InvalidArgument",		Description:    "Argument partNumberMarker must be an integer.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrInvalidPartNumber: {		Code:           "InvalidPartNumber",		Description:    "The requested partnumber is not satisfiable",		HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable,	},	ErrInvalidPolicyDocument: {		Code:           "InvalidPolicyDocument",		Description:    "The content of the form does not meet the conditions specified in the policy document.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrAccessDenied: {		Code:           "AccessDenied",		Description:    "Access Denied.",		HTTPStatusCode: http.StatusForbidden,	},	ErrBadDigest: {		Code:           "BadDigest",		Description:    "The Content-Md5 you specified did not match what we received.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrEntityTooSmall: {		Code:           "EntityTooSmall",		Description:    "Your proposed upload is smaller than the minimum allowed object size.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrEntityTooLarge: {		Code:           "EntityTooLarge",		Description:    "Your proposed upload exceeds the maximum allowed object size.",		HTTPStatusCode: http.StatusBadRequest,	},	ErrPolicyTooLarge: {		Code:           "PolicyTooLarge",

Lines 1–500 of 2313.

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