storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/object-api-interface.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "context" 21 "io" 22 "net/http" 23 "time" 24 25 "github.com/minio/minio-go/v7/pkg/encrypt" 26 "github.com/minio/minio-go/v7/pkg/tags" 27 28 "storj.io/minio/pkg/bucket/policy" 29 "storj.io/minio/pkg/madmin" 30 ) 31 32 // CheckPreconditionFn returns true if precondition check failed. 33 type CheckPreconditionFn func(o ObjectInfo) bool 34 35 // GetObjectInfoFn is the signature of GetObjectInfo function. 36 type GetObjectInfoFn func(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) 37 38 // ObjectOptions represents object options for ObjectLayer object operations 39 type ObjectOptions struct { 40 ServerSideEncryption encrypt.ServerSide 41 VersionSuspended bool // indicates if the bucket was previously versioned but is currently suspended. 42 Versioned bool // indicates if the bucket is versioned 43 WalkVersions bool // indicates if the we are interested in walking versions 44 VersionID string // Specifies the versionID which needs to be overwritten or read 45 MTime time.Time // Is only set in POST/PUT operations 46 Expires time.Time // Is only used in POST/PUT operations 47 48 DeleteMarker bool // Is only set in DELETE operations for delete marker replication 49 UserDefined map[string]string // only set in case of POST/PUT operations 50 PartNumber int // only useful in case of GetObject/HeadObject 51 CheckPrecondFn CheckPreconditionFn // only set during GetObject/HeadObject/CopyObjectPart preconditional valuation 52 DeleteMarkerReplicationStatus string // Is only set in DELETE operations 53 VersionPurgeStatus VersionPurgeStatusType // Is only set in DELETE operations for delete marker version to be permanently deleted. 54 TransitionStatus string // status of the transition 55 NoLock bool // indicates to lower layers if the caller is expecting to hold locks. 56 ProxyRequest bool // only set for GET/HEAD in active-active replication scenario 57 ProxyHeaderSet bool // only set for GET/HEAD in active-active replication scenario 58 ParentIsObject func(ctx context.Context, bucket, parent string) bool // Used to verify if parent is an object. 59 60 // Use the maximum parity (N/2), used when 61 // saving server configuration files 62 MaxParity bool 63 } 64 65 // BucketOptions represents bucket options for ObjectLayer bucket operations 66 type BucketOptions struct { 67 Location string 68 LockEnabled bool 69 VersioningEnabled bool 70 } 71 72 // LockType represents required locking for ObjectLayer operations 73 type LockType int 74 75 const ( 76 noLock LockType = iota 77 readLock 78 writeLock 79 ) 80 81 // BackendMetrics - represents bytes served from backend 82 type BackendMetrics struct { 83 bytesReceived uint64 84 bytesSent uint64 85 requestStats RequestStats 86 } 87 88 // ObjectLayer implements primitives for object API layer. 89 type ObjectLayer interface { 90 // Locking operations on object. 91 NewNSLock(bucket string, objects ...string) RWLocker 92 93 // Storage operations. 94 Shutdown(context.Context) error 95 NSScanner(ctx context.Context, bf *bloomFilter, updates chan<- madmin.DataUsageInfo) error 96 97 BackendInfo() madmin.BackendInfo 98 StorageInfo(ctx context.Context) (StorageInfo, []error) 99 LocalStorageInfo(ctx context.Context) (StorageInfo, []error) 100 101 // Bucket operations. 102 MakeBucketWithLocation(ctx context.Context, bucket string, opts BucketOptions) error 103 GetBucketInfo(ctx context.Context, bucket string) (bucketInfo BucketInfo, err error) 104 ListBuckets(ctx context.Context) (buckets []BucketInfo, err error) 105 DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error 106 ListObjects(ctx context.Context, bucket, prefix, marker, delimiter string, maxKeys int) (result ListObjectsInfo, err error) 107 ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (result ListObjectsV2Info, err error) 108 ListObjectVersions(ctx context.Context, bucket, prefix, marker, versionMarker, delimiter string, maxKeys int) (result ListObjectVersionsInfo, err error) 109 // Walk lists all objects including versions, delete markers. 110 Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error 111 112 // Object operations. 113 114 // GetObjectNInfo returns a GetObjectReader that satisfies the 115 // ReadCloser interface. The Close method unlocks the object 116 // after reading, so it must always be called after usage. 117 // 118 // IMPORTANTLY, when implementations return err != nil, this 119 // function MUST NOT return a non-nil ReadCloser. 120 GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec, h http.Header, lockType LockType, opts ObjectOptions) (reader *GetObjectReader, err error) 121 GetObjectInfo(ctx context.Context, bucket, object string, opts ObjectOptions) (objInfo ObjectInfo, err error) 122 PutObject(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) (objInfo ObjectInfo, err error) 123 CopyObject(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (objInfo ObjectInfo, err error) 124 DeleteObject(ctx context.Context, bucket, object string, opts ObjectOptions) (ObjectInfo, error) 125 DeleteObjects(ctx context.Context, bucket string, objects []ObjectToDelete, opts ObjectOptions) ([]DeletedObject, []error) 126 127 // Multipart operations. 128 ListMultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (result ListMultipartsInfo, err error) 129 NewMultipartUpload(ctx context.Context, bucket, object string, opts ObjectOptions) (uploadID string, err error) 130 CopyObjectPart(ctx context.Context, srcBucket, srcObject, destBucket, destObject string, uploadID string, partID int, 131 startOffset int64, length int64, srcInfo ObjectInfo, srcOpts, dstOpts ObjectOptions) (info PartInfo, err error) 132 PutObjectPart(ctx context.Context, bucket, object, uploadID string, partID int, data *PutObjReader, opts ObjectOptions) (info PartInfo, err error) 133 GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) (info MultipartInfo, err error) 134 ListObjectParts(ctx context.Context, bucket, object, uploadID string, partNumberMarker int, maxParts int, opts ObjectOptions) (result ListPartsInfo, err error) 135 AbortMultipartUpload(ctx context.Context, bucket, object, uploadID string, opts ObjectOptions) error 136 CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart, opts ObjectOptions) (objInfo ObjectInfo, err error) 137 138 // Policy operations 139 SetBucketPolicy(context.Context, string, *policy.Policy) error 140 GetBucketPolicy(context.Context, string) (*policy.Policy, error) 141 DeleteBucketPolicy(context.Context, string) error 142 143 // Supported operations check 144 IsNotificationSupported() bool 145 IsListenSupported() bool 146 IsEncryptionSupported() bool 147 IsTaggingSupported() bool 148 IsCompressionSupported() bool 149 150 SetDriveCounts() []int // list of erasure stripe size for each pool in order. 151 152 // Healing operations. 153 HealFormat(ctx context.Context, dryRun bool) (madmin.HealResultItem, error) 154 HealBucket(ctx context.Context, bucket string, opts madmin.HealOpts) (madmin.HealResultItem, error) 155 HealObject(ctx context.Context, bucket, object, versionID string, opts madmin.HealOpts) (madmin.HealResultItem, error) 156 HealObjects(ctx context.Context, bucket, prefix string, opts madmin.HealOpts, fn HealObjectFn) error 157 158 // Backend related metrics 159 GetMetrics(ctx context.Context) (*BackendMetrics, error) 160 161 // Returns health of the backend 162 Health(ctx context.Context, opts HealthOptions) HealthResult 163 ReadHealth(ctx context.Context) bool 164 165 // Metadata operations 166 PutObjectMetadata(context.Context, string, string, ObjectOptions) (ObjectInfo, error) 167 168 // ObjectTagging operations 169 PutObjectTags(context.Context, string, string, string, ObjectOptions) (ObjectInfo, error) 170 GetObjectTags(context.Context, string, string, ObjectOptions) (*tags.Tags, error) 171 DeleteObjectTags(context.Context, string, string, ObjectOptions) (ObjectInfo, error) 172 } 173 174 // GetObject - TODO(aead): This function just acts as an adapter for GetObject tests and benchmarks 175 // since the GetObject method of the ObjectLayer interface has been removed. Once, the 176 // tests are adjusted to use GetObjectNInfo this function can be removed. 177 func GetObject(ctx context.Context, api ObjectLayer, bucket, object string, startOffset int64, length int64, writer io.Writer, etag string, opts ObjectOptions) (err error) { 178 var header http.Header 179 if etag != "" { 180 header.Set("ETag", etag) 181 } 182 Range := &HTTPRangeSpec{Start: startOffset, End: startOffset + length} 183 184 reader, err := api.GetObjectNInfo(ctx, bucket, object, Range, header, readLock, opts) 185 if err != nil { 186 return err 187 } 188 defer reader.Close() 189 190 _, err = io.Copy(writer, reader) 191 return err 192 }