fix: return versionId in tagging APIs (#10068)

This commit is contained in:
Harshavardhana 2020-07-16 22:38:58 -07:00 committed by GitHub
parent 5e8392c8ef
commit 4bfc50411c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 32 deletions

View File

@ -165,7 +165,7 @@ var defaultAWSCredProviders = []credentials.Provider{
} }
// newS3 - Initializes a new client by auto probing S3 server signature. // newS3 - Initializes a new client by auto probing S3 server signature.
func newS3(urlStr string) (*miniogo.Core, error) { func newS3(urlStr string, tripper http.RoundTripper) (*miniogo.Core, error) {
if urlStr == "" { if urlStr == "" {
urlStr = "https://s3.amazonaws.com" urlStr = "https://s3.amazonaws.com"
} }
@ -191,14 +191,15 @@ func newS3(urlStr string) (*miniogo.Core, error) {
creds = credentials.NewChainCredentials(defaultProviders) creds = credentials.NewChainCredentials(defaultProviders)
} }
options := miniogo.Options{ options := &miniogo.Options{
Creds: creds, Creds: creds,
Secure: secure, Secure: secure,
Region: s3utils.GetRegionFromURL(*u), Region: s3utils.GetRegionFromURL(*u),
BucketLookup: miniogo.BucketLookupAuto, BucketLookup: miniogo.BucketLookupAuto,
Transport: tripper,
} }
clnt, err := miniogo.NewWithOptions(endpoint, &options) clnt, err := miniogo.New(endpoint, options)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -208,13 +209,6 @@ func newS3(urlStr string) (*miniogo.Core, error) {
// NewGatewayLayer returns s3 ObjectLayer. // NewGatewayLayer returns s3 ObjectLayer.
func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) { func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
// creds are ignored here, since S3 gateway implements chaining
// all credentials.
clnt, err := newS3(g.host)
if err != nil {
return nil, err
}
metrics := minio.NewMetrics() metrics := minio.NewMetrics()
t := &minio.MetricsTransport{ t := &minio.MetricsTransport{
@ -222,8 +216,12 @@ func (g *S3) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error)
Metrics: metrics, Metrics: metrics,
} }
// Set custom transport // creds are ignored here, since S3 gateway implements chaining
clnt.SetCustomTransport(t) // all credentials.
clnt, err := newS3(g.host, t)
if err != nil {
return nil, err
}
probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-") probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-")
@ -719,17 +717,12 @@ func (l *s3Objects) GetObjectTags(ctx context.Context, bucket string, object str
return nil, minio.ErrorRespToObjectError(err, bucket, object) return nil, minio.ErrorRespToObjectError(err, bucket, object)
} }
tagsMap, err := l.Client.GetObjectTagging(ctx, bucket, object, miniogo.GetObjectTaggingOptions{}) t, err := l.Client.GetObjectTagging(ctx, bucket, object, miniogo.GetObjectTaggingOptions{})
if err != nil { if err != nil {
return nil, minio.ErrorRespToObjectError(err, bucket, object) return nil, minio.ErrorRespToObjectError(err, bucket, object)
} }
tagObj := tags.Tags{} return t, nil
for k, v := range tagsMap {
tagObj.Set(k, v)
}
return &tagObj, err
} }
// PutObjectTags attaches the tags to the object // PutObjectTags attaches the tags to the object
@ -738,7 +731,7 @@ func (l *s3Objects) PutObjectTags(ctx context.Context, bucket, object string, ta
if err != nil { if err != nil {
return minio.ErrorRespToObjectError(err, bucket, object) return minio.ErrorRespToObjectError(err, bucket, object)
} }
if err = l.Client.PutObjectTagging(ctx, bucket, object, tagObj.ToMap(), miniogo.PutObjectTaggingOptions{}); err != nil { if err = l.Client.PutObjectTagging(ctx, bucket, object, tagObj, miniogo.PutObjectTaggingOptions{}); err != nil {
return minio.ErrorRespToObjectError(err, bucket, object) return minio.ErrorRespToObjectError(err, bucket, object)
} }
return nil return nil

View File

@ -34,6 +34,7 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
miniogo "github.com/minio/minio-go/v7" miniogo "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/minio/minio-go/v7/pkg/encrypt" "github.com/minio/minio-go/v7/pkg/encrypt"
"github.com/minio/minio-go/v7/pkg/tags" "github.com/minio/minio-go/v7/pkg/tags"
"github.com/minio/minio/cmd/config/etcd/dns" "github.com/minio/minio/cmd/config/etcd/dns"
@ -700,8 +701,8 @@ func getCpObjMetadataFromHeader(ctx context.Context, r *http.Request, userMeta m
} }
// getRemoteInstanceTransport contains a singleton roundtripper. // getRemoteInstanceTransport contains a singleton roundtripper.
var getRemoteInstanceTransport http.RoundTripper var getRemoteInstanceTransport *http.Transport
var getRemoteInstanceTransportLongTO http.RoundTripper var getRemoteInstanceTransportLongTO *http.Transport
var getRemoteInstanceTransportOnce sync.Once var getRemoteInstanceTransportOnce sync.Once
// Returns a minio-go Client configured to access remote host described by destDNSRecord // Returns a minio-go Client configured to access remote host described by destDNSRecord
@ -710,7 +711,11 @@ var getRemoteInstanceClient = func(r *http.Request, host string) (*miniogo.Core,
cred := getReqAccessCred(r, globalServerRegion) cred := getReqAccessCred(r, globalServerRegion)
// In a federated deployment, all the instances share config files // In a federated deployment, all the instances share config files
// and hence expected to have same credentials. // and hence expected to have same credentials.
core, err := miniogo.NewCore(host, cred.AccessKey, cred.SecretKey, globalIsSSL) core, err := miniogo.NewCore(host, &miniogo.Options{
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, ""),
Secure: globalIsSSL,
Transport: getRemoteInstanceTransport,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -718,7 +723,6 @@ var getRemoteInstanceClient = func(r *http.Request, host string) (*miniogo.Core,
getRemoteInstanceTransport = NewGatewayHTTPTransport() getRemoteInstanceTransport = NewGatewayHTTPTransport()
getRemoteInstanceTransportLongTO = newGatewayHTTPTransport(time.Hour) getRemoteInstanceTransportLongTO = newGatewayHTTPTransport(time.Hour)
}) })
core.SetCustomTransport(getRemoteInstanceTransport)
return core, nil return core, nil
} }
@ -729,7 +733,11 @@ func getRemoteInstanceClientLongTimeout(r *http.Request, host string) (*miniogo.
cred := getReqAccessCred(r, globalServerRegion) cred := getReqAccessCred(r, globalServerRegion)
// In a federated deployment, all the instances share config files // In a federated deployment, all the instances share config files
// and hence expected to have same credentials. // and hence expected to have same credentials.
core, err := miniogo.NewCore(host, cred.AccessKey, cred.SecretKey, globalIsSSL) core, err := miniogo.NewCore(host, &miniogo.Options{
Creds: credentials.NewStaticV4(cred.AccessKey, cred.SecretKey, ""),
Secure: globalIsSSL,
Transport: getRemoteInstanceTransportLongTO,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -737,7 +745,6 @@ func getRemoteInstanceClientLongTimeout(r *http.Request, host string) (*miniogo.
getRemoteInstanceTransport = NewGatewayHTTPTransport() getRemoteInstanceTransport = NewGatewayHTTPTransport()
getRemoteInstanceTransportLongTO = newGatewayHTTPTransport(time.Hour) getRemoteInstanceTransportLongTO = newGatewayHTTPTransport(time.Hour)
}) })
core.SetCustomTransport(getRemoteInstanceTransportLongTO)
return core, nil return core, nil
} }
@ -3009,6 +3016,7 @@ func (api objectAPIHandlers) GetObjectTaggingHandler(w http.ResponseWriter, r *h
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrNotImplemented), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrNotImplemented), r.URL, guessIsBrowserReq(r))
return return
} }
// Allow getObjectTagging if policy action is set. // Allow getObjectTagging if policy action is set.
if s3Error := checkRequestAuthType(ctx, r, policy.GetObjectTaggingAction, bucket, object); s3Error != ErrNone { if s3Error := checkRequestAuthType(ctx, r, policy.GetObjectTaggingAction, bucket, object); s3Error != ErrNone {
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL, guessIsBrowserReq(r))
@ -3028,6 +3036,10 @@ func (api objectAPIHandlers) GetObjectTaggingHandler(w http.ResponseWriter, r *h
return return
} }
if opts.VersionID != "" {
w.Header()[xhttp.AmzVersionID] = []string{opts.VersionID}
}
writeSuccessResponseXML(w, encodeResponse(tags)) writeSuccessResponseXML(w, encodeResponse(tags))
} }
@ -3079,6 +3091,10 @@ func (api objectAPIHandlers) PutObjectTaggingHandler(w http.ResponseWriter, r *h
return return
} }
if opts.VersionID != "" {
w.Header()[xhttp.AmzVersionID] = []string{opts.VersionID}
}
writeSuccessResponseHeadersOnly(w) writeSuccessResponseHeadersOnly(w)
} }
@ -3118,10 +3134,14 @@ func (api objectAPIHandlers) DeleteObjectTaggingHandler(w http.ResponseWriter, r
} }
// Delete object tags // Delete object tags
if err = objAPI.DeleteObjectTags(ctx, bucket, object, opts); err != nil && err != errConfigNotFound { if err = objAPI.DeleteObjectTags(ctx, bucket, object, opts); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
} }
if opts.VersionID != "" {
w.Header()[xhttp.AmzVersionID] = []string{opts.VersionID}
}
writeSuccessNoContent(w) writeSuccessNoContent(w)
} }

