storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/object-api-datatypes.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2016, 2017 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  	"io"
    21  	"math"
    22  	"time"
    23  
    24  	humanize "github.com/dustin/go-humanize"
    25  
    26  	"storj.io/minio/pkg/bucket/replication"
    27  	"storj.io/minio/pkg/hash"
    28  	"storj.io/minio/pkg/madmin"
    29  )
    30  
    31  // BackendType - represents different backend types.
    32  type BackendType int
    33  
    34  // Enum for different backend types.
    35  const (
    36  	Unknown = BackendType(madmin.Unknown)
    37  	// Filesystem backend.
    38  	BackendFS = BackendType(madmin.FS)
    39  	// Multi disk BackendErasure (single, distributed) backend.
    40  	BackendErasure = BackendType(madmin.Erasure)
    41  	// Gateway backend.
    42  	BackendGateway = BackendType(madmin.Gateway)
    43  	// Add your own backend.
    44  )
    45  
    46  // StorageInfo - represents total capacity of underlying storage.
    47  type StorageInfo = madmin.StorageInfo
    48  
    49  // objectHistogramInterval is an interval that will be
    50  // used to report the histogram of objects data sizes
    51  type objectHistogramInterval struct {
    52  	name       string
    53  	start, end int64
    54  }
    55  
    56  const (
    57  	// dataUsageBucketLen must be length of ObjectsHistogramIntervals
    58  	dataUsageBucketLen = 7
    59  )
    60  
    61  // ObjectsHistogramIntervals is the list of all intervals
    62  // of object sizes to be included in objects histogram.
    63  var ObjectsHistogramIntervals = []objectHistogramInterval{
    64  	{"LESS_THAN_1024_B", 0, humanize.KiByte - 1},
    65  	{"BETWEEN_1024_B_AND_1_MB", humanize.KiByte, humanize.MiByte - 1},
    66  	{"BETWEEN_1_MB_AND_10_MB", humanize.MiByte, humanize.MiByte*10 - 1},
    67  	{"BETWEEN_10_MB_AND_64_MB", humanize.MiByte * 10, humanize.MiByte*64 - 1},
    68  	{"BETWEEN_64_MB_AND_128_MB", humanize.MiByte * 64, humanize.MiByte*128 - 1},
    69  	{"BETWEEN_128_MB_AND_512_MB", humanize.MiByte * 128, humanize.MiByte*512 - 1},
    70  	{"GREATER_THAN_512_MB", humanize.MiByte * 512, math.MaxInt64},
    71  }
    72  
    73  // BucketInfo - represents bucket metadata.
    74  type BucketInfo struct {
    75  	// Name of the bucket.
    76  	Name string
    77  
    78  	// Date and time when the bucket was created.
    79  	Created time.Time
    80  }
    81  
    82  // ObjectInfo - represents object metadata.
    83  type ObjectInfo struct {
    84  	// Name of the bucket.
    85  	Bucket string
    86  
    87  	// Name of the object.
    88  	Name string
    89  
    90  	// Date and time when the object was last modified.
    91  	ModTime time.Time
    92  
    93  	// Total object size.
    94  	Size int64
    95  
    96  	// IsDir indicates if the object is prefix.
    97  	IsDir bool
    98  
    99  	// Hex encoded unique entity tag of the object.
   100  	ETag string
   101  
   102  	// The ETag stored in the gateway backend
   103  	InnerETag string
   104  
   105  	// Version ID of this object.
   106  	VersionID string
   107  
   108  	// IsLatest indicates if this is the latest current version
   109  	// latest can be true for delete marker or a version.
   110  	IsLatest bool
   111  
   112  	// DeleteMarker indicates if the versionId corresponds
   113  	// to a delete marker on an object.
   114  	DeleteMarker bool
   115  
   116  	// TransitionStatus indicates if transition is complete/pending
   117  	TransitionStatus string
   118  
   119  	// RestoreExpires indicates date a restored object expires
   120  	RestoreExpires time.Time
   121  
   122  	// RestoreOngoing indicates if a restore is in progress
   123  	RestoreOngoing bool
   124  
   125  	// A standard MIME type describing the format of the object.
   126  	ContentType string
   127  
   128  	// Specifies what content encodings have been applied to the object and thus
   129  	// what decoding mechanisms must be applied to obtain the object referenced
   130  	// by the Content-Type header field.
   131  	ContentEncoding string
   132  
   133  	// Date and time at which the object is no longer able to be cached
   134  	Expires time.Time
   135  
   136  	// CacheStatus sets status of whether this is a cache hit/miss
   137  	CacheStatus CacheStatusType
   138  	// CacheLookupStatus sets whether a cacheable response is present in the cache
   139  	CacheLookupStatus CacheStatusType
   140  
   141  	// Specify object storage class
   142  	StorageClass string
   143  
   144  	ReplicationStatus replication.StatusType
   145  	// User-Defined metadata
   146  	UserDefined map[string]string
   147  
   148  	// User-Defined object tags
   149  	UserTags string
   150  
   151  	// List of individual parts, maximum size of upto 10,000
   152  	Parts []ObjectPartInfo `json:"-"`
   153  
   154  	// Implements writer and reader used by CopyObject API
   155  	Writer       io.WriteCloser `json:"-"`
   156  	Reader       *hash.Reader   `json:"-"`
   157  	PutObjReader *PutObjReader  `json:"-"`
   158  
   159  	metadataOnly bool
   160  	versionOnly  bool // adds a new version, only used by CopyObject
   161  	keyRotation  bool
   162  
   163  	// Date and time when the object was last accessed.
   164  	AccTime time.Time
   165  
   166  	Legacy bool // indicates object on disk is in legacy data format
   167  
   168  	// backendType indicates which backend filled this structure
   169  	backendType BackendType
   170  
   171  	VersionPurgeStatus VersionPurgeStatusType
   172  
   173  	// The total count of all versions of this object
   174  	NumVersions int
   175  	//  The modtime of the successor object version if any
   176  	SuccessorModTime time.Time
   177  }
   178  
   179  // Clone - Returns a cloned copy of current objectInfo
   180  func (o ObjectInfo) Clone() (cinfo ObjectInfo) {
   181  	cinfo = ObjectInfo{
   182  		Bucket:             o.Bucket,
   183  		Name:               o.Name,
   184  		ModTime:            o.ModTime,
   185  		Size:               o.Size,
   186  		IsDir:              o.IsDir,
   187  		ETag:               o.ETag,
   188  		InnerETag:          o.InnerETag,
   189  		VersionID:          o.VersionID,
   190  		IsLatest:           o.IsLatest,
   191  		DeleteMarker:       o.DeleteMarker,
   192  		TransitionStatus:   o.TransitionStatus,
   193  		RestoreExpires:     o.RestoreExpires,
   194  		RestoreOngoing:     o.RestoreOngoing,
   195  		ContentType:        o.ContentType,
   196  		ContentEncoding:    o.ContentEncoding,
   197  		Expires:            o.Expires,
   198  		CacheStatus:        o.CacheStatus,
   199  		CacheLookupStatus:  o.CacheLookupStatus,
   200  		StorageClass:       o.StorageClass,
   201  		ReplicationStatus:  o.ReplicationStatus,
   202  		UserTags:           o.UserTags,
   203  		Parts:              o.Parts,
   204  		Writer:             o.Writer,
   205  		Reader:             o.Reader,
   206  		PutObjReader:       o.PutObjReader,
   207  		metadataOnly:       o.metadataOnly,
   208  		versionOnly:        o.versionOnly,
   209  		keyRotation:        o.keyRotation,
   210  		backendType:        o.backendType,
   211  		AccTime:            o.AccTime,
   212  		Legacy:             o.Legacy,
   213  		VersionPurgeStatus: o.VersionPurgeStatus,
   214  		NumVersions:        o.NumVersions,
   215  		SuccessorModTime:   o.SuccessorModTime,
   216  	}
   217  	cinfo.UserDefined = make(map[string]string, len(o.UserDefined))
   218  	for k, v := range o.UserDefined {
   219  		cinfo.UserDefined[k] = v
   220  	}
   221  	return cinfo
   222  }
   223  
   224  // ReplicateObjectInfo represents object info to be replicated
   225  type ReplicateObjectInfo struct {
   226  	ObjectInfo
   227  	OpType     replication.Type
   228  	RetryCount uint32
   229  }
   230  
   231  // MultipartInfo captures metadata information about the uploadId
   232  // this data structure is used primarily for some internal purposes
   233  // for verifying upload type such as was the upload
   234  // - encrypted
   235  // - compressed
   236  type MultipartInfo struct {
   237  	// Name of the bucket.
   238  	Bucket string
   239  
   240  	// Name of the object.
   241  	Object string
   242  
   243  	// Upload ID identifying the multipart upload whose parts are being listed.
   244  	UploadID string
   245  
   246  	// Date and time at which the multipart upload was initiated.
   247  	Initiated time.Time
   248  
   249  	// Any metadata set during InitMultipartUpload, including encryption headers.
   250  	UserDefined map[string]string
   251  }
   252  
   253  // ListPartsInfo - represents list of all parts.
   254  type ListPartsInfo struct {
   255  	// Name of the bucket.
   256  	Bucket string
   257  
   258  	// Name of the object.
   259  	Object string
   260  
   261  	// Upload ID identifying the multipart upload whose parts are being listed.
   262  	UploadID string
   263  
   264  	// The class of storage used to store the object.
   265  	StorageClass string
   266  
   267  	// Part number after which listing begins.
   268  	PartNumberMarker int
   269  
   270  	// When a list is truncated, this element specifies the last part in the list,
   271  	// as well as the value to use for the part-number-marker request parameter
   272  	// in a subsequent request.
   273  	NextPartNumberMarker int
   274  
   275  	// Maximum number of parts that were allowed in the response.
   276  	MaxParts int
   277  
   278  	// Indicates whether the returned list of parts is truncated.
   279  	IsTruncated bool
   280  
   281  	// List of all parts.
   282  	Parts []PartInfo
   283  
   284  	// Any metadata set during InitMultipartUpload, including encryption headers.
   285  	UserDefined map[string]string
   286  }
   287  
   288  // Lookup - returns if uploadID is valid
   289  func (lm ListMultipartsInfo) Lookup(uploadID string) bool {
   290  	for _, upload := range lm.Uploads {
   291  		if upload.UploadID == uploadID {
   292  			return true
   293  		}
   294  	}
   295  	return false
   296  }
   297  
   298  // ListMultipartsInfo - represnets bucket resources for incomplete multipart uploads.
   299  type ListMultipartsInfo struct {
   300  	// Together with upload-id-marker, this parameter specifies the multipart upload
   301  	// after which listing should begin.
   302  	KeyMarker string
   303  
   304  	// Together with key-marker, specifies the multipart upload after which listing
   305  	// should begin. If key-marker is not specified, the upload-id-marker parameter
   306  	// is ignored.
   307  	UploadIDMarker string
   308  
   309  	// When a list is truncated, this element specifies the value that should be
   310  	// used for the key-marker request parameter in a subsequent request.
   311  	NextKeyMarker string
   312  
   313  	// When a list is truncated, this element specifies the value that should be
   314  	// used for the upload-id-marker request parameter in a subsequent request.
   315  	NextUploadIDMarker string
   316  
   317  	// Maximum number of multipart uploads that could have been included in the
   318  	// response.
   319  	MaxUploads int
   320  
   321  	// Indicates whether the returned list of multipart uploads is truncated. A
   322  	// value of true indicates that the list was truncated. The list can be truncated
   323  	// if the number of multipart uploads exceeds the limit allowed or specified
   324  	// by max uploads.
   325  	IsTruncated bool
   326  
   327  	// List of all pending uploads.
   328  	Uploads []MultipartInfo
   329  
   330  	// When a prefix is provided in the request, The result contains only keys
   331  	// starting with the specified prefix.
   332  	Prefix string
   333  
   334  	// A character used to truncate the object prefixes.
   335  	// NOTE: only supported delimiter is '/'.
   336  	Delimiter string
   337  
   338  	// CommonPrefixes contains all (if there are any) keys between Prefix and the
   339  	// next occurrence of the string specified by delimiter.
   340  	CommonPrefixes []string
   341  
   342  	EncodingType string // Not supported yet.
   343  }
   344  
   345  // DeletedObjectInfo - container for list objects versions deleted objects.
   346  type DeletedObjectInfo struct {
   347  	// Name of the bucket.
   348  	Bucket string
   349  
   350  	// Name of the object.
   351  	Name string
   352  
   353  	// Date and time when the object was last modified.
   354  	ModTime time.Time
   355  
   356  	// Version ID of this object.
   357  	VersionID string
   358  
   359  	// Indicates the deleted marker is latest
   360  	IsLatest bool
   361  }
   362  
   363  // ListObjectVersionsInfo - container for list objects versions.
   364  type ListObjectVersionsInfo struct {
   365  	// Indicates whether the returned list objects response is truncated. A
   366  	// value of true indicates that the list was truncated. The list can be truncated
   367  	// if the number of objects exceeds the limit allowed or specified
   368  	// by max keys.
   369  	IsTruncated bool
   370  
   371  	// When response is truncated (the IsTruncated element value in the response is true),
   372  	// you can use the key name in this field as marker in the subsequent
   373  	// request to get next set of objects.
   374  	//
   375  	// NOTE: AWS S3 returns NextMarker only if you have delimiter request parameter specified,
   376  	//       MinIO always returns NextMarker.
   377  	NextMarker string
   378  
   379  	// NextVersionIDMarker may be set of IsTruncated is true
   380  	NextVersionIDMarker string
   381  
   382  	// List of objects info for this request.
   383  	Objects []ObjectInfo
   384  
   385  	// List of prefixes for this request.
   386  	Prefixes []string
   387  }
   388  
   389  // ListObjectsInfo - container for list objects.
   390  type ListObjectsInfo struct {
   391  	// Indicates whether the returned list objects response is truncated. A
   392  	// value of true indicates that the list was truncated. The list can be truncated
   393  	// if the number of objects exceeds the limit allowed or specified
   394  	// by max keys.
   395  	IsTruncated bool
   396  
   397  	// When response is truncated (the IsTruncated element value in the response is true),
   398  	// you can use the key name in this field as marker in the subsequent
   399  	// request to get next set of objects.
   400  	//
   401  	// NOTE: AWS S3 returns NextMarker only if you have delimiter request parameter specified,
   402  	//       MinIO always returns NextMarker.
   403  	NextMarker string
   404  
   405  	// List of objects info for this request.
   406  	Objects []ObjectInfo
   407  
   408  	// List of prefixes for this request.
   409  	Prefixes []string
   410  }
   411  
   412  // ListObjectsV2Info - container for list objects version 2.
   413  type ListObjectsV2Info struct {
   414  	// Indicates whether the returned list objects response is truncated. A
   415  	// value of true indicates that the list was truncated. The list can be truncated
   416  	// if the number of objects exceeds the limit allowed or specified
   417  	// by max keys.
   418  	IsTruncated bool
   419  
   420  	// When response is truncated (the IsTruncated element value in the response
   421  	// is true), you can use the key name in this field as marker in the subsequent
   422  	// request to get next set of objects.
   423  	//
   424  	// NOTE: This element is returned only if you have delimiter request parameter
   425  	// specified.
   426  	ContinuationToken     string
   427  	NextContinuationToken string
   428  
   429  	// List of objects info for this request.
   430  	Objects []ObjectInfo
   431  
   432  	// List of prefixes for this request.
   433  	Prefixes []string
   434  }
   435  
   436  // PartInfo - represents individual part metadata.
   437  type PartInfo struct {
   438  	// Part number that identifies the part. This is a positive integer between
   439  	// 1 and 10,000.
   440  	PartNumber int
   441  
   442  	// Date and time at which the part was uploaded.
   443  	LastModified time.Time
   444  
   445  	// Entity tag returned when the part was initially uploaded.
   446  	ETag string
   447  
   448  	// Size in bytes of the part.
   449  	Size int64
   450  
   451  	// Decompressed Size.
   452  	ActualSize int64
   453  }
   454  
   455  // CompletePart - represents the part that was completed, this is sent by the client
   456  // during CompleteMultipartUpload request.
   457  type CompletePart struct {
   458  	// Part number identifying the part. This is a positive integer between 1 and
   459  	// 10,000
   460  	PartNumber int
   461  
   462  	// Entity tag returned when the part was uploaded.
   463  	ETag string
   464  }
   465  
   466  // CompletedParts - is a collection satisfying sort.Interface.
   467  type CompletedParts []CompletePart
   468  
   469  func (a CompletedParts) Len() int           { return len(a) }
   470  func (a CompletedParts) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
   471  func (a CompletedParts) Less(i, j int) bool { return a[i].PartNumber < a[j].PartNumber }
   472  
   473  // CompleteMultipartUpload - represents list of parts which are completed, this is sent by the
   474  // client during CompleteMultipartUpload request.
   475  type CompleteMultipartUpload struct {
   476  	Parts []CompletePart `xml:"Part"`
   477  }