storj.io/uplink@v1.13.0/private/metaclient/types.go (about) 1 // Copyright (C) 2020 Storj Labs, Inc. 2 // See LICENSE for copying information. 3 4 package metaclient 5 6 import ( 7 "time" 8 9 "github.com/zeebo/errs" 10 11 "storj.io/common/pb" 12 "storj.io/common/storj" 13 ) 14 15 // RawObjectItem represents raw object item from get request. 16 type RawObjectItem struct { 17 Bucket string 18 EncryptedObjectKey []byte 19 Version []byte 20 StreamID storj.StreamID 21 Status int32 22 23 Created time.Time 24 Expires time.Time 25 26 PlainSize int64 27 28 EncryptedMetadataNonce storj.Nonce 29 EncryptedMetadataEncryptedKey []byte 30 EncryptedMetadata []byte 31 32 EncryptionParameters storj.EncryptionParameters 33 RedundancyScheme storj.RedundancyScheme 34 35 Retention *Retention 36 } 37 38 // Retention represents an object's Object Lock retention information. 39 type Retention struct { 40 Mode storj.RetentionMode 41 RetainUntil time.Time 42 } 43 44 // IsDeleteMarker returns true if object is a delete marker. 45 func (r RawObjectItem) IsDeleteMarker() bool { 46 return r.Status == int32(pb.Object_DELETE_MARKER_UNVERSIONED) || r.Status == int32(pb.Object_DELETE_MARKER_VERSIONED) 47 } 48 49 // IsPrefix returns true if object is a prefix. 50 func (r RawObjectItem) IsPrefix() bool { 51 return r.Status == int32(pb.Object_PREFIX) 52 } 53 54 // RawObjectListItem represents raw object item from list objects request. 55 type RawObjectListItem struct { 56 Bucket string 57 EncryptedObjectKey []byte 58 Version []byte 59 StreamID storj.StreamID 60 Status int32 61 62 CreatedAt time.Time 63 ExpiresAt time.Time 64 65 PlainSize int64 66 67 EncryptedMetadataNonce storj.Nonce 68 EncryptedMetadataEncryptedKey []byte 69 EncryptedMetadata []byte 70 71 IsPrefix bool 72 } 73 74 // IsDeleteMarker returns true if listed object item is a delete marker. 75 func (r RawObjectListItem) IsDeleteMarker() bool { 76 return r.Status == int32(pb.Object_DELETE_MARKER_UNVERSIONED) || r.Status == int32(pb.Object_DELETE_MARKER_VERSIONED) 77 } 78 79 // SegmentPosition the segment position within its parent object. 80 // It is an identifier for the segment. 81 type SegmentPosition struct { 82 // PartNumber indicates the ordinal of the part within an object. 83 // A part contains one or more segments. 84 // PartNumber is defined by the user. 85 // This is only relevant for multipart objects. 86 // A non-multipart object only has one Part, and its number is 0. 87 PartNumber int32 88 // Index indicates the ordinal of this segment within a part. 89 // Index is managed by uplink. 90 // It is zero-indexed within each part. 91 Index int32 92 } 93 94 // SegmentDownloadResponseInfo represents segment download information inline/remote. 95 type SegmentDownloadResponseInfo struct { 96 SegmentID storj.SegmentID 97 EncryptedSize int64 98 EncryptedInlineData []byte 99 Next SegmentPosition 100 Position SegmentPosition 101 PiecePrivateKey storj.PiecePrivateKey 102 103 SegmentEncryption SegmentEncryption 104 } 105 106 // SegmentEncryption represents segment encryption key and nonce. 107 type SegmentEncryption struct { 108 EncryptedKeyNonce storj.Nonce 109 EncryptedKey storj.EncryptedPrivateKey 110 } 111 112 var ( 113 // ErrNoPath is an error class for using empty path. 114 ErrNoPath = errs.Class("no path specified") 115 116 // ErrObjectNotFound is an error class for non-existing object. 117 ErrObjectNotFound = errs.Class("object not found") 118 119 // ErrUploadIDInvalid is an error class for invalid upload ID. 120 ErrUploadIDInvalid = errs.Class("upload ID invalid") 121 ) 122 123 // Object contains information about a specific object. 124 type Object struct { 125 Version []byte 126 Bucket Bucket 127 Path string 128 IsPrefix bool 129 IsDeleteMarker bool 130 131 Metadata map[string]string 132 133 ContentType string 134 Created time.Time 135 Modified time.Time 136 Expires time.Time 137 138 Retention *Retention 139 140 Stream 141 } 142 143 // Stream is information about an object stream. 144 type Stream struct { 145 ID storj.StreamID 146 147 // Size is the total size of the stream in bytes 148 Size int64 149 150 // SegmentCount is the number of segments 151 SegmentCount int64 152 // FixedSegmentSize is the size of each segment, 153 // when all segments have the same size. It is -1 otherwise. 154 FixedSegmentSize int64 155 156 // RedundancyScheme specifies redundancy strategy used for this stream 157 storj.RedundancyScheme 158 // EncryptionParameters specifies encryption strategy used for this stream 159 storj.EncryptionParameters 160 161 LastSegment LastSegment // TODO: remove 162 } 163 164 // LastSegment contains info about last segment. 165 type LastSegment struct { 166 Size int64 167 EncryptedKeyNonce storj.Nonce 168 EncryptedKey storj.EncryptedPrivateKey 169 } 170 171 var ( 172 // ErrBucket is an error class for general bucket errors. 173 ErrBucket = errs.Class("bucket") 174 175 // ErrNoBucket is an error class for using empty bucket name. 176 ErrNoBucket = errs.Class("no bucket specified") 177 178 // ErrBucketNotFound is an error class for non-existing bucket. 179 ErrBucketNotFound = errs.Class("bucket not found") 180 ) 181 182 // Bucket contains information about a specific bucket. 183 type Bucket struct { 184 Name string 185 Created time.Time 186 Attribution string 187 } 188 189 // ListDirection specifies listing direction. 190 type ListDirection = pb.ListDirection 191 192 const ( 193 // Forward lists forwards from cursor, including cursor. 194 Forward = pb.ListDirection_FORWARD 195 // After lists forwards from cursor, without cursor. 196 After = pb.ListDirection_AFTER 197 ) 198 199 // ListOptions lists objects. 200 type ListOptions struct { 201 Prefix storj.Path 202 Cursor storj.Path // Cursor is relative to Prefix, full path is Prefix + Cursor 203 CursorEnc []byte 204 VersionCursor []byte 205 Delimiter rune 206 Recursive bool 207 Direction ListDirection 208 Limit int 209 IncludeCustomMetadata bool 210 IncludeSystemMetadata bool 211 Status int32 212 IncludeAllVersions bool 213 } 214 215 // NextPage returns options for listing the next page. 216 func (opts ListOptions) NextPage(list ObjectList) ListOptions { 217 if !list.More || len(list.Items) == 0 { 218 return ListOptions{} 219 } 220 221 return ListOptions{ 222 Prefix: opts.Prefix, 223 CursorEnc: list.Cursor, 224 VersionCursor: list.VersionCursor, 225 Delimiter: opts.Delimiter, 226 Recursive: opts.Recursive, 227 IncludeAllVersions: opts.IncludeAllVersions, 228 IncludeSystemMetadata: opts.IncludeSystemMetadata, 229 IncludeCustomMetadata: opts.IncludeCustomMetadata, 230 Direction: After, 231 Limit: opts.Limit, 232 Status: opts.Status, 233 } 234 } 235 236 // ObjectList is a list of objects. 237 type ObjectList struct { 238 Bucket string 239 Prefix string 240 More bool 241 Cursor []byte 242 VersionCursor []byte 243 244 // Items paths are relative to Prefix 245 // To get the full path use list.Prefix + list.Items[0].Path 246 Items []Object 247 } 248 249 // BucketList is a list of buckets. 250 type BucketList struct { 251 More bool 252 Items []Bucket 253 } 254 255 // BucketListOptions lists objects. 256 type BucketListOptions struct { 257 Cursor string 258 Direction ListDirection 259 Limit int 260 } 261 262 // NextPage returns options for listing the next page. 263 func (opts BucketListOptions) NextPage(list BucketList) BucketListOptions { 264 if !list.More || len(list.Items) == 0 { 265 return BucketListOptions{} 266 } 267 268 return BucketListOptions{ 269 Cursor: list.Items[len(list.Items)-1].Name, 270 Direction: After, 271 Limit: opts.Limit, 272 } 273 }