View File

@ -36,6 +36,7 @@ import (
"github.com/gorilla/rpc/v2/json2" "github.com/gorilla/rpc/v2/json2"
"github.com/klauspost/compress/zip" "github.com/klauspost/compress/zip"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
miniogo "github.com/minio/minio-go/v7"
miniogopolicy "github.com/minio/minio-go/v7/pkg/policy" miniogopolicy "github.com/minio/minio-go/v7/pkg/policy"
"github.com/minio/minio-go/v7/pkg/s3utils" "github.com/minio/minio-go/v7/pkg/s3utils"
"github.com/minio/minio/browser" "github.com/minio/minio/browser"
@ -637,14 +638,16 @@ func (web *webAPIHandlers) RemoveObject(r *http.Request, args *RemoveObjectArgs,
if err != nil { if err != nil {
return toJSONError(ctx, err, args.BucketName) return toJSONError(ctx, err, args.BucketName)
} }
objectsCh := make(chan string) objectsCh := make(chan miniogo.ObjectInfo)
// Send object names that are needed to be removed to objectsCh // Send object names that are needed to be removed to objectsCh
go func() { go func() {
defer close(objectsCh) defer close(objectsCh)
for _, objectName := range args.Objects { for _, objectName := range args.Objects {
objectsCh <- objectName objectsCh <- miniogo.ObjectInfo{
Key: objectName,
}
} }
}() }()

2
go.mod
View File

@ -48,7 +48,7 @@ require (
github.com/miekg/dns v1.1.8 github.com/miekg/dns v1.1.8
github.com/minio/cli v1.22.0 github.com/minio/cli v1.22.0
github.com/minio/highwayhash v1.0.0 github.com/minio/highwayhash v1.0.0
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8 github.com/minio/minio-go/v7 v7.0.1
github.com/minio/sha256-simd v0.1.1 github.com/minio/sha256-simd v0.1.1
github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37 github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37
github.com/minio/sio v0.2.0 github.com/minio/sio v0.2.0

4
go.sum
View File

@ -293,8 +293,8 @@ github.com/minio/highwayhash v1.0.0 h1:iMSDhgUILCr0TNm8LWlSjF8N0ZIj2qbO8WHp6Q/J2
github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc= github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc=
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4= github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8 h1:Xh5yHlXj/367YMabi7tWHol1AslXcuAFWaedBtGgbU0= github.com/minio/minio-go/v7 v7.0.1 h1:sL2y4uuNUEi7AjvWjoGyDFQKFX2zA0DU2tGM9m3s5f8=
github.com/minio/minio-go/v7 v7.0.0-20200714085548-47e386e2cde8/go.mod h1:QTstSRgetEDVpqiEpFniLoCslH4d9cNAa4BtjuRQrwE= github.com/minio/minio-go/v7 v7.0.1/go.mod h1:dJ80Mv2HeGkYLH1sqS/ksz07ON6csH3S6JUMSQ2zAns=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37 h1:pDeao6M5AEd8hwTtGmE0pVKomlL56JFRa5SiXDZAuJE= github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37 h1:pDeao6M5AEd8hwTtGmE0pVKomlL56JFRa5SiXDZAuJE=