2017-12-05 20:58:09 -05:00
|
|
|
/*
|
2020-05-17 11:46:23 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2017-2020 MinIO, Inc.
|
2017-12-05 20:58:09 -05: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
2018-03-14 21:36:54 -04:00
|
|
|
"context"
|
2018-04-15 02:09:48 -04:00
|
|
|
"encoding/json"
|
2017-12-05 20:58:09 -05:00
|
|
|
"io"
|
2018-07-23 13:16:56 -04:00
|
|
|
"math/rand"
|
2018-09-19 08:35:30 -04:00
|
|
|
"net/http"
|
2019-01-23 14:12:33 -05:00
|
|
|
"net/url"
|
2018-04-24 18:53:30 -04:00
|
|
|
"strings"
|
2018-07-23 13:16:56 -04:00
|
|
|
"time"
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
"github.com/minio/cli"
|
2020-07-14 12:38:05 -04:00
|
|
|
miniogo "github.com/minio/minio-go/v7"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/tags"
|
2019-01-05 17:16:43 -05:00
|
|
|
minio "github.com/minio/minio/cmd"
|
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/encrypt"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/s3utils"
|
2020-05-23 14:09:35 -04:00
|
|
|
xhttp "github.com/minio/minio/cmd/http"
|
2018-04-05 18:04:40 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2017-12-05 20:58:09 -05:00
|
|
|
"github.com/minio/minio/pkg/auth"
|
2020-01-27 17:12:34 -05:00
|
|
|
"github.com/minio/minio/pkg/bucket/policy"
|
2017-12-05 20:58:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
const s3GatewayTemplate = `NAME:
|
|
|
|
{{.HelpName}} - {{.Usage}}
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
{{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} [ENDPOINT]
|
|
|
|
{{if .VisibleFlags}}
|
|
|
|
FLAGS:
|
|
|
|
{{range .VisibleFlags}}{{.}}
|
|
|
|
{{end}}{{end}}
|
|
|
|
ENDPOINT:
|
2019-12-16 23:30:57 -05:00
|
|
|
s3 server endpoint. Default ENDPOINT is https://s3.amazonaws.com
|
2018-03-28 17:14:06 -04:00
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
EXAMPLES:
|
2019-12-16 23:30:57 -05:00
|
|
|
1. Start minio gateway server for AWS S3 backend
|
2021-01-05 13:22:57 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_USER{{.AssignmentOperator}}accesskey
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_PASSWORD{{.AssignmentOperator}}secretkey
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.HelpName}}
|
2017-12-05 20:58:09 -05:00
|
|
|
|
2019-12-16 23:30:57 -05:00
|
|
|
2. Start minio gateway server for AWS S3 backend with edge caching enabled
|
2021-01-05 13:22:57 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_USER{{.AssignmentOperator}}accesskey
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_PASSWORD{{.AssignmentOperator}}secretkey
|
2019-11-20 18:10:24 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_DRIVES{{.AssignmentOperator}}"/mnt/drive1,/mnt/drive2,/mnt/drive3,/mnt/drive4"
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_EXCLUDE{{.AssignmentOperator}}"bucket1/*,*.png"
|
2020-02-23 08:33:39 -05:00
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_QUOTA{{.AssignmentOperator}}90
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_AFTER{{.AssignmentOperator}}3
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_LOW{{.AssignmentOperator}}75
|
|
|
|
{{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_HIGH{{.AssignmentOperator}}85
|
2019-05-15 04:32:44 -04:00
|
|
|
{{.Prompt}} {{.HelpName}}
|
2017-12-05 20:58:09 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
minio.RegisterGatewayCommand(cli.Command{
|
2020-08-26 11:52:46 -04:00
|
|
|
Name: minio.S3BackendGateway,
|
2018-11-20 20:35:33 -05:00
|
|
|
Usage: "Amazon Simple Storage Service (S3)",
|
2017-12-05 20:58:09 -05:00
|
|
|
Action: s3GatewayMain,
|
|
|
|
CustomHelpTemplate: s3GatewayTemplate,
|
|
|
|
HideHelpCommand: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handler for 'minio gateway s3' command line.
|
|
|
|
func s3GatewayMain(ctx *cli.Context) {
|
2018-06-18 18:27:14 -04:00
|
|
|
args := ctx.Args()
|
|
|
|
if !ctx.Args().Present() {
|
|
|
|
args = cli.Args{"https://s3.amazonaws.com"}
|
|
|
|
}
|
|
|
|
|
2020-05-17 11:46:23 -04:00
|
|
|
serverAddr := ctx.GlobalString("address")
|
|
|
|
if serverAddr == "" || serverAddr == ":"+minio.GlobalMinioDefaultPort {
|
|
|
|
serverAddr = ctx.String("address")
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
// Validate gateway arguments.
|
2020-05-17 11:46:23 -04:00
|
|
|
logger.FatalIf(minio.ValidateGatewayArguments(serverAddr, args.First()), "Invalid argument")
|
2017-12-05 20:58:09 -05:00
|
|
|
|
2018-06-18 18:27:14 -04:00
|
|
|
// Start the gateway..
|
|
|
|
minio.StartGateway(ctx, &S3{args.First()})
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// S3 implements Gateway.
|
|
|
|
type S3 struct {
|
|
|
|
host string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name implements Gateway interface.
|
|
|
|
func (g *S3) Name() string {
|
2020-08-26 11:52:46 -04:00
|
|
|
return minio.S3BackendGateway
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:16:56 -04:00
|
|
|
const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569"
|
|
|
|
const (
|
2020-02-11 10:38:01 -05:00
|
|
|
letterIdxBits = 6 // 6 bits to represent a letter index
|
|
|
|
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
|
|
|
|
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
2018-07-23 13:16:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// randString generates random names and prepends them with a known prefix.
|
|
|
|
func randString(n int, src rand.Source, prefix string) string {
|
|
|
|
b := make([]byte, n)
|
|
|
|
// A rand.Int63() generates 63 random bits, enough for letterIdxMax letters!
|
|
|
|
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
|
|
|
|
if remain == 0 {
|
|
|
|
cache, remain = src.Int63(), letterIdxMax
|
|
|
|
}
|
|
|
|
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
|
|
|
|
b[i] = letterBytes[idx]
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
cache >>= letterIdxBits
|
|
|
|
remain--
|
|
|
|
}
|
|
|
|
return prefix + string(b[0:30-len(prefix)])
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:35:20 -05:00
|
|
|
// Chains all credential types, in the following order:
|
|
|
|
// - AWS env vars (i.e. AWS_ACCESS_KEY_ID)
|
|
|
|
// - AWS creds file (i.e. AWS_SHARED_CREDENTIALS_FILE or ~/.aws/credentials)
|
2021-01-05 13:22:57 -05:00
|
|
|
// - Static credentials provided by user (i.e. MINIO_ROOT_USER)
|
2019-01-29 05:35:20 -05:00
|
|
|
var defaultProviders = []credentials.Provider{
|
|
|
|
&credentials.EnvAWS{},
|
|
|
|
&credentials.FileAWSCredentials{},
|
2019-01-23 14:12:33 -05:00
|
|
|
&credentials.EnvMinio{},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chains all credential types, in the following order:
|
|
|
|
// - AWS env vars (i.e. AWS_ACCESS_KEY_ID)
|
|
|
|
// - AWS creds file (i.e. AWS_SHARED_CREDENTIALS_FILE or ~/.aws/credentials)
|
|
|
|
// - IAM profile based credentials. (performs an HTTP
|
|
|
|
// call to a pre-defined endpoint, only valid inside
|
|
|
|
// configured ec2 instances)
|
|
|
|
var defaultAWSCredProviders = []credentials.Provider{
|
|
|
|
&credentials.EnvAWS{},
|
|
|
|
&credentials.FileAWSCredentials{},
|
|
|
|
&credentials.IAM{
|
|
|
|
Client: &http.Client{
|
2020-03-22 01:10:13 -04:00
|
|
|
Transport: minio.NewGatewayHTTPTransport(),
|
2019-01-23 14:12:33 -05:00
|
|
|
},
|
|
|
|
},
|
2019-01-29 05:35:20 -05:00
|
|
|
&credentials.EnvMinio{},
|
2019-01-23 14:12:33 -05:00
|
|
|
}
|
|
|
|
|
2018-06-18 18:27:14 -04:00
|
|
|
// newS3 - Initializes a new client by auto probing S3 server signature.
|
2020-07-17 01:38:58 -04:00
|
|
|
func newS3(urlStr string, tripper http.RoundTripper) (*miniogo.Core, error) {
|
2019-01-23 14:12:33 -05:00
|
|
|
if urlStr == "" {
|
|
|
|
urlStr = "https://s3.amazonaws.com"
|
2018-06-18 18:27:14 -04:00
|
|
|
}
|
|
|
|
|
2019-06-07 18:49:13 -04:00
|
|
|
u, err := url.Parse(urlStr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-06-18 18:27:14 -04:00
|
|
|
// Override default params if the host is provided
|
2019-01-23 14:12:33 -05:00
|
|
|
endpoint, secure, err := minio.ParseGatewayEndpoint(urlStr)
|
2018-06-18 18:27:14 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:12:33 -05:00
|
|
|
var creds *credentials.Credentials
|
2019-06-07 18:49:13 -04:00
|
|
|
if s3utils.IsAmazonEndpoint(*u) {
|
2019-01-23 14:12:33 -05:00
|
|
|
// If we see an Amazon S3 endpoint, then we use more ways to fetch backend credentials.
|
2019-01-29 05:35:20 -05:00
|
|
|
// Specifically IAM style rotating credentials are only supported with AWS S3 endpoint.
|
|
|
|
creds = credentials.NewChainCredentials(defaultAWSCredProviders)
|
2019-06-07 18:49:13 -04:00
|
|
|
|
2019-01-23 14:12:33 -05:00
|
|
|
} else {
|
2019-01-29 05:35:20 -05:00
|
|
|
creds = credentials.NewChainCredentials(defaultProviders)
|
2019-01-23 14:12:33 -05:00
|
|
|
}
|
2018-09-19 08:35:30 -04:00
|
|
|
|
2020-07-17 01:38:58 -04:00
|
|
|
options := &miniogo.Options{
|
2019-06-07 18:49:13 -04:00
|
|
|
Creds: creds,
|
|
|
|
Secure: secure,
|
|
|
|
Region: s3utils.GetRegionFromURL(*u),
|
|
|
|
BucketLookup: miniogo.BucketLookupAuto,
|
2020-07-17 01:38:58 -04:00
|
|
|
Transport: tripper,
|
2019-06-07 18:49:13 -04:00
|
|
|
}
|
|
|
|
|
2020-07-17 01:38:58 -04:00
|
|
|
clnt, err := miniogo.New(endpoint, options)
|
2018-06-18 18:27:14 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-19 08:35:30 -04:00
|
|
|
|
2018-06-18 18:27:14 -04:00
|
|
|
return &miniogo.Core{Client: clnt}, nil
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
|
2018-06-18 18:27:14 -04:00
|
|
|
// NewGatewayLayer returns s3 ObjectLayer.
|
|
|
|
func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
|
2019-12-06 02:16:06 -05:00
|
|
|
metrics := minio.NewMetrics()
|
|
|
|
|
2020-02-11 10:38:01 -05:00
|
|
|
t := &minio.MetricsTransport{
|
2020-03-22 01:10:13 -04:00
|
|
|
Transport: minio.NewGatewayHTTPTransport(),
|
2020-02-11 10:38:01 -05:00
|
|
|
Metrics: metrics,
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
2020-07-17 01:38:58 -04:00
|
|
|
// creds are ignored here, since S3 gateway implements chaining
|
|
|
|
// all credentials.
|
|
|
|
clnt, err := newS3(g.host, t)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-12-06 02:16:06 -05:00
|
|
|
|
|
|
|
probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-")
|
|
|
|
|
|
|
|
// Check if the provided keys are valid.
|
2020-07-14 12:38:05 -04:00
|
|
|
if _, err = clnt.BucketExists(context.Background(), probeBucketName); err != nil {
|
2019-12-06 02:16:06 -05:00
|
|
|
if miniogo.ToErrorResponse(err).Code != "AccessDenied" {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 17:16:43 -05:00
|
|
|
s := s3Objects{
|
2019-12-06 02:16:06 -05:00
|
|
|
Client: clnt,
|
|
|
|
Metrics: metrics,
|
2019-11-01 19:58:11 -04:00
|
|
|
HTTPClient: &http.Client{
|
2019-12-06 02:16:06 -05:00
|
|
|
Transport: t,
|
2019-11-01 19:58:11 -04:00
|
|
|
},
|
2019-01-05 17:16:43 -05:00
|
|
|
}
|
2019-11-01 19:58:11 -04:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
// Enables single encryption of KMS is configured.
|
2019-01-05 17:16:43 -05:00
|
|
|
if minio.GlobalKMS != nil {
|
|
|
|
encS := s3EncObjects{s}
|
|
|
|
|
|
|
|
// Start stale enc multipart uploads cleanup routine.
|
2020-04-09 12:30:02 -04:00
|
|
|
go encS.cleanupStaleEncMultipartUploads(minio.GlobalContext,
|
2020-09-08 18:55:40 -04:00
|
|
|
minio.GlobalStaleUploadsCleanupInterval, minio.GlobalStaleUploadsExpiry)
|
2019-01-05 17:16:43 -05:00
|
|
|
|
|
|
|
return &encS, nil
|
|
|
|
}
|
|
|
|
return &s, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2018-04-09 19:33:48 -04:00
|
|
|
// Production - s3 gateway is production ready.
|
2017-12-05 20:58:09 -05:00
|
|
|
func (g *S3) Production() bool {
|
2018-04-09 19:33:48 -04:00
|
|
|
return true
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2019-04-09 14:39:42 -04:00
|
|
|
// s3Objects implements gateway for MinIO and S3 compatible object storage servers.
|
2017-12-05 20:58:09 -05:00
|
|
|
type s3Objects struct {
|
|
|
|
minio.GatewayUnsupported
|
2019-11-01 19:58:11 -04:00
|
|
|
Client *miniogo.Core
|
|
|
|
HTTPClient *http.Client
|
2021-01-18 23:35:38 -05:00
|
|
|
Metrics *minio.BackendMetrics
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetMetrics returns this gateway's metrics
|
2021-01-18 23:35:38 -05:00
|
|
|
func (l *s3Objects) GetMetrics(ctx context.Context) (*minio.BackendMetrics, error) {
|
2019-12-06 02:16:06 -05:00
|
|
|
return l.Metrics, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown saves any gateway metadata to disk
|
|
|
|
// if necessary and reload upon next restart.
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) Shutdown(ctx context.Context) error {
|
2017-12-05 20:58:09 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageInfo is not relevant to S3 backend.
|
2021-01-04 12:42:09 -05:00
|
|
|
func (l *s3Objects) StorageInfo(ctx context.Context) (si minio.StorageInfo, _ []error) {
|
2019-11-01 19:58:11 -04:00
|
|
|
si.Backend.Type = minio.BackendGateway
|
2020-11-19 13:38:02 -05:00
|
|
|
host := l.Client.EndpointURL().Host
|
|
|
|
if l.Client.EndpointURL().Port() == "" {
|
|
|
|
host = l.Client.EndpointURL().Host + ":" + l.Client.EndpointURL().Scheme
|
|
|
|
}
|
|
|
|
si.Backend.GatewayOnline = minio.IsBackendOnline(ctx, host)
|
2020-05-28 16:03:04 -04:00
|
|
|
return si, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// MakeBucket creates a new container on S3 backend.
|
2020-06-12 23:04:01 -04:00
|
|
|
func (l *s3Objects) MakeBucketWithLocation(ctx context.Context, bucket string, opts minio.BucketOptions) error {
|
|
|
|
if opts.LockEnabled || opts.VersioningEnabled {
|
2020-05-08 16:44:44 -04:00
|
|
|
return minio.NotImplemented{}
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// Verify if bucket name is valid.
|
|
|
|
// We are using a separate helper function here to validate bucket
|
|
|
|
// names instead of IsValidBucketName() because there is a possibility
|
|
|
|
// that certains users might have buckets which are non-DNS compliant
|
|
|
|
// in us-east-1 and we might severely restrict them by not allowing
|
|
|
|
// access to these buckets.
|
|
|
|
// Ref - http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
|
|
|
|
if s3utils.CheckValidBucketName(bucket) != nil {
|
2018-04-23 23:27:33 -04:00
|
|
|
return minio.BucketNameInvalid{Bucket: bucket}
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
2020-07-14 12:38:05 -04:00
|
|
|
err := l.Client.MakeBucket(ctx, bucket, miniogo.MakeBucketOptions{Region: opts.Location})
|
2018-04-23 23:27:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return minio.ErrorRespToObjectError(err, bucket)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucketInfo gets bucket metadata..
|
|
|
|
func (l *s3Objects) GetBucketInfo(ctx context.Context, bucket string) (bi minio.BucketInfo, e error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
buckets, err := l.Client.ListBuckets(ctx)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2019-06-07 18:49:13 -04:00
|
|
|
// Listbuckets may be disallowed, proceed to check if
|
|
|
|
// bucket indeed exists, if yes return success.
|
|
|
|
var ok bool
|
2020-07-14 12:38:05 -04:00
|
|
|
if ok, err = l.Client.BucketExists(ctx, bucket); err != nil {
|
2019-06-07 18:49:13 -04:00
|
|
|
return bi, minio.ErrorRespToObjectError(err, bucket)
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
return bi, minio.BucketNotFound{Bucket: bucket}
|
|
|
|
}
|
|
|
|
return minio.BucketInfo{
|
|
|
|
Name: bi.Name,
|
|
|
|
Created: time.Now().UTC(),
|
|
|
|
}, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, bi := range buckets {
|
|
|
|
if bi.Name != bucket {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
return minio.BucketInfo{
|
|
|
|
Name: bi.Name,
|
|
|
|
Created: bi.CreationDate,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:04:40 -04:00
|
|
|
return bi, minio.BucketNotFound{Bucket: bucket}
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListBuckets lists all S3 buckets
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) ListBuckets(ctx context.Context) ([]minio.BucketInfo, error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
buckets, err := l.Client.ListBuckets(ctx)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return nil, minio.ErrorRespToObjectError(err)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
b := make([]minio.BucketInfo, len(buckets))
|
|
|
|
for i, bi := range buckets {
|
|
|
|
b[i] = minio.BucketInfo{
|
|
|
|
Name: bi.Name,
|
|
|
|
Created: bi.CreationDate,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return b, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteBucket deletes a bucket on S3
|
2020-03-28 00:52:59 -04:00
|
|
|
func (l *s3Objects) DeleteBucket(ctx context.Context, bucket string, forceDelete bool) error {
|
2020-07-14 12:38:05 -04:00
|
|
|
err := l.Client.RemoveBucket(ctx, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjects lists all blobs in S3 bucket filtered by prefix
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) ListObjects(ctx context.Context, bucket string, prefix string, marker string, delimiter string, maxKeys int) (loi minio.ListObjectsInfo, e error) {
|
2017-12-05 20:58:09 -05:00
|
|
|
result, err := l.Client.ListObjects(bucket, prefix, marker, delimiter, maxKeys)
|
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return loi, minio.ErrorRespToObjectError(err, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return minio.FromMinioClientListBucketResult(bucket, result), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListObjectsV2 lists all blobs in S3 bucket filtered by prefix
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) ListObjectsV2(ctx context.Context, bucket, prefix, continuationToken, delimiter string, maxKeys int, fetchOwner bool, startAfter string) (loi minio.ListObjectsV2Info, e error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
result, err := l.Client.ListObjectsV2(bucket, prefix, continuationToken, fetchOwner, delimiter, maxKeys)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return loi, minio.ErrorRespToObjectError(err, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return minio.FromMinioClientListBucketV2Result(bucket, result), nil
|
|
|
|
}
|
|
|
|
|
2018-09-20 22:22:09 -04:00
|
|
|
// GetObjectNInfo - returns object info and locked object ReadCloser
|
2018-09-27 06:06:45 -04:00
|
|
|
func (l *s3Objects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec, h http.Header, lockType minio.LockType, opts minio.ObjectOptions) (gr *minio.GetObjectReader, err error) {
|
2018-09-20 22:22:09 -04:00
|
|
|
var objInfo minio.ObjectInfo
|
2018-09-27 06:06:45 -04:00
|
|
|
objInfo, err = l.GetObjectInfo(ctx, bucket, object, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
if err != nil {
|
2018-10-29 01:11:20 -04:00
|
|
|
return nil, minio.ErrorRespToObjectError(err, bucket, object)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
2020-09-15 16:57:15 -04:00
|
|
|
fn, off, length, err := minio.NewGetObjectReader(rs, objInfo, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
if err != nil {
|
2018-10-29 01:11:20 -04:00
|
|
|
return nil, minio.ErrorRespToObjectError(err, bucket, object)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pr, pw := io.Pipe()
|
|
|
|
go func() {
|
2020-09-15 16:57:15 -04:00
|
|
|
err := l.GetObject(ctx, bucket, object, off, length, pw, objInfo.ETag, opts)
|
2018-09-20 22:22:09 -04:00
|
|
|
pw.CloseWithError(err)
|
|
|
|
}()
|
2020-09-15 16:57:15 -04:00
|
|
|
|
2018-09-21 14:42:06 -04:00
|
|
|
// Setup cleanup function to cause the above go-routine to
|
|
|
|
// exit in case of partial read
|
|
|
|
pipeCloser := func() { pr.Close() }
|
2020-09-15 16:57:15 -04:00
|
|
|
return fn(pr, h, opts.CheckPrecondFn, pipeCloser)
|
2018-09-20 22:22:09 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// GetObject reads an object from S3. Supports additional
|
|
|
|
// parameters like offset and length which are synonymous with
|
|
|
|
// HTTP Range requests.
|
|
|
|
//
|
|
|
|
// startOffset indicates the starting read location of the object.
|
|
|
|
// length indicates the total length of the object.
|
2018-09-10 12:42:43 -04:00
|
|
|
func (l *s3Objects) GetObject(ctx context.Context, bucket string, key string, startOffset int64, length int64, writer io.Writer, etag string, o minio.ObjectOptions) error {
|
2017-12-05 20:58:09 -05:00
|
|
|
if length < 0 && length != -1 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(minio.InvalidRange{}, bucket, key)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
opts := miniogo.GetObjectOptions{}
|
2018-09-10 12:42:43 -04:00
|
|
|
opts.ServerSideEncryption = o.ServerSideEncryption
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
if startOffset >= 0 && length >= 0 {
|
|
|
|
if err := opts.SetRange(startOffset, startOffset+length-1); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket, key)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
}
|
2020-12-17 12:11:14 -05:00
|
|
|
|
|
|
|
if etag != "" {
|
|
|
|
opts.SetMatchETag(etag)
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
object, _, _, err := l.Client.GetObject(ctx, bucket, key, opts)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket, key)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
defer object.Close()
|
|
|
|
if _, err := io.Copy(writer, object); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket, key)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObjectInfo reads object info and replies back ObjectInfo
|
2018-09-10 12:42:43 -04:00
|
|
|
func (l *s3Objects) GetObjectInfo(ctx context.Context, bucket string, object string, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
oi, err := l.Client.StatObject(ctx, bucket, object, miniogo.StatObjectOptions{
|
|
|
|
ServerSideEncryption: opts.ServerSideEncryption,
|
2019-01-05 17:16:43 -05:00
|
|
|
})
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return minio.FromMinioClientObjectInfo(bucket, oi), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject creates a new object with the incoming data,
|
2019-02-09 00:31:06 -05:00
|
|
|
func (l *s3Objects) PutObject(ctx context.Context, bucket string, object string, r *minio.PutObjReader, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2018-11-14 20:36:41 -05:00
|
|
|
data := r.Reader
|
2020-05-23 14:09:35 -04:00
|
|
|
var tagMap map[string]string
|
|
|
|
if tagstr, ok := opts.UserDefined[xhttp.AmzObjectTagging]; ok && tagstr != "" {
|
|
|
|
tagObj, err := tags.ParseObjectTags(tagstr)
|
|
|
|
if err != nil {
|
|
|
|
return objInfo, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
tagMap = tagObj.ToMap()
|
|
|
|
delete(opts.UserDefined, xhttp.AmzObjectTagging)
|
|
|
|
}
|
|
|
|
putOpts := miniogo.PutObjectOptions{
|
|
|
|
UserMetadata: opts.UserDefined,
|
|
|
|
ServerSideEncryption: opts.ServerSideEncryption,
|
|
|
|
UserTags: tagMap,
|
|
|
|
}
|
2020-07-14 12:38:05 -04:00
|
|
|
ui, err := l.Client.PutObject(ctx, bucket, object, data, data.Size(), data.MD5Base64String(), data.SHA256HexString(), putOpts)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
2018-10-12 15:25:59 -04:00
|
|
|
// On success, populate the key & metadata so they are present in the notification
|
2020-07-14 12:38:05 -04:00
|
|
|
oi := miniogo.ObjectInfo{
|
|
|
|
ETag: ui.ETag,
|
|
|
|
Size: ui.Size,
|
|
|
|
Key: object,
|
|
|
|
Metadata: minio.ToMinioClientObjectInfoMetadata(opts.UserDefined),
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
|
|
|
|
return minio.FromMinioClientObjectInfo(bucket, oi), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject copies an object from source bucket to a destination bucket.
|
2018-09-10 12:42:43 -04:00
|
|
|
func (l *s3Objects) CopyObject(ctx context.Context, srcBucket string, srcObject string, dstBucket string, dstObject string, srcInfo minio.ObjectInfo, srcOpts, dstOpts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
|
2020-07-17 16:01:22 -04:00
|
|
|
if srcOpts.CheckPrecondFn != nil && srcOpts.CheckPrecondFn(srcInfo) {
|
2019-03-06 15:38:41 -05:00
|
|
|
return minio.ObjectInfo{}, minio.PreConditionFailed{}
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
// Set this header such that following CopyObject() always sets the right metadata on the destination.
|
|
|
|
// metadata input is already a trickled down value from interpreting x-amz-metadata-directive at
|
|
|
|
// handler layer. So what we have right now is supposed to be applied on the destination object anyways.
|
|
|
|
// So preserve it by adding "REPLACE" directive to save all the metadata set by CopyObject API.
|
2018-02-21 03:48:47 -05:00
|
|
|
srcInfo.UserDefined["x-amz-metadata-directive"] = "REPLACE"
|
|
|
|
srcInfo.UserDefined["x-amz-copy-source-if-match"] = srcInfo.ETag
|
2019-01-05 17:16:43 -05:00
|
|
|
header := make(http.Header)
|
|
|
|
if srcOpts.ServerSideEncryption != nil {
|
|
|
|
encrypt.SSECopy(srcOpts.ServerSideEncryption).Marshal(header)
|
|
|
|
}
|
|
|
|
|
|
|
|
if dstOpts.ServerSideEncryption != nil {
|
|
|
|
dstOpts.ServerSideEncryption.Marshal(header)
|
|
|
|
}
|
2020-05-23 14:09:35 -04:00
|
|
|
|
2019-01-05 17:16:43 -05:00
|
|
|
for k, v := range header {
|
|
|
|
srcInfo.UserDefined[k] = v[0]
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:50:22 -05:00
|
|
|
if _, err = l.Client.CopyObject(ctx, srcBucket, srcObject, dstBucket, dstObject, srcInfo.UserDefined, miniogo.PutObjectOptions{}); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return objInfo, minio.ErrorRespToObjectError(err, srcBucket, srcObject)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
2018-09-10 12:42:43 -04:00
|
|
|
return l.GetObjectInfo(ctx, dstBucket, dstObject, dstOpts)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObject deletes a blob in bucket
|
2020-06-12 23:04:01 -04:00
|
|
|
func (l *s3Objects) DeleteObject(ctx context.Context, bucket string, object string, opts minio.ObjectOptions) (minio.ObjectInfo, error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
err := l.Client.RemoveObject(ctx, bucket, object, miniogo.RemoveObjectOptions{})
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
return minio.ObjectInfo{
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
|
|
|
}, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func (l *s3Objects) DeleteObjects(ctx context.Context, bucket string, objects []minio.ObjectToDelete, opts minio.ObjectOptions) ([]minio.DeletedObject, []error) {
|
2019-05-13 15:25:49 -04:00
|
|
|
errs := make([]error, len(objects))
|
2020-06-12 23:04:01 -04:00
|
|
|
dobjects := make([]minio.DeletedObject, len(objects))
|
2019-05-13 15:25:49 -04:00
|
|
|
for idx, object := range objects {
|
2020-06-12 23:04:01 -04:00
|
|
|
_, errs[idx] = l.DeleteObject(ctx, bucket, object.ObjectName, opts)
|
|
|
|
if errs[idx] == nil {
|
|
|
|
dobjects[idx] = minio.DeletedObject{
|
|
|
|
ObjectName: object.ObjectName,
|
|
|
|
}
|
|
|
|
}
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return dobjects, errs
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// ListMultipartUploads lists all multipart uploads.
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) ListMultipartUploads(ctx context.Context, bucket string, prefix string, keyMarker string, uploadIDMarker string, delimiter string, maxUploads int) (lmi minio.ListMultipartsInfo, e error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
result, err := l.Client.ListMultipartUploads(ctx, bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
|
|
|
return lmi, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return minio.FromMinioClientListMultipartsInfo(result), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMultipartUpload upload object in multiple parts
|
2019-02-09 00:31:06 -05:00
|
|
|
func (l *s3Objects) NewMultipartUpload(ctx context.Context, bucket string, object string, o minio.ObjectOptions) (uploadID string, err error) {
|
2020-05-23 14:09:35 -04:00
|
|
|
var tagMap map[string]string
|
|
|
|
if tagStr, ok := o.UserDefined[xhttp.AmzObjectTagging]; ok {
|
|
|
|
tagObj, err := tags.Parse(tagStr, true)
|
|
|
|
if err != nil {
|
|
|
|
return uploadID, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
tagMap = tagObj.ToMap()
|
|
|
|
delete(o.UserDefined, xhttp.AmzObjectTagging)
|
|
|
|
}
|
2017-12-05 20:58:09 -05:00
|
|
|
// Create PutObject options
|
2020-05-23 14:09:35 -04:00
|
|
|
opts := miniogo.PutObjectOptions{
|
|
|
|
UserMetadata: o.UserDefined,
|
|
|
|
ServerSideEncryption: o.ServerSideEncryption,
|
|
|
|
UserTags: tagMap,
|
|
|
|
}
|
2020-07-14 12:38:05 -04:00
|
|
|
uploadID, err = l.Client.NewMultipartUpload(ctx, bucket, object, opts)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return uploadID, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
return uploadID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObjectPart puts a part of object in bucket
|
2018-11-14 20:36:41 -05:00
|
|
|
func (l *s3Objects) PutObjectPart(ctx context.Context, bucket string, object string, uploadID string, partID int, r *minio.PutObjReader, opts minio.ObjectOptions) (pi minio.PartInfo, e error) {
|
|
|
|
data := r.Reader
|
2020-07-14 12:38:05 -04:00
|
|
|
info, err := l.Client.PutObjectPart(ctx, bucket, object, uploadID, partID, data, data.Size(), data.MD5Base64String(), data.SHA256HexString(), opts.ServerSideEncryption)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return pi, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return minio.FromMinioClientObjectPart(info), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObjectPart creates a part in a multipart upload by copying
|
|
|
|
// existing object or a part of it.
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) CopyObjectPart(ctx context.Context, srcBucket, srcObject, destBucket, destObject, uploadID string,
|
2018-09-10 12:42:43 -04:00
|
|
|
partID int, startOffset, length int64, srcInfo minio.ObjectInfo, srcOpts, dstOpts minio.ObjectOptions) (p minio.PartInfo, err error) {
|
2020-07-17 16:01:22 -04:00
|
|
|
if srcOpts.CheckPrecondFn != nil && srcOpts.CheckPrecondFn(srcInfo) {
|
2019-03-06 15:38:41 -05:00
|
|
|
return minio.PartInfo{}, minio.PreConditionFailed{}
|
|
|
|
}
|
2018-02-21 03:48:47 -05:00
|
|
|
srcInfo.UserDefined = map[string]string{
|
|
|
|
"x-amz-copy-source-if-match": srcInfo.ETag,
|
|
|
|
}
|
2019-01-05 17:16:43 -05:00
|
|
|
header := make(http.Header)
|
|
|
|
if srcOpts.ServerSideEncryption != nil {
|
|
|
|
encrypt.SSECopy(srcOpts.ServerSideEncryption).Marshal(header)
|
|
|
|
}
|
|
|
|
|
|
|
|
if dstOpts.ServerSideEncryption != nil {
|
|
|
|
dstOpts.ServerSideEncryption.Marshal(header)
|
|
|
|
}
|
|
|
|
for k, v := range header {
|
|
|
|
srcInfo.UserDefined[k] = v[0]
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
completePart, err := l.Client.CopyObjectPart(ctx, srcBucket, srcObject, destBucket, destObject,
|
2018-02-21 03:48:47 -05:00
|
|
|
uploadID, partID, startOffset, length, srcInfo.UserDefined)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return p, minio.ErrorRespToObjectError(err, srcBucket, srcObject)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
p.PartNumber = completePart.PartNumber
|
|
|
|
p.ETag = completePart.ETag
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
// GetMultipartInfo returns multipart info of the uploadId of the object
|
|
|
|
func (l *s3Objects) GetMultipartInfo(ctx context.Context, bucket, object, uploadID string, opts minio.ObjectOptions) (result minio.MultipartInfo, err error) {
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:58:09 -05:00
|
|
|
// ListObjectParts returns all object parts for specified object in specified bucket
|
2019-01-05 17:16:43 -05:00
|
|
|
func (l *s3Objects) ListObjectParts(ctx context.Context, bucket string, object string, uploadID string, partNumberMarker int, maxParts int, opts minio.ObjectOptions) (lpi minio.ListPartsInfo, e error) {
|
2020-06-12 13:18:42 -04:00
|
|
|
result, err := l.Client.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxParts)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2020-05-28 15:36:20 -04:00
|
|
|
return lpi, err
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
2020-05-28 15:36:20 -04:00
|
|
|
lpi = minio.FromMinioClientListPartsInfo(result)
|
|
|
|
if lpi.IsTruncated && maxParts > len(lpi.Parts) {
|
|
|
|
partNumberMarker = lpi.NextPartNumberMarker
|
|
|
|
for {
|
2020-06-12 13:18:42 -04:00
|
|
|
result, err = l.Client.ListObjectParts(ctx, bucket, object, uploadID, partNumberMarker, maxParts)
|
2020-05-28 15:36:20 -04:00
|
|
|
if err != nil {
|
|
|
|
return lpi, err
|
|
|
|
}
|
|
|
|
|
|
|
|
nlpi := minio.FromMinioClientListPartsInfo(result)
|
2017-12-05 20:58:09 -05:00
|
|
|
|
2020-05-28 15:36:20 -04:00
|
|
|
partNumberMarker = nlpi.NextPartNumberMarker
|
|
|
|
|
|
|
|
lpi.Parts = append(lpi.Parts, nlpi.Parts...)
|
|
|
|
if !nlpi.IsTruncated {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lpi, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// AbortMultipartUpload aborts a ongoing multipart upload
|
2020-09-14 18:57:13 -04:00
|
|
|
func (l *s3Objects) AbortMultipartUpload(ctx context.Context, bucket string, object string, uploadID string, opts minio.ObjectOptions) error {
|
2020-07-14 12:38:05 -04:00
|
|
|
err := l.Client.AbortMultipartUpload(ctx, bucket, object, uploadID)
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CompleteMultipartUpload completes ongoing multipart upload and finalizes object
|
2018-11-14 20:36:41 -05:00
|
|
|
func (l *s3Objects) CompleteMultipartUpload(ctx context.Context, bucket string, object string, uploadID string, uploadedParts []minio.CompletePart, opts minio.ObjectOptions) (oi minio.ObjectInfo, e error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
etag, err := l.Client.CompleteMultipartUpload(ctx, bucket, object, uploadID, minio.ToMinioClientCompleteParts(uploadedParts))
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return oi, minio.ErrorRespToObjectError(err, bucket, object)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2020-05-14 20:43:54 -04:00
|
|
|
return minio.ObjectInfo{Bucket: bucket, Name: object, ETag: strings.Trim(etag, "\"")}, nil
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// SetBucketPolicy sets policy on bucket
|
2018-04-24 18:53:30 -04:00
|
|
|
func (l *s3Objects) SetBucketPolicy(ctx context.Context, bucket string, bucketPolicy *policy.Policy) error {
|
|
|
|
data, err := json.Marshal(bucketPolicy)
|
2018-04-15 02:09:48 -04:00
|
|
|
if err != nil {
|
2018-04-24 18:53:30 -04:00
|
|
|
// This should not happen.
|
|
|
|
logger.LogIf(ctx, err)
|
|
|
|
return minio.ErrorRespToObjectError(err, bucket)
|
2018-04-15 02:09:48 -04:00
|
|
|
}
|
2018-04-24 18:53:30 -04:00
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
if err := l.Client.SetBucketPolicy(ctx, bucket, string(data)); err != nil {
|
2018-04-24 18:53:30 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// GetBucketPolicy will get policy on bucket
|
2018-04-24 18:53:30 -04:00
|
|
|
func (l *s3Objects) GetBucketPolicy(ctx context.Context, bucket string) (*policy.Policy, error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
data, err := l.Client.GetBucketPolicy(ctx, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
if err != nil {
|
2018-04-24 18:53:30 -04:00
|
|
|
return nil, minio.ErrorRespToObjectError(err, bucket)
|
2018-04-15 02:09:48 -04:00
|
|
|
}
|
2018-04-24 18:53:30 -04:00
|
|
|
|
|
|
|
bucketPolicy, err := policy.ParseConfig(strings.NewReader(data), bucket)
|
|
|
|
return bucketPolicy, minio.ErrorRespToObjectError(err, bucket)
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
|
2018-02-09 18:19:30 -05:00
|
|
|
// DeleteBucketPolicy deletes all policies on bucket
|
2018-03-14 21:36:54 -04:00
|
|
|
func (l *s3Objects) DeleteBucketPolicy(ctx context.Context, bucket string) error {
|
2020-07-14 12:38:05 -04:00
|
|
|
if err := l.Client.SetBucketPolicy(ctx, bucket, ""); err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return minio.ErrorRespToObjectError(err, bucket, "")
|
2017-12-05 20:58:09 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-09-27 23:36:17 -04:00
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
// GetObjectTags gets the tags set on the object
|
2020-06-12 23:04:01 -04:00
|
|
|
func (l *s3Objects) GetObjectTags(ctx context.Context, bucket string, object string, opts minio.ObjectOptions) (*tags.Tags, error) {
|
2020-05-23 14:09:35 -04:00
|
|
|
var err error
|
|
|
|
if _, err = l.GetObjectInfo(ctx, bucket, object, opts); err != nil {
|
|
|
|
return nil, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2020-07-17 01:38:58 -04:00
|
|
|
t, err := l.Client.GetObjectTagging(ctx, bucket, object, miniogo.GetObjectTaggingOptions{})
|
2020-07-14 12:38:05 -04:00
|
|
|
if err != nil {
|
2020-05-23 14:09:35 -04:00
|
|
|
return nil, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2020-07-17 01:38:58 -04:00
|
|
|
return t, nil
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObjectTags attaches the tags to the object
|
2021-02-01 16:52:51 -05:00
|
|
|
func (l *s3Objects) PutObjectTags(ctx context.Context, bucket, object string, tagStr string, opts minio.ObjectOptions) (minio.ObjectInfo, error) {
|
2020-05-23 14:09:35 -04:00
|
|
|
tagObj, err := tags.Parse(tagStr, true)
|
|
|
|
if err != nil {
|
2021-02-01 16:52:51 -05:00
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
2021-02-01 16:52:51 -05:00
|
|
|
if err = l.Client.PutObjectTagging(ctx, bucket, object, tagObj, miniogo.PutObjectTaggingOptions{VersionID: opts.VersionID}); err != nil {
|
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
2021-02-01 16:52:51 -05:00
|
|
|
|
|
|
|
objInfo, err := l.GetObjectInfo(ctx, bucket, object, opts)
|
|
|
|
if err != nil {
|
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
return objInfo, nil
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObjectTags removes the tags attached to the object
|
2021-02-01 16:52:51 -05:00
|
|
|
func (l *s3Objects) DeleteObjectTags(ctx context.Context, bucket, object string, opts minio.ObjectOptions) (minio.ObjectInfo, error) {
|
2020-07-14 12:38:05 -04:00
|
|
|
if err := l.Client.RemoveObjectTagging(ctx, bucket, object, miniogo.RemoveObjectTaggingOptions{}); err != nil {
|
2021-02-01 16:52:51 -05:00
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
2021-02-01 16:52:51 -05:00
|
|
|
objInfo, err := l.GetObjectInfo(ctx, bucket, object, opts)
|
|
|
|
if err != nil {
|
|
|
|
return minio.ObjectInfo{}, minio.ErrorRespToObjectError(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
return objInfo, nil
|
2020-05-23 14:09:35 -04:00
|
|
|
}
|
|
|
|
|
2018-09-27 23:36:17 -04:00
|
|
|
// IsCompressionSupported returns whether compression is applicable for this layer.
|
|
|
|
func (l *s3Objects) IsCompressionSupported() bool {
|
|
|
|
return false
|
|
|
|
}
|
2019-01-05 17:16:43 -05:00
|
|
|
|
|
|
|
// IsEncryptionSupported returns whether server side encryption is implemented for this layer.
|
|
|
|
func (l *s3Objects) IsEncryptionSupported() bool {
|
2020-09-15 16:57:15 -04:00
|
|
|
return minio.GlobalKMS != nil || minio.GlobalGatewaySSE.IsSet()
|
2019-01-05 17:16:43 -05:00
|
|
|
}
|
2019-12-28 11:54:43 -05:00
|
|
|
|
2020-05-23 14:09:35 -04:00
|
|
|
func (l *s3Objects) IsTaggingSupported() bool {
|
|
|
|
return true
|
|
|
|
}
|