github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/client.go (about)

     1  // Copyright (c) 2015-2022 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"context"
    22  	"io"
    23  	"net/http"
    24  	"os"
    25  	"time"
    26  
    27  	"github.com/minio/mc/pkg/probe"
    28  	"github.com/minio/minio-go/v7"
    29  	"github.com/minio/minio-go/v7/pkg/encrypt"
    30  	"github.com/minio/minio-go/v7/pkg/lifecycle"
    31  	"github.com/minio/minio-go/v7/pkg/replication"
    32  )
    33  
    34  // DirOpt - list directory option.
    35  type DirOpt int8
    36  
    37  const (
    38  	// DirNone - do not include directories in the list.
    39  	DirNone DirOpt = iota
    40  	// DirFirst - include directories before objects in the list.
    41  	DirFirst
    42  	// DirLast - include directories after objects in the list.
    43  	DirLast
    44  )
    45  
    46  // GetOptions holds options of the GET operation
    47  type GetOptions struct {
    48  	SSE        encrypt.ServerSide
    49  	VersionID  string
    50  	Zip        bool
    51  	RangeStart int64
    52  	Preserve   bool
    53  }
    54  
    55  // PutOptions holds options for PUT operation
    56  type PutOptions struct {
    57  	metadata              map[string]string
    58  	sse                   encrypt.ServerSide
    59  	md5, disableMultipart bool
    60  	isPreserve            bool
    61  	storageClass          string
    62  	multipartSize         uint64
    63  	multipartThreads      uint
    64  	concurrentStream      bool
    65  }
    66  
    67  // StatOptions holds options of the HEAD operation
    68  type StatOptions struct {
    69  	incomplete         bool
    70  	preserve           bool
    71  	sse                encrypt.ServerSide
    72  	timeRef            time.Time
    73  	versionID          string
    74  	isZip              bool
    75  	ignoreBucketExists bool
    76  }
    77  
    78  // BucketStatOptions - bucket stat.
    79  type BucketStatOptions struct {
    80  	bucket             string
    81  	ignoreBucketExists bool
    82  }
    83  
    84  // ListOptions holds options for listing operation
    85  type ListOptions struct {
    86  	Recursive         bool
    87  	Incomplete        bool
    88  	WithMetadata      bool
    89  	WithOlderVersions bool
    90  	WithDeleteMarkers bool
    91  	ListZip           bool
    92  	TimeRef           time.Time
    93  	ShowDir           DirOpt
    94  	Count             int
    95  }
    96  
    97  // CopyOptions holds options for copying operation
    98  type CopyOptions struct {
    99  	versionID        string
   100  	size             int64
   101  	srcSSE, tgtSSE   encrypt.ServerSide
   102  	metadata         map[string]string
   103  	disableMultipart bool
   104  	isPreserve       bool
   105  	storageClass     string
   106  }
   107  
   108  // Client - client interface
   109  type Client interface {
   110  	// Common operations
   111  	Stat(ctx context.Context, opts StatOptions) (content *ClientContent, err *probe.Error)
   112  	List(ctx context.Context, opts ListOptions) <-chan *ClientContent
   113  
   114  	// Bucket operations
   115  	MakeBucket(ctx context.Context, region string, ignoreExisting, withLock bool) *probe.Error
   116  	RemoveBucket(ctx context.Context, forceRemove bool) *probe.Error
   117  	ListBuckets(ctx context.Context) ([]*ClientContent, *probe.Error)
   118  
   119  	// Object lock config
   120  	SetObjectLockConfig(ctx context.Context, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) *probe.Error
   121  	GetObjectLockConfig(ctx context.Context) (status string, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, perr *probe.Error)
   122  
   123  	// Access policy operations.
   124  	GetAccess(ctx context.Context) (access, policyJSON string, error *probe.Error)
   125  	GetAccessRules(ctx context.Context) (policyRules map[string]string, error *probe.Error)
   126  	SetAccess(ctx context.Context, access string, isJSON bool) *probe.Error
   127  
   128  	// I/O operations
   129  	Copy(ctx context.Context, source string, opts CopyOptions, progress io.Reader) *probe.Error
   130  
   131  	// Runs select expression on object storage on specific files.
   132  	Select(ctx context.Context, expression string, sse encrypt.ServerSide, opts SelectObjectOpts) (io.ReadCloser, *probe.Error)
   133  
   134  	// I/O operations with metadata.
   135  	Get(ctx context.Context, opts GetOptions) (reader io.ReadCloser, content *ClientContent, err *probe.Error)
   136  	Put(ctx context.Context, reader io.Reader, size int64, progress io.Reader, opts PutOptions) (n int64, err *probe.Error)
   137  
   138  	// Object Locking related API
   139  	PutObjectRetention(ctx context.Context, versionID string, mode minio.RetentionMode, retainUntilDate time.Time, bypassGovernance bool) *probe.Error
   140  	GetObjectRetention(ctx context.Context, versionID string) (minio.RetentionMode, time.Time, *probe.Error)
   141  	PutObjectLegalHold(ctx context.Context, versionID string, hold minio.LegalHoldStatus) *probe.Error
   142  	GetObjectLegalHold(ctx context.Context, versionID string) (minio.LegalHoldStatus, *probe.Error)
   143  
   144  	// I/O operations with expiration
   145  	ShareDownload(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error)
   146  	ShareUpload(context.Context, bool, time.Duration, string) (string, map[string]string, *probe.Error)
   147  
   148  	// Watch events
   149  	Watch(ctx context.Context, options WatchOptions) (*WatchObject, *probe.Error)
   150  
   151  	// Delete operations
   152  	Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, isForceDel bool, contentCh <-chan *ClientContent) (errorCh <-chan RemoveResult)
   153  	// GetURL returns back internal url
   154  	GetURL() ClientURL
   155  	AddUserAgent(app, version string)
   156  
   157  	// Tagging operations
   158  	GetTags(ctx context.Context, versionID string) (map[string]string, *probe.Error)
   159  	SetTags(ctx context.Context, versionID, tags string) *probe.Error
   160  	DeleteTags(ctx context.Context, versionID string) *probe.Error
   161  
   162  	// Lifecycle operations
   163  	GetLifecycle(ctx context.Context) (*lifecycle.Configuration, time.Time, *probe.Error)
   164  	SetLifecycle(ctx context.Context, config *lifecycle.Configuration) *probe.Error
   165  
   166  	// Versioning operations
   167  	GetVersion(ctx context.Context) (minio.BucketVersioningConfiguration, *probe.Error)
   168  	SetVersion(ctx context.Context, status string, prefixes []string, excludeFolders bool) *probe.Error
   169  	// Replication operations
   170  	GetReplication(ctx context.Context) (replication.Config, *probe.Error)
   171  	SetReplication(ctx context.Context, cfg *replication.Config, opts replication.Options) *probe.Error
   172  	RemoveReplication(ctx context.Context) *probe.Error
   173  	GetReplicationMetrics(ctx context.Context) (replication.MetricsV2, *probe.Error)
   174  	ResetReplication(ctx context.Context, before time.Duration, arn string) (replication.ResyncTargetsInfo, *probe.Error)
   175  	ReplicationResyncStatus(ctx context.Context, arn string) (rinfo replication.ResyncTargetsInfo, err *probe.Error)
   176  
   177  	// Encryption operations
   178  	GetEncryption(ctx context.Context) (string, string, *probe.Error)
   179  	SetEncryption(ctx context.Context, algorithm, kmsKeyID string) *probe.Error
   180  	DeleteEncryption(ctx context.Context) *probe.Error
   181  	// Bucket info operation
   182  	GetBucketInfo(ctx context.Context) (BucketInfo, *probe.Error)
   183  
   184  	// Restore an object
   185  	Restore(ctx context.Context, versionID string, days int) *probe.Error
   186  
   187  	// OD operations
   188  	GetPart(ctx context.Context, part int) (io.ReadCloser, *probe.Error)
   189  	PutPart(ctx context.Context, reader io.Reader, size int64, progress io.Reader, opts PutOptions) (n int64, err *probe.Error)
   190  }
   191  
   192  // ClientContent - Content container for content metadata
   193  type ClientContent struct {
   194  	URL          ClientURL
   195  	BucketName   string // only valid and set for client-type objectStorage
   196  	Time         time.Time
   197  	Size         int64
   198  	Type         os.FileMode
   199  	StorageClass string
   200  	Metadata     map[string]string
   201  	Tags         map[string]string
   202  	UserMetadata map[string]string
   203  	ETag         string
   204  	Expires      time.Time
   205  
   206  	Expiration       time.Time
   207  	ExpirationRuleID string
   208  
   209  	RetentionEnabled  bool
   210  	RetentionMode     string
   211  	RetentionDuration string
   212  	BypassGovernance  bool
   213  	LegalHoldEnabled  bool
   214  	LegalHold         string
   215  	VersionID         string
   216  	IsDeleteMarker    bool
   217  	IsLatest          bool
   218  	ReplicationStatus string
   219  
   220  	Restore *minio.RestoreInfo
   221  
   222  	Err *probe.Error
   223  }
   224  
   225  // Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
   226  type Config struct {
   227  	Alias             string
   228  	AccessKey         string
   229  	SecretKey         string
   230  	SessionToken      string
   231  	Signature         string
   232  	HostURL           string
   233  	AppName           string
   234  	AppVersion        string
   235  	Debug             bool
   236  	Insecure          bool
   237  	Lookup            minio.BucketLookupType
   238  	ConnReadDeadline  time.Duration
   239  	ConnWriteDeadline time.Duration
   240  	UploadLimit       int64
   241  	DownloadLimit     int64
   242  	Transport         http.RoundTripper
   243  }
   244  
   245  // SelectObjectOpts - opts entered for select API
   246  type SelectObjectOpts struct {
   247  	InputSerOpts    map[string]map[string]string
   248  	OutputSerOpts   map[string]map[string]string
   249  	CompressionType minio.SelectCompressionType
   250  }