| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2020-05-09 04:44:44 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-20 03:40:27 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-09-20 03:40:27 +08:00
										 |  |  | 	"io" | 
					
						
							| 
									
										
										
										
											2018-09-21 10:22:09 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2020-07-09 08:36:56 +08:00
										 |  |  | 	"time" | 
					
						
							| 
									
										
										
										
											2017-09-20 03:40:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 00:38:05 +08:00
										 |  |  | 	"github.com/minio/minio-go/v7/pkg/encrypt" | 
					
						
							|  |  |  | 	"github.com/minio/minio-go/v7/pkg/tags" | 
					
						
							| 
									
										
										
										
											2020-05-20 04:53:54 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/bucket/policy" | 
					
						
							| 
									
										
										
										
											2018-01-23 06:54:55 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/madmin" | 
					
						
							| 
									
										
										
										
											2017-09-20 03:40:27 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 04:01:22 +08:00
										 |  |  | // CheckPreconditionFn returns true if precondition check failed.
 | 
					
						
							|  |  |  | type CheckPreconditionFn func(o ObjectInfo) bool | 
					
						
							| 
									
										
										
										
											2019-03-07 04:38:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | // GetObjectInfoFn is the signature of GetObjectInfo function.
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | type GetObjectInfoFn func(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | // ObjectOptions represents object options for ObjectLayer object operations
 | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | type ObjectOptions struct { | 
					
						
							| 
									
										
										
										
											2020-11-13 04:12:09 +08:00
										 |  |  | 	ServerSideEncryption encrypt.ServerSide | 
					
						
							|  |  |  | 	VersionSuspended     bool      // indicates if the bucket was previously versioned but is currently suspended.
 | 
					
						
							|  |  |  | 	Versioned            bool      // indicates if the bucket is versioned
 | 
					
						
							|  |  |  | 	WalkVersions         bool      // indicates if the we are interested in walking versions
 | 
					
						
							|  |  |  | 	VersionID            string    // Specifies the versionID which needs to be overwritten or read
 | 
					
						
							|  |  |  | 	MTime                time.Time // Is only set in POST/PUT operations
 | 
					
						
							|  |  |  | 	Expires              time.Time // Is only used in POST/PUT operations
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 17:11:48 +08:00
										 |  |  | 	DeleteMarker                  bool                                                  // Is only set in DELETE operations for delete marker replication
 | 
					
						
							|  |  |  | 	UserDefined                   map[string]string                                     // only set in case of POST/PUT operations
 | 
					
						
							|  |  |  | 	PartNumber                    int                                                   // only useful in case of GetObject/HeadObject
 | 
					
						
							|  |  |  | 	CheckPrecondFn                CheckPreconditionFn                                   // only set during GetObject/HeadObject/CopyObjectPart preconditional valuation
 | 
					
						
							|  |  |  | 	DeleteMarkerReplicationStatus string                                                // Is only set in DELETE operations
 | 
					
						
							|  |  |  | 	VersionPurgeStatus            VersionPurgeStatusType                                // Is only set in DELETE operations for delete marker version to be permanently deleted.
 | 
					
						
							|  |  |  | 	TransitionStatus              string                                                // status of the transition
 | 
					
						
							|  |  |  | 	NoLock                        bool                                                  // indicates to lower layers if the caller is expecting to hold locks.
 | 
					
						
							|  |  |  | 	ProxyRequest                  bool                                                  // only set for GET/HEAD in active-active replication scenario
 | 
					
						
							| 
									
										
										
										
											2021-01-28 03:22:34 +08:00
										 |  |  | 	ProxyHeaderSet                bool                                                  // only set for GET/HEAD in active-active replication scenario
 | 
					
						
							| 
									
										
										
										
											2021-01-17 17:11:48 +08:00
										 |  |  | 	ParentIsObject                func(ctx context.Context, bucket, parent string) bool // Used to verify if parent is an object.
 | 
					
						
							| 
									
										
										
										
											2021-03-10 02:19:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Use the maximum parity (N/2), used when
 | 
					
						
							|  |  |  | 	// saving server configuration files
 | 
					
						
							|  |  |  | 	MaxParity bool | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | // BucketOptions represents bucket options for ObjectLayer bucket operations
 | 
					
						
							|  |  |  | type BucketOptions struct { | 
					
						
							|  |  |  | 	Location          string | 
					
						
							|  |  |  | 	LockEnabled       bool | 
					
						
							|  |  |  | 	VersioningEnabled bool | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-26 03:39:46 +08:00
										 |  |  | // LockType represents required locking for ObjectLayer operations
 | 
					
						
							|  |  |  | type LockType int | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	noLock LockType = iota | 
					
						
							|  |  |  | 	readLock | 
					
						
							|  |  |  | 	writeLock | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | // BackendMetrics - represents bytes served from backend
 | 
					
						
							|  |  |  | type BackendMetrics struct { | 
					
						
							|  |  |  | 	bytesReceived uint64 | 
					
						
							|  |  |  | 	bytesSent     uint64 | 
					
						
							|  |  |  | 	requestStats  RequestStats | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | // ObjectLayer implements primitives for object API layer.
 | 
					
						
							|  |  |  | type ObjectLayer interface { | 
					
						
							| 
									
										
										
										
											2019-11-14 04:17:45 +08:00
										 |  |  | 	// Locking operations on object.
 | 
					
						
							| 
									
										
										
										
											2020-11-05 00:25:42 +08:00
										 |  |  | 	NewNSLock(bucket string, objects ...string) RWLocker | 
					
						
							| 
									
										
										
										
											2019-11-14 04:17:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-27 05:13:10 +08:00
										 |  |  | 	// Storage operations.
 | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	Shutdown(context.Context) error | 
					
						
							| 
									
										
										
										
											2021-02-27 07:11:42 +08:00
										 |  |  | 	NSScanner(ctx context.Context, bf *bloomFilter, updates chan<- DataUsageInfo) error | 
					
						
							| 
									
										
										
										
											2020-12-22 01:35:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 06:36:23 +08:00
										 |  |  | 	BackendInfo() madmin.BackendInfo | 
					
						
							| 
									
										
										
										
											2021-03-03 09:28:04 +08:00
										 |  |  | 	StorageInfo(ctx context.Context) (StorageInfo, []error) | 
					
						
							|  |  |  | 	LocalStorageInfo(ctx context.Context) (StorageInfo, []error) | 
					
						
							| 
									
										
										
										
											2016-05-27 05:13:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | 	// Bucket operations.
 | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	MakeBucketWithLocation(ctx context.Context, bucket string, opts BucketOptions) error | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	GetBucketInfo(ctx context.Context, bucket string) (bucketInfo BucketInfo, err error) | 
					
						
							|  |  |  | 	ListBuckets(ctx context.Context) (buckets []BucketInfo, err error) | 
					
						
							| 
									
										
										
										
											2020-03-28 12:52:59 +08:00
										 |  |  | 	DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	ListObjects(ctx context.Context, bucket, prefix, marker, delimiter string, maxKeys int) (result ListObjectsInfo, err error) | 
					
						
							|  |  |  | 	ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (result ListObjectsV2Info, err error) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	ListObjectVersions(ctx context.Context, bucket, prefix, marker, versionMarker, delimiter string, maxKeys int) (result ListObjectVersionsInfo, err error) | 
					
						
							|  |  |  | 	// Walk lists all objects including versions, delete markers.
 | 
					
						
							| 
									
										
										
										
											2020-07-11 13:21:04 +08:00
										 |  |  | 	Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Object operations.
 | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-21 10:22:09 +08:00
										 |  |  | 	// GetObjectNInfo returns a GetObjectReader that satisfies the
 | 
					
						
							|  |  |  | 	// ReadCloser interface. The Close method unlocks the object
 | 
					
						
							|  |  |  | 	// after reading, so it must always be called after usage.
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// IMPORTANTLY, when implementations return err != nil, this
 | 
					
						
							|  |  |  | 	// function MUST NOT return a non-nil ReadCloser.
 | 
					
						
							| 
									
										
										
										
											2018-09-27 18:06:45 +08:00
										 |  |  | 	GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (reader *GetObjectReader, err error) | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | 	GetObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) | 
					
						
							| 
									
										
										
										
											2019-02-09 13:31:06 +08:00
										 |  |  | 	PutObject(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | 	CopyObject(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (objInfo ObjectInfo, err error) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	DeleteObject(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) | 
					
						
							|  |  |  | 	DeleteObjects(ctx context.Context, bucket string, objects []ObjectToDelete, opts ObjectOptions) ([]DeletedObject, []error) | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Multipart operations.
 | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	ListMultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, err error) | 
					
						
							| 
									
										
										
										
											2019-02-09 13:31:06 +08:00
										 |  |  | 	NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (uploadID string, err error) | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	CopyObjectPart(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, uploadID string, partID int, | 
					
						
							| 
									
										
										
										
											2018-09-11 00:42:43 +08:00
										 |  |  | 		startOffset int64, length int64, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (info PartInfo, err error) | 
					
						
							| 
									
										
										
										
											2018-11-15 09:36:41 +08:00
										 |  |  | 	PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, data *PutObjReader, opts ObjectOptions) (info PartInfo, err error) | 
					
						
							| 
									
										
										
										
											2020-05-29 03:36:20 +08:00
										 |  |  | 	GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (info MultipartInfo, err error) | 
					
						
							| 
									
										
										
										
											2019-01-06 06:16:43 +08:00
										 |  |  | 	ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker int, maxParts int, opts ObjectOptions) (result ListPartsInfo, err error) | 
					
						
							| 
									
										
										
										
											2020-09-15 06:57:13 +08:00
										 |  |  | 	AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) error | 
					
						
							| 
									
										
										
										
											2018-11-15 09:36:41 +08:00
										 |  |  | 	CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart, opts ObjectOptions) (objInfo ObjectInfo, err error) | 
					
						
							| 
									
										
										
										
											2016-10-15 10:57:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 07:19:30 +08:00
										 |  |  | 	// Policy operations
 | 
					
						
							| 
									
										
										
										
											2018-04-25 06:53:30 +08:00
										 |  |  | 	SetBucketPolicy(context.Context, string, *policy.Policy) error | 
					
						
							|  |  |  | 	GetBucketPolicy(context.Context, string) (*policy.Policy, error) | 
					
						
							| 
									
										
										
										
											2018-03-15 03:01:47 +08:00
										 |  |  | 	DeleteBucketPolicy(context.Context, string) error | 
					
						
							| 
									
										
										
										
											2018-02-10 07:19:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Supported operations check
 | 
					
						
							|  |  |  | 	IsNotificationSupported() bool | 
					
						
							| 
									
										
										
										
											2020-07-21 03:52:49 +08:00
										 |  |  | 	IsListenSupported() bool | 
					
						
							| 
									
										
										
										
											2018-02-10 07:19:30 +08:00
										 |  |  | 	IsEncryptionSupported() bool | 
					
						
							| 
									
										
										
										
											2020-06-04 04:18:54 +08:00
										 |  |  | 	IsTaggingSupported() bool | 
					
						
							| 
									
										
										
										
											2018-09-28 11:36:17 +08:00
										 |  |  | 	IsCompressionSupported() bool | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-23 04:09:24 +08:00
										 |  |  | 	SetDriveCounts() []int // list of erasure stripe size for each pool in order.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Healing operations.
 | 
					
						
							|  |  |  | 	HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error) | 
					
						
							|  |  |  | 	HealBucket(ctx context.Context, bucket string, opts madmin.HealOpts) (madmin.HealResultItem, error) | 
					
						
							|  |  |  | 	HealObject(ctx context.Context, bucket, object, versionID string, opts madmin.HealOpts) (madmin.HealResultItem, error) | 
					
						
							|  |  |  | 	HealObjects(ctx context.Context, bucket, prefix string, opts madmin.HealOpts, fn HealObjectFn) error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-06 15:16:06 +08:00
										 |  |  | 	// Backend related metrics
 | 
					
						
							| 
									
										
										
										
											2021-01-19 12:35:38 +08:00
										 |  |  | 	GetMetrics(ctx context.Context) (*BackendMetrics, error) | 
					
						
							| 
									
										
										
										
											2019-12-29 00:54:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 09:31:22 +08:00
										 |  |  | 	// Returns health of the backend
 | 
					
						
							|  |  |  | 	Health(ctx context.Context, opts HealthOptions) HealthResult | 
					
						
							| 
									
										
										
										
											2021-02-09 17:00:44 +08:00
										 |  |  | 	ReadHealth(ctx context.Context) bool | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ObjectTagging operations
 | 
					
						
							| 
									
										
										
										
											2021-02-02 05:52:51 +08:00
										 |  |  | 	PutObjectTags(context.Context, string, string, string, ObjectOptions) (ObjectInfo, error) | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	GetObjectTags(context.Context, string, string, ObjectOptions) (*tags.Tags, error) | 
					
						
							| 
									
										
										
										
											2021-02-02 05:52:51 +08:00
										 |  |  | 	DeleteObjectTags(context.Context, string, string, ObjectOptions) (ObjectInfo, error) | 
					
						
							| 
									
										
										
										
											2016-04-30 05:24:10 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-02-27 01:52:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // GetObject - TODO(aead): This function just acts as an adapter for GetObject tests and benchmarks
 | 
					
						
							|  |  |  | // since the GetObject method of the ObjectLayer interface has been removed. Once, the
 | 
					
						
							|  |  |  | // tests are adjusted to use GetObjectNInfo this function can be removed.
 | 
					
						
							|  |  |  | func GetObject(ctx context.Context, api ObjectLayer, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) (err error) { | 
					
						
							|  |  |  | 	var header http.Header | 
					
						
							|  |  |  | 	if etag != "" { | 
					
						
							|  |  |  | 		header.Set("ETag", etag) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Range := &HTTPRangeSpec{Start: startOffset, End: startOffset + length} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	reader, err := api.GetObjectNInfo(ctx, bucket, object, Range, header, readLock, opts) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer reader.Close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = io.Copy(writer, reader) | 
					
						
							|  |  |  | 	return err | 
					
						
							|  |  |  | } |