diff --git a/go.mod b/go.mod index 9fd5e63be7d07..c55d847b7120a 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/alicebob/miniredis/v2 v2.30.4 github.com/aliyun/aliyun-oss-go-sdk v2.2.10+incompatible github.com/aws/aws-sdk-go v1.54.19 - github.com/baidubce/bce-sdk-go v0.9.141 + github.com/baidubce/bce-sdk-go v0.9.186 github.com/bmatcuk/doublestar v1.3.4 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 github.com/cespare/xxhash v1.1.0 diff --git a/go.sum b/go.sum index e664c656f1e14..39d0ec92e4640 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ github.com/aws/smithy-go v1.11.1 h1:IQ+lPZVkSM3FRtyaDox41R8YS6iwPMYIreejOgPW49g= github.com/aws/smithy-go v1.11.1/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= github.com/axiomhq/hyperloglog v0.0.0-20240507144631-af9851f82b27 h1:60m4tnanN1ctzIu4V3bfCNJ39BiOPSm1gHFlFjTkRE0= github.com/axiomhq/hyperloglog v0.0.0-20240507144631-af9851f82b27/go.mod h1:k08r+Yj1PRAmuayFiRK6MYuR5Ve4IuZtTfxErMIh0+c= -github.com/baidubce/bce-sdk-go v0.9.141 h1:EV5BH5lfymIGPSmYDo9xYdsVlvWAW6nFeiA6t929zBE= -github.com/baidubce/bce-sdk-go v0.9.141/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= +github.com/baidubce/bce-sdk-go v0.9.186 h1:GVJTwH34UhsY0Plh9avlNw1V3F2N20p7hzcrRTf2zpk= +github.com/baidubce/bce-sdk-go v0.9.186/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 h1:6df1vn4bBlDDo4tARvBm7l6KA9iVMnE3NWizDeWSrps= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3/go.mod h1:CIWtjkly68+yqLPbvwwR/fjNJA/idrtULjZWh2v1ys0= diff --git a/vendor/github.com/baidubce/bce-sdk-go/bce/client.go b/vendor/github.com/baidubce/bce-sdk-go/bce/client.go index 28eccd0f3b8bb..d223a0987fc66 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/bce/client.go +++ b/vendor/github.com/baidubce/bce-sdk-go/bce/client.go @@ -155,6 +155,11 @@ func (c *BceClient) SendRequest(req *BceRequest, resp *BceResponse) error { log.Infof("receive http response: status: %s, debugId: %s, requestId: %s, elapsed: %v", resp.StatusText(), resp.DebugId(), resp.RequestId(), resp.ElapsedTime()) + + if resp.ElapsedTime().Milliseconds() > DEFAULT_WARN_LOG_TIMEOUT_IN_MILLS { + log.Warnf("request time more than 5 second, debugId: %s, requestId: %s, elapsed: %v", + resp.DebugId(), resp.RequestId(), resp.ElapsedTime()) + } for k, v := range resp.Headers() { log.Debugf("%s=%s", k, v) } diff --git a/vendor/github.com/baidubce/bce-sdk-go/bce/config.go b/vendor/github.com/baidubce/bce-sdk-go/bce/config.go index 346b06cddf5dc..c55090aae342f 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/bce/config.go +++ b/vendor/github.com/baidubce/bce-sdk-go/bce/config.go @@ -26,13 +26,15 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.141" + SDK_VERSION = "0.9.186" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" + HTTPS_PROTOCAL = "https" DEFAULT_REGION = "bj" DEFAULT_CONTENT_TYPE = "application/json;charset=utf-8" DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS = 1200 * 1000 + DEFAULT_WARN_LOG_TIMEOUT_IN_MILLS = 5 * 1000 ) var ( diff --git a/vendor/github.com/baidubce/bce-sdk-go/http/client.go b/vendor/github.com/baidubce/bce-sdk-go/http/client.go index b036a40350f87..fe0fa4dbac111 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/http/client.go +++ b/vendor/github.com/baidubce/bce-sdk-go/http/client.go @@ -172,3 +172,22 @@ func Execute(request *Request) (*Response, error) { response := &Response{httpResponse, end.Sub(start)} return response, nil } +func SetResponseHeaderTimeout(t int) { + transport = &http.Transport{ + MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost, + ResponseHeaderTimeout: time.Duration(t) * time.Second, + Dial: func(network, address string) (net.Conn, error) { + conn, err := net.DialTimeout(network, address, defaultDialTimeout) + if err != nil { + return nil, err + } + tc := &timeoutConn{conn, defaultSmallInterval, defaultLargeInterval} + err = tc.SetReadDeadline(time.Now().Add(defaultLargeInterval)) + if err != nil { + return nil, err + } + return tc, nil + }, + } + httpClient.Transport = transport +} diff --git a/vendor/github.com/baidubce/bce-sdk-go/http/constants.go b/vendor/github.com/baidubce/bce-sdk-go/http/constants.go index 2f9a1e185082a..f362a19ddd0ba 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/http/constants.go +++ b/vendor/github.com/baidubce/bce-sdk-go/http/constants.go @@ -61,6 +61,7 @@ const ( BCE_USER_METADATA_PREFIX = "x-bce-meta-" BCE_SECURITY_TOKEN = "x-bce-security-token" BCE_DATE = "x-bce-date" + BCE_TAG = "x-bce-tag-list" // BOS HTTP Headers BCE_COPY_METADATA_DIRECTIVE = "x-bce-metadata-directive" @@ -80,5 +81,8 @@ const ( BCE_RESTORE = "x-bce-restore" BCE_FORBID_OVERWRITE = "x-bce-forbid-overwrite" BCE_SYMLINK_TARGET = "x-bce-symlink-target" - BCE_TRAFFIC_LIMIT = "x-bce-traffic-limit" + BCE_SYMLINK_BUCKET = "x-bce-symlink-bucket" + BCE_TRAFFIC_LIMIT = "x-bce-traffic-limit" + BCE_BUCKET_TYPE = "x-bce-bucket-type" + BCE_OBJECT_TAGGING = "x-bce-tagging" ) diff --git a/vendor/github.com/baidubce/bce-sdk-go/http/request.go b/vendor/github.com/baidubce/bce-sdk-go/http/request.go index 7fecfb99a460e..964c57010a3a0 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/http/request.go +++ b/vendor/github.com/baidubce/bce-sdk-go/http/request.go @@ -149,7 +149,11 @@ func (r *Request) SetParam(key, value string) { func (r *Request) QueryString() string { buf := make([]string, 0, len(r.params)) for k, v := range r.params { - buf = append(buf, util.UriEncode(k, true)+"="+util.UriEncode(v, true)) + if len(v) == 0 { + buf = append(buf, util.UriEncode(k, true)) + } else { + buf = append(buf, util.UriEncode(k, true)+"="+util.UriEncode(v, true)) + } } return strings.Join(buf, "&") } diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/bucket.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/bucket.go index 9046364c394f0..ea79f00322078 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/bucket.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/bucket.go @@ -32,11 +32,11 @@ import ( // RETURNS: // - *ListBucketsResult: the result bucket list structure // - error: nil if ok otherwise the specific error -func ListBuckets(cli bce.Client) (*ListBucketsResult, error) { +func ListBuckets(cli bce.Client, ctx *BosContext) (*ListBucketsResult, error) { req := &bce.BceRequest{} req.SetMethod(http.GET) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -59,11 +59,11 @@ func ListBuckets(cli bce.Client) (*ListBucketsResult, error) { // - *ListObjectsResult: the result object list structure // - error: nil if ok otherwise the specific error func ListObjects(cli bce.Client, bucket string, - args *ListObjectsArgs) (*ListObjectsResult, error) { + args *ListObjectsArgs, ctx *BosContext) (*ListObjectsResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) - + ctx.Bucket = bucket // Optional arguments settings if args != nil { if len(args.Delimiter) != 0 { @@ -85,7 +85,7 @@ func ListObjects(cli bce.Client, bucket string, // Send the request and get result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -106,19 +106,20 @@ func ListObjects(cli bce.Client, bucket string, // - bucket: the bucket name // RETURNS: // - error: nil if exists and have authority otherwise the specific error -func HeadBucket(cli bce.Client, bucket string) error { +func HeadBucket(cli bce.Client, bucket string, ctx *BosContext) (error, *bce.BceResponse) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.HEAD) + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { - return err + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err, resp } if resp.IsFail() { - return resp.ServiceError() + return resp.ServiceError(), resp } defer func() { resp.Body().Close() }() - return nil + return nil, resp } // PutBucket - create a new bucket with the given name @@ -129,12 +130,18 @@ func HeadBucket(cli bce.Client, bucket string) error { // RETURNS: // - string: the location of the new bucket if create success // - error: nil if create success otherwise the specific error -func PutBucket(cli bce.Client, bucket string) (string, error) { +func PutBucket(cli bce.Client, bucket string, args *PutBucketArgs, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) + ctx.Bucket = bucket + if args != nil { + if len(args.TagList) != 0 { + req.SetHeader(http.BCE_TAG, args.TagList) + } + } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { @@ -151,12 +158,13 @@ func PutBucket(cli bce.Client, bucket string) (string, error) { // - bucket: the bucket name to be deleted // RETURNS: // - error: nil if delete success otherwise the specific error -func DeleteBucket(cli bce.Client, bucket string) error { +func DeleteBucket(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -174,13 +182,14 @@ func DeleteBucket(cli bce.Client, bucket string) error { // RETURNS: // - string: the location of the bucket // - error: nil if delete success otherwise the specific error -func GetBucketLocation(cli bce.Client, bucket string) (string, error) { +func GetBucketLocation(cli bce.Client, bucket string, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("location", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { @@ -203,12 +212,12 @@ func GetBucketLocation(cli bce.Client, bucket string) (string, error) { // - aclBody: the acl file body // RETURNS: // - error: nil if delete success otherwise the specific error -func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) error { +func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("acl", "") - + ctx.Bucket = bucket // The acl setting if len(cannedAcl) != 0 && aclBody != nil { return bce.NewBceClientError("BOS does not support cannedAcl and acl file at the same time") @@ -222,7 +231,7 @@ func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) e } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -240,14 +249,14 @@ func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) e // RETURNS: // - *GetBucketAclResult: the result of the bucket acl // - error: nil if success otherwise the specific error -func GetBucketAcl(cli bce.Client, bucket string) (*GetBucketAclResult, error) { +func GetBucketAcl(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketAclResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("acl", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -269,14 +278,15 @@ func GetBucketAcl(cli bce.Client, bucket string) (*GetBucketAclResult, error) { // - logging: the logging prefix json string body // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketLogging(cli bce.Client, bucket string, logging *bce.Body) error { +func PutBucketLogging(cli bce.Client, bucket string, logging *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("logging", "") req.SetBody(logging) + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -294,14 +304,14 @@ func PutBucketLogging(cli bce.Client, bucket string, logging *bce.Body) error { // RETURNS: // - *GetBucketLoggingResult: the logging setting of the bucket // - error: nil if success otherwise the specific error -func GetBucketLogging(cli bce.Client, bucket string) (*GetBucketLoggingResult, error) { +func GetBucketLogging(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketLoggingResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("logging", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -321,13 +331,14 @@ func GetBucketLogging(cli bce.Client, bucket string) (*GetBucketLoggingResult, e // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketLogging(cli bce.Client, bucket string) error { +func DeleteBucketLogging(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("logging", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -345,14 +356,15 @@ func DeleteBucketLogging(cli bce.Client, bucket string) error { // - lifecycle: the lifecycle rule json string body // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketLifecycle(cli bce.Client, bucket string, lifecycle *bce.Body) error { +func PutBucketLifecycle(cli bce.Client, bucket string, lifecycle *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("lifecycle", "") req.SetBody(lifecycle) + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -370,14 +382,14 @@ func PutBucketLifecycle(cli bce.Client, bucket string, lifecycle *bce.Body) erro // RETURNS: // - *GetBucketLifecycleResult: the lifecycle rule of the bucket // - error: nil if success otherwise the specific error -func GetBucketLifecycle(cli bce.Client, bucket string) (*GetBucketLifecycleResult, error) { +func GetBucketLifecycle(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketLifecycleResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("lifecycle", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -397,13 +409,14 @@ func GetBucketLifecycle(cli bce.Client, bucket string) (*GetBucketLifecycleResul // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketLifecycle(cli bce.Client, bucket string) error { +func DeleteBucketLifecycle(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("lifecycle", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -421,12 +434,12 @@ func DeleteBucketLifecycle(cli bce.Client, bucket string) error { // - storageClass: the storage class string // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketStorageclass(cli bce.Client, bucket, storageClass string) error { +func PutBucketStorageclass(cli bce.Client, bucket, storageClass string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("storageClass", "") - + ctx.Bucket = bucket obj := &StorageClassType{storageClass} jsonBytes, jsonErr := json.Marshal(obj) if jsonErr != nil { @@ -439,7 +452,7 @@ func PutBucketStorageclass(cli bce.Client, bucket, storageClass string) error { req.SetBody(body) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -457,14 +470,14 @@ func PutBucketStorageclass(cli bce.Client, bucket, storageClass string) error { // RETURNS: // - string: the storage class of the bucket // - error: nil if success otherwise the specific error -func GetBucketStorageclass(cli bce.Client, bucket string) (string, error) { +func GetBucketStorageclass(cli bce.Client, bucket string, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("storageClass", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { @@ -486,11 +499,12 @@ func GetBucketStorageclass(cli bce.Client, bucket string) (string, error) { // - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Body, replicationRuleId string) error { +func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Body, replicationRuleId string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("replication", "") + ctx.Bucket = bucket if len(replicationRuleId) > 0 { req.SetParam("id", replicationRuleId) } @@ -501,7 +515,7 @@ func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Bo } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -520,17 +534,18 @@ func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Bo // RETURNS: // - *GetBucketReplicationResult: the result of the bucket replication config // - error: nil if success otherwise the specific error -func GetBucketReplication(cli bce.Client, bucket string, replicationRuleId string) (*GetBucketReplicationResult, error) { +func GetBucketReplication(cli bce.Client, bucket string, replicationRuleId string, ctx *BosContext) (*GetBucketReplicationResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replication", "") + ctx.Bucket = bucket if len(replicationRuleId) > 0 { req.SetParam("id", replicationRuleId) } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -550,12 +565,13 @@ func GetBucketReplication(cli bce.Client, bucket string, replicationRuleId strin // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func ListBucketReplication(cli bce.Client, bucket string) (*ListBucketReplicationResult, error) { +func ListBucketReplication(cli bce.Client, bucket string, ctx *BosContext) (*ListBucketReplicationResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replication", "") req.SetParam("list", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} if err := cli.SendRequest(req, resp); err != nil { return nil, err @@ -578,16 +594,17 @@ func ListBucketReplication(cli bce.Client, bucket string) (*ListBucketReplicatio // - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketReplication(cli bce.Client, bucket string, replicationRuleId string) error { +func DeleteBucketReplication(cli bce.Client, bucket string, replicationRuleId string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("replication", "") + ctx.Bucket = bucket if len(replicationRuleId) > 0 { req.SetParam("id", replicationRuleId) } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -606,18 +623,19 @@ func DeleteBucketReplication(cli bce.Client, bucket string, replicationRuleId st // RETURNS: // - *GetBucketReplicationProgressResult: the result of the bucket replication process // - error: nil if success otherwise the specific error -func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRuleId string) ( +func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRuleId string, ctx *BosContext) ( *GetBucketReplicationProgressResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replicationProgress", "") + ctx.Bucket = bucket if len(replicationRuleId) > 0 { req.SetParam("id", replicationRuleId) } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -638,12 +656,12 @@ func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRule // - algorithm: the encryption algorithm // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketEncryption(cli bce.Client, bucket, algorithm string) error { +func PutBucketEncryption(cli bce.Client, bucket, algorithm string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("encryption", "") - + ctx.Bucket = bucket obj := &BucketEncryptionType{algorithm} jsonBytes, jsonErr := json.Marshal(obj) if jsonErr != nil { @@ -657,7 +675,7 @@ func PutBucketEncryption(cli bce.Client, bucket, algorithm string) error { req.SetBody(body) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -675,14 +693,14 @@ func PutBucketEncryption(cli bce.Client, bucket, algorithm string) error { // RETURNS: // - algorithm: the bucket encryption algorithm // - error: nil if success otherwise the specific error -func GetBucketEncryption(cli bce.Client, bucket string) (string, error) { +func GetBucketEncryption(cli bce.Client, bucket string, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("encryption", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { @@ -702,13 +720,14 @@ func GetBucketEncryption(cli bce.Client, bucket string) (string, error) { // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketEncryption(cli bce.Client, bucket string) error { +func DeleteBucketEncryption(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("encryption", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -726,18 +745,19 @@ func DeleteBucketEncryption(cli bce.Client, bucket string) error { // - confBody: the static website config body stream // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketStaticWebsite(cli bce.Client, bucket string, confBody *bce.Body) error { +func PutBucketStaticWebsite(cli bce.Client, bucket string, confBody *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("website", "") + ctx.Bucket = bucket if confBody != nil { req.SetHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE) req.SetBody(confBody) } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -755,15 +775,15 @@ func PutBucketStaticWebsite(cli bce.Client, bucket string, confBody *bce.Body) e // RETURNS: // - result: the bucket static website config result object // - error: nil if success otherwise the specific error -func GetBucketStaticWebsite(cli bce.Client, bucket string) ( +func GetBucketStaticWebsite(cli bce.Client, bucket string, ctx *BosContext) ( *GetBucketStaticWebsiteResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("website", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -783,13 +803,14 @@ func GetBucketStaticWebsite(cli bce.Client, bucket string) ( // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketStaticWebsite(cli bce.Client, bucket string) error { +func DeleteBucketStaticWebsite(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("website", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -807,18 +828,19 @@ func DeleteBucketStaticWebsite(cli bce.Client, bucket string) error { // - confBody: the CORS config body stream // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketCors(cli bce.Client, bucket string, confBody *bce.Body) error { +func PutBucketCors(cli bce.Client, bucket string, confBody *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("cors", "") + ctx.Bucket = bucket if confBody != nil { req.SetHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE) req.SetBody(confBody) } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -836,15 +858,15 @@ func PutBucketCors(cli bce.Client, bucket string, confBody *bce.Body) error { // RETURNS: // - result: the bucket CORS config result object // - error: nil if success otherwise the specific error -func GetBucketCors(cli bce.Client, bucket string) ( +func GetBucketCors(cli bce.Client, bucket string, ctx *BosContext) ( *GetBucketCorsResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("cors", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -864,13 +886,14 @@ func GetBucketCors(cli bce.Client, bucket string) ( // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketCors(cli bce.Client, bucket string) error { +func DeleteBucketCors(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("cors", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -888,11 +911,12 @@ func DeleteBucketCors(cli bce.Client, bucket string) error { // - resources: the resource items in the bucket to be protected // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketCopyrightProtection(cli bce.Client, bucket string, resources ...string) error { +func PutBucketCopyrightProtection(cli bce.Client, ctx *BosContext, bucket string, resources ...string) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("copyrightProtection", "") + ctx.Bucket = bucket if len(resources) == 0 { return bce.NewBceClientError("the resource to set copyright protection is empty") } @@ -909,7 +933,7 @@ func PutBucketCopyrightProtection(cli bce.Client, bucket string, resources ...st req.SetBody(body) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -927,14 +951,14 @@ func PutBucketCopyrightProtection(cli bce.Client, bucket string, resources ...st // RETURNS: // - result: the bucket copyright protection resources array // - error: nil if success otherwise the specific error -func GetBucketCopyrightProtection(cli bce.Client, bucket string) ([]string, error) { +func GetBucketCopyrightProtection(cli bce.Client, bucket string, ctx *BosContext) ([]string, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("copyrightProtection", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -954,13 +978,14 @@ func GetBucketCopyrightProtection(cli bce.Client, bucket string) ([]string, erro // - bucket: the bucket name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteBucketCopyrightProtection(cli bce.Client, bucket string) error { +func DeleteBucketCopyrightProtection(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("copyrightProtection", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -978,11 +1003,12 @@ func DeleteBucketCopyrightProtection(cli bce.Client, bucket string) error { // - trashDir: the trash dir name // RETURNS: // - error: nil if success otherwise the specific error -func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq) error { +func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("trash", "") + ctx.Bucket = bucket reqByte, _ := json.Marshal(trashReq) body, err := bce.NewBodyFromString(string(reqByte)) if err != nil { @@ -990,7 +1016,7 @@ func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq) e } req.SetBody(body) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -1000,13 +1026,14 @@ func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq) e return nil } -func GetBucketTrash(cli bce.Client, bucket string) (*GetBucketTrashResult, error) { +func GetBucketTrash(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketTrashResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("trash", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -1019,13 +1046,14 @@ func GetBucketTrash(cli bce.Client, bucket string) (*GetBucketTrashResult, error return result, nil } -func DeleteBucketTrash(cli bce.Client, bucket string) error { +func DeleteBucketTrash(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("trash", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -1035,11 +1063,12 @@ func DeleteBucketTrash(cli bce.Client, bucket string) error { return nil } -func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationReq PutBucketNotificationReq) error { +func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationReq PutBucketNotificationReq, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("notification", "") + ctx.Bucket = bucket reqByte, _ := json.Marshal(putBucketNotificationReq) body, err := bce.NewBodyFromString(string(reqByte)) if err != nil { @@ -1047,7 +1076,7 @@ func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationR } req.SetBody(body) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -1057,13 +1086,14 @@ func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationR return nil } -func GetBucketNotification(cli bce.Client, bucket string) (*PutBucketNotificationReq, error) { +func GetBucketNotification(cli bce.Client, bucket string, ctx *BosContext) (*PutBucketNotificationReq, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("notification", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -1076,13 +1106,134 @@ func GetBucketNotification(cli bce.Client, bucket string) (*PutBucketNotificatio return result, nil } -func DeleteBucketNotification(cli bce.Client, bucket string) error { +func DeleteBucketNotification(cli bce.Client, bucket string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("notification", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} + +func PutBucketMirror(cli bce.Client, bucket string, putBucketMirrorArgs *PutBucketMirrorArgs, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.PUT) + req.SetParam("mirroring", "") + ctx.Bucket = bucket + reqByte, _ := json.Marshal(putBucketMirrorArgs) + body, err := bce.NewBodyFromString(string(reqByte)) + if err != nil { + return err + } + req.SetBody(body) + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} + +func GetBucketMirror(cli bce.Client, bucket string, ctx *BosContext) (*PutBucketMirrorArgs, error) { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.GET) + req.SetParam("mirroring", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return nil, err + } + if resp.IsFail() { + return nil, resp.ServiceError() + } + result := &PutBucketMirrorArgs{} + if err := resp.ParseJsonBody(result); err != nil { + return nil, err + } + return result, nil +} + +func DeleteBucketMirror(cli bce.Client, bucket string, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.DELETE) + req.SetParam("mirroring", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} + +func PutBucketTag(cli bce.Client, bucket string, putBucketTagArgs *PutBucketTagArgs, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.PUT) + req.SetParam("tagging", "") + ctx.Bucket = bucket + reqByte, _ := json.Marshal(putBucketTagArgs) + body, err := bce.NewBodyFromString(string(reqByte)) + if err != nil { + return err + } + req.SetBody(body) + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} + +func GetBucketTag(cli bce.Client, bucket string, ctx *BosContext) (*GetBucketTagResult, error) { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.GET) + req.SetParam("tagging", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return nil, err + } + if resp.IsFail() { + return nil, resp.ServiceError() + } + result := &GetBucketTagResult{} + if err := resp.ParseJsonBody(result); err != nil { + return nil, err + } + return result, nil +} + +func DeleteBucketTag(cli bce.Client, bucket string, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getBucketUri(bucket)) + req.SetMethod(http.DELETE) + req.SetParam("tagging", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/model.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/model.go index 30fd7f731f38d..914fa21d16d4b 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/model.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/model.go @@ -58,6 +58,10 @@ type PrefixType struct { Prefix string `json:"prefix"` } +type PutBucketArgs struct { + TagList string +} + // ListObjectsResult defines the result structure of ListObjects api. type ListObjectsResult struct { Name string `json:"name"` @@ -172,18 +176,20 @@ type StorageClassType struct { type BucketReplicationDescriptor struct { Bucket string `json:"bucket,omitempty"` StorageClass string `json:"storageClass,omitempty"` + Prefix string `json:"prefix,omitempty"` } // BucketReplicationType defines the data structure for Put and Get of bucket replication type BucketReplicationType struct { - Id string `json:"id"` - Status string `json:"status"` - Resource []string `json:"resource"` - ReplicateDeletes string `json:"replicateDeletes"` - Destination *BucketReplicationDescriptor `json:"destination,omitempty"` - ReplicateHistory *BucketReplicationDescriptor `json:"replicateHistory,omitempty"` - CreateTime int64 `json:"createTime"` - DestRegion string `json:"destRegion"` + Id string `json:"id"` + Status string `json:"status"` + Resource []string `json:"resource"` + NotIncludeResource []string `json:"notIncludeResource,omitempty"` + ReplicateDeletes string `json:"replicateDeletes"` + Destination *BucketReplicationDescriptor `json:"destination,omitempty"` + ReplicateHistory *BucketReplicationDescriptor `json:"replicateHistory,omitempty"` + CreateTime int64 `json:"createTime"` + DestRegion string `json:"destRegion"` } type PutBucketReplicationArgs BucketReplicationType @@ -259,6 +265,8 @@ type PutObjectArgs struct { ContentCrc32 string StorageClass string Process string + CannedAcl string + ObjectTagging string TrafficLimit int64 } @@ -270,13 +278,22 @@ type CopyObjectArgs struct { IfNoneMatch string IfModifiedSince string IfUnmodifiedSince string - TrafficLimit int64 + TrafficLimit int64 + CannedAcl string } type MultiCopyObjectArgs struct { StorageClass string } +type CallbackResult struct { + Result string `json:"result"` +} + +type PutObjectResult struct { + Callback CallbackResult `json:"callback"` +} + // CopyObjectResult defines the result json structure for the copy object api. type CopyObjectResult struct { LastModified string `json:"lastModified"` @@ -462,13 +479,14 @@ type UploadPartCopyArgs struct { IfNoneMatch string IfModifiedSince string IfUnmodifiedSince string - TrafficLimit int64 + TrafficLimit int64 } type PutSymlinkArgs struct { ForbidOverwrite string StorageClass string UserMeta map[string]string + SymlinkBucket string } // UploadInfoType defines an uploaded part info structure. @@ -583,3 +601,65 @@ type PutBucketNotificationAppsSt struct { EventUrl string `json:"eventUrl"` XVars string `json:"xVars"` } + +type MirrorConfigurationRule struct { + Prefix string `json:"prefix,omitempty"` + SourceUrl string `json:"sourceUrl"` + PassQueryString bool `json:"passQuerystring"` + Mode string `json:"mode"` + StorageClass string `json:"storageClass"` + PassHeaders []string `json:"passHeaders"` + IgnoreHeaders []string `json:"ignoreHeaders"` + CustomHeaders []HeaderPair `json:"customHeaders"` + BackSourceUrl string `json:"backSourceUrl"` + Resource string `json:"resource"` + Suffix string `json:"suffix"` + FixedKey string `json:"fixedKey"` + PrefixReplace string `json:"prefixReplace"` + Version string `json:"version"` +} + +type HeaderPair struct { + HeaderName string `json:"headerName"` + HeaderValue string `json:"headerValue"` +} + +type PutBucketMirrorArgs struct { + BucketMirroringConfiguration []MirrorConfigurationRule `json:"bucketMirroringConfiguration"` +} + +type PutBucketTagArgs struct { + Tags []Tag `json:"tags"` +} + +type Tag struct { + TagKey string `json:"tagKey"` + TagValue string `json:"tagValue"` +} + +type GetBucketTagResult struct { + Tags []BucketTag `json:"tag"` +} + +type BucketTag struct { + TagKey string `json:"tag_key"` + TagValue string `json:"tag_value"` +} + +type BosContext struct { + Bucket string + PathStyleEnable bool +} + +type PutObjectTagArgs struct { + ObjectTags []ObjectTags `json:"tagSet"` +} + +type ObjectTags struct { + TagInfo []ObjectTag `json:"tagInfo"` +} + +type ObjectTag struct { + Key string `json:"key"` + Value string `json:"value"` +} diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/multipart.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/multipart.go index 806017b39eff8..0f86fa6404515 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/multipart.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/multipart.go @@ -39,11 +39,12 @@ import ( // - *InitiateMultipartUploadResult: the result data structure // - error: nil if ok otherwise the specific error func InitiateMultipartUpload(cli bce.Client, bucket, object, contentType string, - args *InitiateMultipartUploadArgs) (*InitiateMultipartUploadResult, error) { + args *InitiateMultipartUploadArgs, ctx *BosContext) (*InitiateMultipartUploadResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("uploads", "") + ctx.Bucket = bucket if len(contentType) == 0 { contentType = RAW_CONTENT_TYPE } @@ -69,7 +70,7 @@ func InitiateMultipartUpload(cli bce.Client, bucket, object, contentType string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -97,12 +98,13 @@ func InitiateMultipartUpload(cli bce.Client, bucket, object, contentType string, // - string: the etag of the uploaded part // - error: nil if ok otherwise the specific error func UploadPart(cli bce.Client, bucket, object, uploadId string, partNumber int, - content *bce.Body, args *UploadPartArgs) (string, error) { + content *bce.Body, args *UploadPartArgs, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) req.SetParam("uploadId", uploadId) req.SetParam("partNumber", fmt.Sprintf("%d", partNumber)) + ctx.Bucket = bucket if content == nil { return "", bce.NewBceClientError("upload part content should not be empty") } @@ -130,7 +132,7 @@ func UploadPart(cli bce.Client, bucket, object, uploadId string, partNumber int, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { @@ -154,12 +156,13 @@ func UploadPart(cli bce.Client, bucket, object, uploadId string, partNumber int, // - string: the etag of the uploaded part // - error: nil if ok otherwise the specific error func UploadPartFromBytes(cli bce.Client, bucket, object, uploadId string, partNumber int, - content []byte, args *UploadPartArgs) (string, error) { + content []byte, args *UploadPartArgs, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) req.SetParam("uploadId", uploadId) req.SetParam("partNumber", fmt.Sprintf("%d", partNumber)) + ctx.Bucket = bucket if content == nil { return "", bce.NewBceClientError("upload part content should not be empty") } @@ -188,6 +191,14 @@ func UploadPartFromBytes(cli bce.Client, bucket, object, uploadId string, partNu http.BCE_CONTENT_SHA256: args.ContentSha256, http.BCE_CONTENT_CRC32: args.ContentCrc32, }) + //set traffic-limit + if args.TrafficLimit > 0 { + if args.TrafficLimit > TRAFFIC_LIMIT_MAX || args.TrafficLimit < TRAFFIC_LIMIT_MIN { + return "", bce.NewBceClientError(fmt.Sprintf("TrafficLimit must between %d ~ %d, current value:%d", + TRAFFIC_LIMIT_MIN, TRAFFIC_LIMIT_MAX, args.TrafficLimit)) + } + req.SetHeader(http.BCE_TRAFFIC_LIMIT, fmt.Sprintf("%d", args.TrafficLimit)) + } } // Send request and get the result resp := &bce.BceResponse{} @@ -215,12 +226,13 @@ func UploadPartFromBytes(cli bce.Client, bucket, object, uploadId string, partNu // - *CopyObjectResult: the lastModified and eTag of the part // - error: nil if ok otherwise the specific error func UploadPartCopy(cli bce.Client, bucket, object, source, uploadId string, partNumber int, - args *UploadPartCopyArgs) (*CopyObjectResult, error) { + args *UploadPartCopyArgs, ctx *BosContext) (*CopyObjectResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) req.SetParam("uploadId", uploadId) req.SetParam("partNumber", fmt.Sprintf("%d", partNumber)) + ctx.Bucket = bucket if len(source) == 0 { return nil, bce.NewBceClientError("upload part copy source should not be empty") } @@ -246,7 +258,7 @@ func UploadPartCopy(cli bce.Client, bucket, object, source, uploadId string, par // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -272,11 +284,12 @@ func UploadPartCopy(cli bce.Client, bucket, object, source, uploadId string, par // - *CompleteMultipartUploadResult: the result data // - error: nil if ok otherwise the specific error func CompleteMultipartUpload(cli bce.Client, bucket, object, uploadId string, - body *bce.Body, args *CompleteMultipartUploadArgs) (*CompleteMultipartUploadResult, error) { + body *bce.Body, args *CompleteMultipartUploadArgs, ctx *BosContext) (*CompleteMultipartUploadResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("uploadId", uploadId) + ctx.Bucket = bucket if body == nil { return nil, bce.NewBceClientError("upload body info should not be emtpy") } @@ -300,7 +313,7 @@ func CompleteMultipartUpload(cli bce.Client, bucket, object, uploadId string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -326,14 +339,14 @@ func CompleteMultipartUpload(cli bce.Client, bucket, object, uploadId string, // - uploadId: the multipart upload id // RETURNS: // - error: nil if ok otherwise the specific error -func AbortMultipartUpload(cli bce.Client, bucket, object, uploadId string) error { +func AbortMultipartUpload(cli bce.Client, bucket, object, uploadId string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.DELETE) req.SetParam("uploadId", uploadId) - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -357,12 +370,12 @@ func AbortMultipartUpload(cli bce.Client, bucket, object, uploadId string) error // - *ListPartsResult: the uploaded parts info result // - error: nil if ok otherwise the specific error func ListParts(cli bce.Client, bucket, object, uploadId string, - args *ListPartsArgs) (*ListPartsResult, error) { + args *ListPartsArgs, ctx *BosContext) (*ListPartsResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.GET) req.SetParam("uploadId", uploadId) - + ctx.Bucket = bucket // Optional arguments settings if args != nil { if len(args.PartNumberMarker) > 0 { @@ -375,7 +388,7 @@ func ListParts(cli bce.Client, bucket, object, uploadId string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -398,11 +411,12 @@ func ListParts(cli bce.Client, bucket, object, uploadId string, // - *ListMultipartUploadsResult: the unfinished uploaded parts info result // - error: nil if ok otherwise the specific error func ListMultipartUploads(cli bce.Client, bucket string, - args *ListMultipartUploadsArgs) (*ListMultipartUploadsResult, error) { + args *ListMultipartUploadsArgs, ctx *BosContext) (*ListMultipartUploadsResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("uploads", "") + ctx.Bucket = bucket // Optional arguments settings if args != nil { @@ -422,7 +436,7 @@ func ListMultipartUploads(cli bce.Client, bucket string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/object.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/object.go index c8f9a6acd54d7..b4f2269b9ffb8 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/object.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/object.go @@ -19,6 +19,7 @@ package api import ( "encoding/json" "fmt" + "io/ioutil" "net" "strconv" "strings" @@ -41,12 +42,14 @@ import ( // - string: the etag of the object // - error: nil if ok otherwise the specific error func PutObject(cli bce.Client, bucket, object string, body *bce.Body, - args *PutObjectArgs) (string, error) { + args *PutObjectArgs, ctx *BosContext) (string, *PutObjectResult, error) { req := &bce.BceRequest{} + NeedReturnCallback := false req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) + ctx.Bucket = bucket if body == nil { - return "", bce.NewBceClientError("PutObject body should not be emtpy") + return "", nil, bce.NewBceClientError("PutObject body should not be emtpy") } if body.Size() >= THRESHOLD_100_CONTINUE { req.SetHeader("Expect", "100-continue") @@ -68,11 +71,11 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, // be reset. The `net/http.Client' does not support the Content-Length bigger than the // body size. if args.ContentLength > body.Size() { - return "", bce.NewBceClientError(fmt.Sprintf("ContentLength %d is bigger than body size %d", args.ContentLength, body.Size())) + return "", nil, bce.NewBceClientError(fmt.Sprintf("ContentLength %d is bigger than body size %d", args.ContentLength, body.Size())) } body, err := bce.NewBodyFromSizedReader(body.Stream(), args.ContentLength) if err != nil { - return "", bce.NewBceClientError(err.Error()) + return "", nil, bce.NewBceClientError(err.Error()) } req.SetHeader(http.CONTENT_LENGTH, fmt.Sprintf("%d", args.ContentLength)) req.SetBody(body) // re-assign body @@ -81,7 +84,7 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, //set traffic-limit if args.TrafficLimit > 0 { if args.TrafficLimit > TRAFFIC_LIMIT_MAX || args.TrafficLimit < TRAFFIC_LIMIT_MIN { - return "", bce.NewBceClientError(fmt.Sprintf("TrafficLimit must between %d ~ %d, current value:%d", TRAFFIC_LIMIT_MIN, TRAFFIC_LIMIT_MAX, args.TrafficLimit)) + return "", nil, bce.NewBceClientError(fmt.Sprintf("TrafficLimit must between %d ~ %d, current value:%d", TRAFFIC_LIMIT_MIN, TRAFFIC_LIMIT_MAX, args.TrafficLimit)) } req.SetHeader(http.BCE_TRAFFIC_LIMIT, fmt.Sprintf("%d", args.TrafficLimit)) } @@ -95,17 +98,30 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, req.SetHeader(http.BCE_STORAGE_CLASS, args.StorageClass) } else { if len(args.StorageClass) != 0 { - return "", bce.NewBceClientError("invalid storage class value: " + + return "", nil, bce.NewBceClientError("invalid storage class value: " + args.StorageClass) } } if err := setUserMetadata(req, args.UserMeta); err != nil { - return "", err + return "", nil, err } if len(args.Process) != 0 { req.SetHeader(http.BCE_PROCESS, args.Process) + if strings.HasPrefix(args.Process, "callback") { + NeedReturnCallback = true + } + } + if len(args.CannedAcl) != 0 { + if validCannedAcl(args.CannedAcl) { + req.SetHeader(http.BCE_ACL, args.CannedAcl) + } + } + if len(args.ObjectTagging) != 0 { + if ok, encodeTagging := validObjectTagging(args.ObjectTagging); ok { + req.SetHeader(http.BCE_OBJECT_TAGGING, encodeTagging) + } } } // add content-type if not assigned by user @@ -114,14 +130,21 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, } resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { - return "", err + if err := SendRequest(cli, req, resp, ctx); err != nil { + return "", nil, err } if resp.IsFail() { - return "", resp.ServiceError() + return "", nil, resp.ServiceError() } defer func() { resp.Body().Close() }() - return strings.Trim(resp.Header(http.ETAG), "\""), nil + if NeedReturnCallback { + jsonBody := &PutObjectResult{} + if err := resp.ParseJsonBody(jsonBody); err != nil { + return "", nil, err + } + return strings.Trim(resp.Header(http.ETAG), "\""), jsonBody, nil + } + return strings.Trim(resp.Header(http.ETAG), "\""), nil, nil } // CopyObject - copy one object to a new object with new bucket and/or name. It can alse set the @@ -137,10 +160,11 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, // - *CopyObjectResult: the result object which contains etag and lastmodified // - error: nil if ok otherwise the specific error func CopyObject(cli bce.Client, bucket, object, source string, - args *CopyObjectArgs) (*CopyObjectResult, error) { + args *CopyObjectArgs, ctx *BosContext) (*CopyObjectResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) + ctx.Bucket = bucket if len(source) == 0 { return nil, bce.NewBceClientError("copy source should not be null") } @@ -194,6 +218,10 @@ func CopyObject(cli bce.Client, bucket, object, source string, req.SetHeader(http.BCE_TRAFFIC_LIMIT, fmt.Sprintf("%d", args.TrafficLimit)) } + if validCannedAcl(args.CannedAcl) { + req.SetHeader(http.BCE_ACL, args.CannedAcl) + } + if err := setUserMetadata(req, args.UserMeta); err != nil { return nil, err } @@ -201,7 +229,7 @@ func CopyObject(cli bce.Client, bucket, object, source string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -220,12 +248,12 @@ func CopyObject(cli bce.Client, bucket, object, source string, // - cli: the client agent which can perform sending request // - bucket: the bucket name of the object // - object: the name of the object -// - responseHeaders: the optional response headers to get the given object +// - args: the optional args in querysring // - ranges: the optional range start and end to get the given object // RETURNS: // - *GetObjectResult: the output content result of the object // - error: nil if ok otherwise the specific error -func GetObject(cli bce.Client, bucket, object string, responseHeaders map[string]string, +func GetObject(cli bce.Client, bucket, object string, ctx *BosContext, args map[string]string, // nolint:gocyclo ranges ...int64) (*GetObjectResult, error) { if object == "" { @@ -235,13 +263,16 @@ func GetObject(cli bce.Client, bucket, object string, responseHeaders map[string req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.GET) - + ctx.Bucket = bucket // Optional arguments settings - if responseHeaders != nil { - for k, v := range responseHeaders { + if args != nil { + for k, v := range args { if _, ok := GET_OBJECT_ALLOWED_RESPONSE_HEADERS[k]; ok { req.SetParam("response"+k, v) } + if strings.HasPrefix(k, http.BCE_PREFIX) { + req.SetParam(k, v) + } } } if len(ranges) != 0 { @@ -256,7 +287,7 @@ func GetObject(cli bce.Client, bucket, object string, responseHeaders map[string // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -336,14 +367,14 @@ func GetObject(cli bce.Client, bucket, object string, responseHeaders map[string // RETURNS: // - *GetObjectMetaResult: the result of this api // - error: nil if ok otherwise the specific error -func GetObjectMeta(cli bce.Client, bucket, object string) (*GetObjectMetaResult, error) { +func GetObjectMeta(cli bce.Client, bucket, object string, ctx *BosContext) (*GetObjectMetaResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.HEAD) - + ctx.Bucket = bucket // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -427,13 +458,13 @@ func GetObjectMeta(cli bce.Client, bucket, object string) (*GetObjectMetaResult, // RETURNS: // - *SelectObjectResult: the output select content result of the object // - error: nil if ok otherwise the specific error -func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs) (*SelectObjectResult, error) { +func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs, ctx *BosContext) (*SelectObjectResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("select", "") req.SetParam("type", args.SelectType) - + ctx.Bucket = bucket jsonBytes, jsonErr := json.Marshal(args) if jsonErr != nil { return nil, jsonErr @@ -446,7 +477,7 @@ func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs) // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -471,11 +502,12 @@ func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs) // - *FetchObjectArgs: the result of this api // - error: nil if ok otherwise the specific error func FetchObject(cli bce.Client, bucket, object, source string, - args *FetchObjectArgs) (*FetchObjectResult, error) { + args *FetchObjectArgs, ctx *BosContext) (*FetchObjectResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("fetch", "") + ctx.Bucket = bucket if len(source) == 0 { return nil, bce.NewBceClientError("invalid fetch source value: " + source) } @@ -502,7 +534,7 @@ func FetchObject(cli bce.Client, bucket, object, source string, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -527,11 +559,12 @@ func FetchObject(cli bce.Client, bucket, object, source string, // - *AppendObjectResult: the result status for this api // - error: nil if ok otherwise the specific error func AppendObject(cli bce.Client, bucket, object string, content *bce.Body, - args *AppendObjectArgs) (*AppendObjectResult, error) { + args *AppendObjectArgs, ctx *BosContext) (*AppendObjectResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("append", "") + ctx.Bucket = bucket if content == nil { return nil, bce.NewBceClientError("AppendObject body should not be emtpy") } @@ -581,7 +614,7 @@ func AppendObject(cli bce.Client, bucket, object string, content *bce.Body, // Send request and get the result resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -619,13 +652,13 @@ func AppendObject(cli bce.Client, bucket, object string, content *bce.Body, // - object: the name of the object // RETURNS: // - error: nil if ok otherwise the specific error -func DeleteObject(cli bce.Client, bucket, object string) error { +func DeleteObject(cli bce.Client, bucket, object string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.DELETE) - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -645,12 +678,13 @@ func DeleteObject(cli bce.Client, bucket, object string) error { // - *DeleteMultipleObjectsResult: the objects failed to delete // - error: nil if ok otherwise the specific error func DeleteMultipleObjects(cli bce.Client, bucket string, - objectListStream *bce.Body) (*DeleteMultipleObjectsResult, error) { + objectListStream *bce.Body, ctx *BosContext) (*DeleteMultipleObjectsResult, error) { req := &bce.BceRequest{} req.SetUri(getBucketUri(bucket)) req.SetMethod(http.POST) req.SetParam("delete", "") req.SetHeader(http.CONTENT_TYPE, "application/json; charset=utf-8") + ctx.Bucket = bucket if objectListStream == nil { return nil, bce.NewBceClientError("DeleteMultipleObjects body should not be emtpy") } @@ -660,13 +694,18 @@ func DeleteMultipleObjects(cli bce.Client, bucket string, req.SetBody(objectListStream) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { return nil, resp.ServiceError() } jsonBody := &DeleteMultipleObjectsResult{} + + if resp.Header(http.CONTENT_LENGTH) == "0" { + resp.Body().Close() + return jsonBody, nil + } if err := resp.ParseJsonBody(jsonBody); err != nil { return nil, err } @@ -772,12 +811,12 @@ func GeneratePresignedUrlInternal(conf *bce.BceClientConfiguration, signer auth. // RETURNS: // - error: nil if success otherwise the specific error func PutObjectAcl(cli bce.Client, bucket, object, cannedAcl string, - grantRead, grantFullControl []string, aclBody *bce.Body) error { + grantRead, grantFullControl []string, aclBody *bce.Body, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) req.SetParam("acl", "") - + ctx.Bucket = bucket // Joiner for generate the user id list string for grant acl header joiner := func(ids []string) string { for i := range ids { @@ -813,7 +852,7 @@ func PutObjectAcl(cli bce.Client, bucket, object, cannedAcl string, // Do sending request resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -832,14 +871,14 @@ func PutObjectAcl(cli bce.Client, bucket, object, cannedAcl string, // RETURNS: // - result: the object acl result object // - error: nil if success otherwise the specific error -func GetObjectAcl(cli bce.Client, bucket, object string) (*GetObjectAclResult, error) { +func GetObjectAcl(cli bce.Client, bucket, object string, ctx *BosContext) (*GetObjectAclResult, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.GET) req.SetParam("acl", "") - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return nil, err } if resp.IsFail() { @@ -860,13 +899,14 @@ func GetObjectAcl(cli bce.Client, bucket, object string) (*GetObjectAclResult, e // - object: the object name // RETURNS: // - error: nil if success otherwise the specific error -func DeleteObjectAcl(cli bce.Client, bucket, object string) error { +func DeleteObjectAcl(cli bce.Client, bucket, object string, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.DELETE) req.SetParam("acl", "") + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -885,16 +925,16 @@ func DeleteObjectAcl(cli bce.Client, bucket, object string) error { // - args: the restore args // RETURNS: // - error: nil if success otherwise the specific error -func RestoreObject(cli bce.Client, bucket string, object string, args ArchiveRestoreArgs) error { +func RestoreObject(cli bce.Client, bucket string, object string, args ArchiveRestoreArgs, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, object)) req.SetParam("restore", "") req.SetMethod(http.POST) req.SetHeader(http.BCE_RESTORE_DAYS, strconv.Itoa(args.RestoreDays)) req.SetHeader(http.BCE_RESTORE_TIER, args.RestoreTier) - + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -914,11 +954,12 @@ func RestoreObject(cli bce.Client, bucket string, object string, args ArchiveRes // - symlinkArgs: the optional arguments of this api // RETURNS: // - error: nil if ok otherwise the specific error -func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey string, symlinkArgs *PutSymlinkArgs) error { +func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey string, symlinkArgs *PutSymlinkArgs, ctx *BosContext) error { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, symlinkKey)) req.SetParam("symlink", "") req.SetMethod(http.PUT) + ctx.Bucket = bucket if symlinkArgs != nil { if len(symlinkArgs.ForbidOverwrite) != 0 { if !validForbidOverwrite(symlinkArgs.ForbidOverwrite) { @@ -942,11 +983,14 @@ func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey s return err } } + if len(symlinkArgs.SymlinkBucket) != 0 { + req.SetHeader(http.BCE_SYMLINK_BUCKET, symlinkArgs.SymlinkBucket) + } } req.SetHeader(http.BCE_SYMLINK_TARGET, object) resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return err } if resp.IsFail() { @@ -965,18 +1009,99 @@ func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey s // RETURNS: // - string: the name of the target object // - error: nil if ok otherwise the specific error -func GetObjectSymlink(cli bce.Client, bucket string, symlinkKey string) (string, error) { +func GetObjectSymlink(cli bce.Client, bucket string, symlinkKey string, ctx *BosContext) (string, error) { req := &bce.BceRequest{} req.SetUri(getObjectUri(bucket, symlinkKey)) req.SetParam("symlink", "") req.SetMethod(http.GET) + ctx.Bucket = bucket resp := &bce.BceResponse{} - if err := SendRequest(cli, req, resp); err != nil { + if err := SendRequest(cli, req, resp, ctx); err != nil { return "", err } if resp.IsFail() { return "", resp.ServiceError() } defer func() { resp.Body().Close() }() + if resp.Header(http.BCE_SYMLINK_BUCKET) != "" { + result := BOS_CONFIG_PREFIX + resp.Header(http.BCE_SYMLINK_BUCKET) + "/" + resp.Header(http.BCE_SYMLINK_TARGET) + return result, nil + } return resp.Header(http.BCE_SYMLINK_TARGET), nil } + +// PutObjectTag - set tag for given object +// +// PARAMS: +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - putObjectTagArgs: the arguments of object tag +// RETURNS: +// - error: nil if ok otherwise the specific error + +func PutObjectTag(cli bce.Client, bucket, object string, putObjectTagArgs *PutObjectTagArgs, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getObjectUri(bucket, object)) + req.SetMethod(http.PUT) + req.SetParam("tagging", "") + ctx.Bucket = bucket + reqByte, _ := json.Marshal(putObjectTagArgs) + body, err := bce.NewBodyFromString(string(reqByte)) + if err != nil { + return err + } + req.SetBody(body) + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} + +func GetObjectTag(cli bce.Client, bucket, object string, ctx *BosContext) (map[string]interface{}, error) { + req := &bce.BceRequest{} + req.SetUri(getObjectUri(bucket, object)) + req.SetMethod(http.GET) + req.SetParam("tagging", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return nil, err + } + if resp.IsFail() { + return nil, resp.ServiceError() + } + defer func() { resp.Body().Close() }() + bodyBytes, err := ioutil.ReadAll(resp.Body()) + if err != nil { + return nil, err + } + + result, err := ParseObjectTagResult(bodyBytes) + if err != nil { + return nil, err + } + return result, nil +} + +func DeleteObjectTag(cli bce.Client, bucket, object string, ctx *BosContext) error { + req := &bce.BceRequest{} + req.SetUri(getObjectUri(bucket, object)) + req.SetMethod(http.DELETE) + req.SetParam("tagging", "") + ctx.Bucket = bucket + resp := &bce.BceResponse{} + if err := SendRequest(cli, req, resp, ctx); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + defer func() { resp.Body().Close() }() + return nil +} diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/util.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/util.go index d5ce8bc6ee54a..31ba002b7e089 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/util.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/api/util.go @@ -18,7 +18,11 @@ package api import ( "bytes" + "encoding/json" + "fmt" + "net" net_http "net/http" + "net/url" "strings" "github.com/baidubce/bce-sdk-go/bce" @@ -59,6 +63,9 @@ const ( FORBID_OVERWRITE_FALSE = "false" FORBID_OVERWRITE_TRUE = "true" + + NAMESPACE_BUCKET = "namespace" + BOS_CONFIG_PREFIX = "bos://" ) var DEFAULT_CNAME_LIKE_LIST = []string{ @@ -150,6 +157,29 @@ func validCannedAcl(val string) bool { return false } +func validObjectTagging(tagging string) (bool, string) { + if len(tagging) > 4000 { + return false, "" + } + encodeTagging := []string{} + pair := strings.Split(tagging, "&") + for _, p := range pair { + kv := strings.Split(p, "=") + if len(kv) != 2 { + return false, "" + } + key := kv[0] + value := kv[1] + encodeKey := url.QueryEscape(key) + encodeValue := url.QueryEscape(value) + if len(encodeKey) > 128 || len(encodeValue) > 256 { + return false, "" + } + encodeTagging = append(encodeTagging, encodeKey+"="+encodeValue) + } + return true, strings.Join(encodeTagging, "&") +} + func toHttpHeaderKey(key string) string { var result bytes.Buffer needToUpper := true @@ -235,22 +265,18 @@ func isCnameLikeHost(host string) bool { return true } } + if isVirtualHost(host) { + return true + } return false } -func SendRequest(cli bce.Client, req *bce.BceRequest, resp *bce.BceResponse) error { +func SendRequest(cli bce.Client, req *bce.BceRequest, resp *bce.BceResponse, ctx *BosContext) error { var ( err error need_retry bool ) - - req.SetEndpoint(cli.GetBceClientConfig().Endpoint) - origin_uri := req.Uri() - // set uri for cname or cdn endpoint - if cli.GetBceClientConfig().CnameEnabled || isCnameLikeHost(cli.GetBceClientConfig().Endpoint) { - req.SetUri(getCnameUri(origin_uri)) - } - + setUriAndEndpoint(cli, req, ctx, cli.GetBceClientConfig().Endpoint) if err = cli.SendRequest(req, resp); err != nil { if serviceErr, isServiceErr := err.(*bce.BceServiceError); isServiceErr { if serviceErr.StatusCode == net_http.StatusInternalServerError || @@ -265,10 +291,7 @@ func SendRequest(cli bce.Client, req *bce.BceRequest, resp *bce.BceResponse) err } // retry backup endpoint if need_retry && cli.GetBceClientConfig().BackupEndpoint != "" { - req.SetEndpoint(cli.GetBceClientConfig().BackupEndpoint) - if cli.GetBceClientConfig().CnameEnabled || isCnameLikeHost(cli.GetBceClientConfig().BackupEndpoint) { - req.SetUri(getCnameUri(origin_uri)) - } + setUriAndEndpoint(cli, req, ctx, cli.GetBceClientConfig().BackupEndpoint) if err = cli.SendRequest(req, resp); err != nil { return err } @@ -277,6 +300,102 @@ func SendRequest(cli bce.Client, req *bce.BceRequest, resp *bce.BceResponse) err return err } +func isVirtualHost(host string) bool { + domain := getDomainWithoutPort(host) + arr := strings.Split(domain, ".") + if len(arr) != 4 { + return false + } + // bucket max length is 64 + if len(arr[0]) == 0 || len(arr[0]) > 64 { + return false + } + if arr[2] != "bcebos" || arr[3] != "com" { + return false + } + return true +} + +func isIpHost(host string) bool { + domain := getDomainWithoutPort(host) + validIp := net.ParseIP(domain) + return validIp != nil +} + +func isBosHost(host string) bool { + domain := getDomainWithoutPort(host) + arr := strings.Split(domain, ".") + if len(arr) != 3 { + return false + } + if arr[1] != "bcebos" || arr[2] != "com" { + return false + } + return true +} + +func getDomainWithoutPort(host string) string { + end := 0 + if end = strings.Index(host, ":"); end == -1 { + end = len(host) + } + return host[:end] +} + +func needCompatibleBucketAndEndpoint(bucket, endpoint string) bool { + if bucket == "" { + return false + } + if !isVirtualHost(endpoint) { + return false + } + if strings.Split(endpoint, ".")[0] == bucket { + return false + } + // bucket from sdk and from endpoint is different + return true +} + +// replace endpoint by bucket, only effective when two bucket are in same region, otherwise server return NoSuchBucket error +func replaceEndpointByBucket(bucket, endpoint string) string { + arr := strings.Split(endpoint, ".") + arr[0] = bucket + return strings.Join(arr, ".") +} + +func setUriAndEndpoint(cli bce.Client, req *bce.BceRequest, ctx *BosContext, endpoint string) { + origin_uri := req.Uri() + bucket := ctx.Bucket + // deal with protocal + if strings.HasPrefix(endpoint, "https://") { + req.SetProtocol(bce.HTTPS_PROTOCAL) + endpoint = strings.TrimPrefix(endpoint, "https://") + } else if strings.HasPrefix(endpoint, "http://") { + req.SetProtocol(bce.DEFAULT_PROTOCOL) + endpoint = strings.TrimPrefix(endpoint, "http://") + } + // set uri, endpoint for cname, cdn, virtual host + if cli.GetBceClientConfig().CnameEnabled || isCnameLikeHost(endpoint) { + req.SetEndpoint(endpoint) + // if virtual host endpoint and bucket is not empty, compatible bucket and endpoint + if needCompatibleBucketAndEndpoint(bucket, endpoint) { + req.SetEndpoint(replaceEndpointByBucket(bucket, endpoint)) + } + req.SetUri(getCnameUri(origin_uri)) + } else if isIpHost(endpoint) { + // set endpoint for ip host + req.SetEndpoint(endpoint) + } else if isBosHost(endpoint) { + // endpoint is xx.bcebos.com, set endpoint depends on PathStyleEnable + if bucket != "" && !ctx.PathStyleEnable { + req.SetEndpoint(bucket + "." + endpoint) + req.SetUri(getCnameUri(origin_uri)) + } else { + req.SetEndpoint(endpoint) + } + } +} + func getDefaultContentType(object string) string { dot := strings.LastIndex(object, ".") if dot == -1 { @@ -290,3 +409,27 @@ func getDefaultContentType(object string) string { return "application/octet-stream" } + +func ParseObjectTagResult(rawData []byte) (map[string]interface{}, error) { + var data map[string]interface{} + err := json.Unmarshal(rawData, &data) + if err != nil { + return nil, err + } + + tagSet, ok := data["tagSet"].([]interface{}) + if !ok || len(tagSet) == 0 { + return nil, fmt.Errorf("decode tagSet error") + } + + tagInfoMap, ok := tagSet[0].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("decode tagInfo error") + } + + tags, ok := tagInfoMap["tagInfo"].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("decode tags error") + } + return tags, nil +} diff --git a/vendor/github.com/baidubce/bce-sdk-go/services/bos/client.go b/vendor/github.com/baidubce/bce-sdk-go/services/bos/client.go index b449a869dbae8..aec79b24b2f06 100644 --- a/vendor/github.com/baidubce/bce-sdk-go/services/bos/client.go +++ b/vendor/github.com/baidubce/bce-sdk-go/services/bos/client.go @@ -23,11 +23,13 @@ import ( "errors" "fmt" "io" + "math" "net/http" "os" "github.com/baidubce/bce-sdk-go/auth" "github.com/baidubce/bce-sdk-go/bce" + sdk_http "github.com/baidubce/bce-sdk-go/http" "github.com/baidubce/bce-sdk-go/services/bos/api" "github.com/baidubce/bce-sdk-go/services/sts" "github.com/baidubce/bce-sdk-go/util/log" @@ -52,6 +54,7 @@ type Client struct { // Fileds that used in parallel operation for BOS service MaxParallel int64 MultipartSize int64 + BosContext *api.BosContext } // BosClientConfiguration defines the config components structure by user. @@ -60,6 +63,7 @@ type BosClientConfiguration struct { Sk string Endpoint string RedirectDisabled bool + PathStyleEnable bool } // NewClient make the BOS service client with default configuration. @@ -70,6 +74,7 @@ func NewClient(ak, sk, endpoint string) (*Client, error) { Sk: sk, Endpoint: endpoint, RedirectDisabled: false, + PathStyleEnable: false, }) } @@ -131,9 +136,11 @@ func NewClientWithConfig(config *BosClientConfiguration) (*Client, error) { ConnectionTimeoutInMillis: bce.DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS, RedirectDisabled: config.RedirectDisabled} v1Signer := &auth.BceV1Signer{} - + defaultContext := &api.BosContext{ + PathStyleEnable: config.PathStyleEnable, + } client := &Client{bce.NewBceClient(defaultConf, v1Signer), - DEFAULT_MAX_PARALLEL, DEFAULT_MULTIPART_SIZE} + DEFAULT_MAX_PARALLEL, DEFAULT_MULTIPART_SIZE, defaultContext} return client, nil } @@ -143,7 +150,7 @@ func NewClientWithConfig(config *BosClientConfiguration) (*Client, error) { // - *api.ListBucketsResult: the all buckets // - error: the return error if any occurs func (c *Client) ListBuckets() (*api.ListBucketsResult, error) { - return api.ListBuckets(c) + return api.ListBuckets(c, c.BosContext) } // ListObjects - list all objects of the given bucket @@ -156,7 +163,7 @@ func (c *Client) ListBuckets() (*api.ListBucketsResult, error) { // - error: the return error if any occurs func (c *Client) ListObjects(bucket string, args *api.ListObjectsArgs) (*api.ListObjectsResult, error) { - return api.ListObjects(c, bucket, args) + return api.ListObjects(c, bucket, args, c.BosContext) } // SimpleListObjects - list all objects of the given bucket with simple arguments @@ -173,7 +180,7 @@ func (c *Client) ListObjects(bucket string, func (c *Client) SimpleListObjects(bucket, prefix string, maxKeys int, marker, delimiter string) (*api.ListObjectsResult, error) { args := &api.ListObjectsArgs{delimiter, marker, maxKeys, prefix} - return api.ListObjects(c, bucket, args) + return api.ListObjects(c, bucket, args, c.BosContext) } // HeadBucket - test the given bucket existed and access authority @@ -183,7 +190,8 @@ func (c *Client) SimpleListObjects(bucket, prefix string, maxKeys int, marker, // RETURNS: // - error: nil if exists and have authority otherwise the specific error func (c *Client) HeadBucket(bucket string) error { - return api.HeadBucket(c, bucket) + err, _ := api.HeadBucket(c, bucket, c.BosContext) + return err } // DoesBucketExist - test the given bucket existed or not @@ -194,7 +202,7 @@ func (c *Client) HeadBucket(bucket string) error { // - bool: true if exists and false if not exists or occurs error // - error: nil if exists or not exist, otherwise the specific error func (c *Client) DoesBucketExist(bucket string) (bool, error) { - err := api.HeadBucket(c, bucket) + err, _ := api.HeadBucket(c, bucket, c.BosContext) if err == nil { return true, nil } @@ -209,6 +217,21 @@ func (c *Client) DoesBucketExist(bucket string) (bool, error) { return false, err } +//IsNsBucket - test the given bucket is namespace bucket or not +func (c *Client) IsNsBucket(bucket string) bool { + err, resp := api.HeadBucket(c, bucket, c.BosContext) + if err == nil && resp.Header(sdk_http.BCE_BUCKET_TYPE) == api.NAMESPACE_BUCKET { + return true + } + if realErr, ok := err.(*bce.BceServiceError); ok { + if realErr.StatusCode == http.StatusForbidden && + resp.Header(sdk_http.BCE_BUCKET_TYPE) == api.NAMESPACE_BUCKET { + return true + } + } + return false +} + // PutBucket - create a new bucket // // PARAMS: @@ -217,7 +240,11 @@ func (c *Client) DoesBucketExist(bucket string) (bool, error) { // - string: the location of the new bucket if create success // - error: nil if create success otherwise the specific error func (c *Client) PutBucket(bucket string) (string, error) { - return api.PutBucket(c, bucket) + return api.PutBucket(c, bucket, nil, c.BosContext) +} + +func (c *Client) PutBucketWithArgs(bucket string, args *api.PutBucketArgs) (string, error) { + return api.PutBucket(c, bucket, args, c.BosContext) } // DeleteBucket - delete a empty bucket @@ -227,7 +254,7 @@ func (c *Client) PutBucket(bucket string) (string, error) { // RETURNS: // - error: nil if delete success otherwise the specific error func (c *Client) DeleteBucket(bucket string) error { - return api.DeleteBucket(c, bucket) + return api.DeleteBucket(c, bucket, c.BosContext) } // GetBucketLocation - get the location fo the given bucket @@ -238,7 +265,7 @@ func (c *Client) DeleteBucket(bucket string) error { // - string: the location of the bucket // - error: nil if success otherwise the specific error func (c *Client) GetBucketLocation(bucket string) (string, error) { - return api.GetBucketLocation(c, bucket) + return api.GetBucketLocation(c, bucket, c.BosContext) } // PutBucketAcl - set the acl of the given bucket with acl body stream @@ -249,7 +276,7 @@ func (c *Client) GetBucketLocation(bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAcl(bucket string, aclBody *bce.Body) error { - return api.PutBucketAcl(c, bucket, "", aclBody) + return api.PutBucketAcl(c, bucket, "", aclBody, c.BosContext) } // PutBucketAclFromCanned - set the canned acl of the given bucket @@ -260,7 +287,7 @@ func (c *Client) PutBucketAcl(bucket string, aclBody *bce.Body) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAclFromCanned(bucket, cannedAcl string) error { - return api.PutBucketAcl(c, bucket, cannedAcl, nil) + return api.PutBucketAcl(c, bucket, cannedAcl, nil, c.BosContext) } // PutBucketAclFromFile - set the acl of the given bucket with acl json file name @@ -275,7 +302,7 @@ func (c *Client) PutBucketAclFromFile(bucket, aclFile string) error { if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAcl(c, bucket, "", body, c.BosContext) } // PutBucketAclFromString - set the acl of the given bucket with acl json string @@ -290,7 +317,7 @@ func (c *Client) PutBucketAclFromString(bucket, aclString string) error { if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAcl(c, bucket, "", body, c.BosContext) } // PutBucketAclFromStruct - set the acl of the given bucket with acl data structure @@ -309,7 +336,7 @@ func (c *Client) PutBucketAclFromStruct(bucket string, aclObj *api.PutBucketAclA if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAcl(c, bucket, "", body, c.BosContext) } // GetBucketAcl - get the acl of the given bucket @@ -320,7 +347,7 @@ func (c *Client) PutBucketAclFromStruct(bucket string, aclObj *api.PutBucketAclA // - *api.GetBucketAclResult: the result of the bucket acl // - error: nil if success otherwise the specific error func (c *Client) GetBucketAcl(bucket string) (*api.GetBucketAclResult, error) { - return api.GetBucketAcl(c, bucket) + return api.GetBucketAcl(c, bucket, c.BosContext) } // PutBucketLogging - set the loging setting of the given bucket with json stream @@ -331,7 +358,7 @@ func (c *Client) GetBucketAcl(bucket string) (*api.GetBucketAclResult, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketLogging(bucket string, body *bce.Body) error { - return api.PutBucketLogging(c, bucket, body) + return api.PutBucketLogging(c, bucket, body, c.BosContext) } // PutBucketLoggingFromString - set the loging setting of the given bucket with json string @@ -346,7 +373,7 @@ func (c *Client) PutBucketLoggingFromString(bucket, logging string) error { if err != nil { return err } - return api.PutBucketLogging(c, bucket, body) + return api.PutBucketLogging(c, bucket, body, c.BosContext) } // PutBucketLoggingFromStruct - set the loging setting of the given bucket with args object @@ -365,7 +392,7 @@ func (c *Client) PutBucketLoggingFromStruct(bucket string, obj *api.PutBucketLog if err != nil { return err } - return api.PutBucketLogging(c, bucket, body) + return api.PutBucketLogging(c, bucket, body, c.BosContext) } // GetBucketLogging - get the logging setting of the given bucket @@ -376,7 +403,7 @@ func (c *Client) PutBucketLoggingFromStruct(bucket string, obj *api.PutBucketLog // - *api.GetBucketLoggingResult: the logging setting of the bucket // - error: nil if success otherwise the specific error func (c *Client) GetBucketLogging(bucket string) (*api.GetBucketLoggingResult, error) { - return api.GetBucketLogging(c, bucket) + return api.GetBucketLogging(c, bucket, c.BosContext) } // DeleteBucketLogging - delete the logging setting of the given bucket @@ -386,7 +413,7 @@ func (c *Client) GetBucketLogging(bucket string) (*api.GetBucketLoggingResult, e // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketLogging(bucket string) error { - return api.DeleteBucketLogging(c, bucket) + return api.DeleteBucketLogging(c, bucket, c.BosContext) } // PutBucketLifecycle - set the lifecycle rule of the given bucket with raw stream @@ -397,7 +424,7 @@ func (c *Client) DeleteBucketLogging(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketLifecycle(bucket string, lifecycle *bce.Body) error { - return api.PutBucketLifecycle(c, bucket, lifecycle) + return api.PutBucketLifecycle(c, bucket, lifecycle, c.BosContext) } // PutBucketLifecycleFromString - set the lifecycle rule of the given bucket with string @@ -412,7 +439,7 @@ func (c *Client) PutBucketLifecycleFromString(bucket, lifecycle string) error { if err != nil { return err } - return api.PutBucketLifecycle(c, bucket, body) + return api.PutBucketLifecycle(c, bucket, body, c.BosContext) } // GetBucketLifecycle - get the lifecycle rule of the given bucket @@ -423,7 +450,7 @@ func (c *Client) PutBucketLifecycleFromString(bucket, lifecycle string) error { // - *api.GetBucketLifecycleResult: the lifecycle rule of the bucket // - error: nil if success otherwise the specific error func (c *Client) GetBucketLifecycle(bucket string) (*api.GetBucketLifecycleResult, error) { - return api.GetBucketLifecycle(c, bucket) + return api.GetBucketLifecycle(c, bucket, c.BosContext) } // DeleteBucketLifecycle - delete the lifecycle rule of the given bucket @@ -433,7 +460,7 @@ func (c *Client) GetBucketLifecycle(bucket string) (*api.GetBucketLifecycleResul // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketLifecycle(bucket string) error { - return api.DeleteBucketLifecycle(c, bucket) + return api.DeleteBucketLifecycle(c, bucket, c.BosContext) } // PutBucketStorageclass - set the storage class of the given bucket @@ -444,7 +471,7 @@ func (c *Client) DeleteBucketLifecycle(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketStorageclass(bucket, storageClass string) error { - return api.PutBucketStorageclass(c, bucket, storageClass) + return api.PutBucketStorageclass(c, bucket, storageClass, c.BosContext) } // GetBucketStorageclass - get the storage class of the given bucket @@ -455,7 +482,7 @@ func (c *Client) PutBucketStorageclass(bucket, storageClass string) error { // - string: the storage class string value // - error: nil if success otherwise the specific error func (c *Client) GetBucketStorageclass(bucket string) (string, error) { - return api.GetBucketStorageclass(c, bucket) + return api.GetBucketStorageclass(c, bucket, c.BosContext) } // PutBucketReplication - set the bucket replication config of different region @@ -467,7 +494,7 @@ func (c *Client) GetBucketStorageclass(bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketReplication(bucket string, replicationConf *bce.Body, replicationRuleId string) error { - return api.PutBucketReplication(c, bucket, replicationConf, replicationRuleId) + return api.PutBucketReplication(c, bucket, replicationConf, replicationRuleId, c.BosContext) } // PutBucketReplicationFromFile - set the bucket replication config with json file name @@ -483,7 +510,7 @@ func (c *Client) PutBucketReplicationFromFile(bucket, confFile string, replicati if err != nil { return err } - return api.PutBucketReplication(c, bucket, body, replicationRuleId) + return api.PutBucketReplication(c, bucket, body, replicationRuleId, c.BosContext) } // PutBucketReplicationFromString - set the bucket replication config with json string @@ -499,7 +526,7 @@ func (c *Client) PutBucketReplicationFromString(bucket, confString string, repli if err != nil { return err } - return api.PutBucketReplication(c, bucket, body, replicationRuleId) + return api.PutBucketReplication(c, bucket, body, replicationRuleId, c.BosContext) } // PutBucketReplicationFromStruct - set the bucket replication config with struct @@ -520,7 +547,7 @@ func (c *Client) PutBucketReplicationFromStruct(bucket string, if err != nil { return err } - return api.PutBucketReplication(c, bucket, body, replicationRuleId) + return api.PutBucketReplication(c, bucket, body, replicationRuleId, c.BosContext) } // GetBucketReplication - get the bucket replication config of the given bucket @@ -532,7 +559,7 @@ func (c *Client) PutBucketReplicationFromStruct(bucket string, // - *api.GetBucketReplicationResult: the result of the bucket replication config // - error: nil if success otherwise the specific error func (c *Client) GetBucketReplication(bucket string, replicationRuleId string) (*api.GetBucketReplicationResult, error) { - return api.GetBucketReplication(c, bucket, replicationRuleId) + return api.GetBucketReplication(c, bucket, replicationRuleId, c.BosContext) } // ListBucketReplication - get all replication config of the given bucket @@ -543,7 +570,7 @@ func (c *Client) GetBucketReplication(bucket string, replicationRuleId string) ( // - *api.ListBucketReplicationResult: the list of the bucket replication config // - error: nil if success otherwise the specific error func (c *Client) ListBucketReplication(bucket string) (*api.ListBucketReplicationResult, error) { - return api.ListBucketReplication(c, bucket) + return api.ListBucketReplication(c, bucket, c.BosContext) } // DeleteBucketReplication - delete the bucket replication config of the given bucket @@ -554,7 +581,7 @@ func (c *Client) ListBucketReplication(bucket string) (*api.ListBucketReplicatio // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketReplication(bucket string, replicationRuleId string) error { - return api.DeleteBucketReplication(c, bucket, replicationRuleId) + return api.DeleteBucketReplication(c, bucket, replicationRuleId, c.BosContext) } // GetBucketReplicationProgress - get the bucket replication process of the given bucket @@ -567,7 +594,7 @@ func (c *Client) DeleteBucketReplication(bucket string, replicationRuleId string // - error: nil if success otherwise the specific error func (c *Client) GetBucketReplicationProgress(bucket string, replicationRuleId string) ( *api.GetBucketReplicationProgressResult, error) { - return api.GetBucketReplicationProgress(c, bucket, replicationRuleId) + return api.GetBucketReplicationProgress(c, bucket, replicationRuleId, c.BosContext) } // PutBucketEncryption - set the bucket encryption config of the given bucket @@ -578,7 +605,7 @@ func (c *Client) GetBucketReplicationProgress(bucket string, replicationRuleId s // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketEncryption(bucket, algorithm string) error { - return api.PutBucketEncryption(c, bucket, algorithm) + return api.PutBucketEncryption(c, bucket, algorithm, c.BosContext) } // GetBucketEncryption - get the bucket encryption config @@ -589,7 +616,7 @@ func (c *Client) PutBucketEncryption(bucket, algorithm string) error { // - string: the encryption algorithm name // - error: nil if success otherwise the specific error func (c *Client) GetBucketEncryption(bucket string) (string, error) { - return api.GetBucketEncryption(c, bucket) + return api.GetBucketEncryption(c, bucket, c.BosContext) } // DeleteBucketEncryption - delete the bucket encryption config of the given bucket @@ -599,7 +626,7 @@ func (c *Client) GetBucketEncryption(bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketEncryption(bucket string) error { - return api.DeleteBucketEncryption(c, bucket) + return api.DeleteBucketEncryption(c, bucket, c.BosContext) } // PutBucketStaticWebsite - set the bucket static website config @@ -610,7 +637,7 @@ func (c *Client) DeleteBucketEncryption(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketStaticWebsite(bucket string, config *bce.Body) error { - return api.PutBucketStaticWebsite(c, bucket, config) + return api.PutBucketStaticWebsite(c, bucket, config, c.BosContext) } // PutBucketStaticWebsiteFromString - set the bucket static website config from json string @@ -625,7 +652,7 @@ func (c *Client) PutBucketStaticWebsiteFromString(bucket, jsonConfig string) err if err != nil { return err } - return api.PutBucketStaticWebsite(c, bucket, body) + return api.PutBucketStaticWebsite(c, bucket, body, c.BosContext) } // PutBucketStaticWebsiteFromStruct - set the bucket static website config from struct @@ -645,7 +672,7 @@ func (c *Client) PutBucketStaticWebsiteFromStruct(bucket string, if err != nil { return err } - return api.PutBucketStaticWebsite(c, bucket, body) + return api.PutBucketStaticWebsite(c, bucket, body, c.BosContext) } // SimplePutBucketStaticWebsite - simple set the bucket static website config @@ -670,7 +697,7 @@ func (c *Client) SimplePutBucketStaticWebsite(bucket, index, notFound string) er // - error: nil if success otherwise the specific error func (c *Client) GetBucketStaticWebsite(bucket string) ( *api.GetBucketStaticWebsiteResult, error) { - return api.GetBucketStaticWebsite(c, bucket) + return api.GetBucketStaticWebsite(c, bucket, c.BosContext) } // DeleteBucketStaticWebsite - delete the bucket static website config of the given bucket @@ -680,7 +707,7 @@ func (c *Client) GetBucketStaticWebsite(bucket string) ( // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketStaticWebsite(bucket string) error { - return api.DeleteBucketStaticWebsite(c, bucket) + return api.DeleteBucketStaticWebsite(c, bucket, c.BosContext) } // PutBucketCors - set the bucket CORS config @@ -691,7 +718,7 @@ func (c *Client) DeleteBucketStaticWebsite(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketCors(bucket string, config *bce.Body) error { - return api.PutBucketCors(c, bucket, config) + return api.PutBucketCors(c, bucket, config, c.BosContext) } // PutBucketCorsFromFile - set the bucket CORS config from json config file @@ -706,7 +733,7 @@ func (c *Client) PutBucketCorsFromFile(bucket, filename string) error { if err != nil { return err } - return api.PutBucketCors(c, bucket, body) + return api.PutBucketCors(c, bucket, body, c.BosContext) } // PutBucketCorsFromString - set the bucket CORS config from json config string @@ -721,7 +748,7 @@ func (c *Client) PutBucketCorsFromString(bucket, jsonConfig string) error { if err != nil { return err } - return api.PutBucketCors(c, bucket, body) + return api.PutBucketCors(c, bucket, body, c.BosContext) } // PutBucketCorsFromStruct - set the bucket CORS config from json config object @@ -740,7 +767,7 @@ func (c *Client) PutBucketCorsFromStruct(bucket string, confObj *api.PutBucketCo if err != nil { return err } - return api.PutBucketCors(c, bucket, body) + return api.PutBucketCors(c, bucket, body, c.BosContext) } // GetBucketCors - get the bucket CORS config @@ -751,7 +778,7 @@ func (c *Client) PutBucketCorsFromStruct(bucket string, confObj *api.PutBucketCo // - result: the bucket CORS config result object // - error: nil if success otherwise the specific error func (c *Client) GetBucketCors(bucket string) (*api.GetBucketCorsResult, error) { - return api.GetBucketCors(c, bucket) + return api.GetBucketCors(c, bucket, c.BosContext) } // DeleteBucketCors - delete the bucket CORS config of the given bucket @@ -761,7 +788,7 @@ func (c *Client) GetBucketCors(bucket string) (*api.GetBucketCorsResult, error) // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketCors(bucket string) error { - return api.DeleteBucketCors(c, bucket) + return api.DeleteBucketCors(c, bucket, c.BosContext) } // PutBucketCopyrightProtection - set the copyright protection config of the given bucket @@ -773,7 +800,7 @@ func (c *Client) DeleteBucketCors(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketCopyrightProtection(bucket string, resources ...string) error { - return api.PutBucketCopyrightProtection(c, bucket, resources...) + return api.PutBucketCopyrightProtection(c, c.BosContext, bucket, resources...) } // GetBucketCopyrightProtection - get the bucket copyright protection config @@ -784,7 +811,7 @@ func (c *Client) PutBucketCopyrightProtection(bucket string, resources ...string // - result: the bucket copyright protection config resources // - error: nil if success otherwise the specific error func (c *Client) GetBucketCopyrightProtection(bucket string) ([]string, error) { - return api.GetBucketCopyrightProtection(c, bucket) + return api.GetBucketCopyrightProtection(c, bucket, c.BosContext) } // DeleteBucketCopyrightProtection - delete the bucket copyright protection config @@ -794,7 +821,7 @@ func (c *Client) GetBucketCopyrightProtection(bucket string) ([]string, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketCopyrightProtection(bucket string) error { - return api.DeleteBucketCopyrightProtection(c, bucket) + return api.DeleteBucketCopyrightProtection(c, bucket, c.BosContext) } // PutObject - upload a new object or rewrite the existed object with raw stream @@ -809,7 +836,8 @@ func (c *Client) DeleteBucketCopyrightProtection(bucket string) error { // - error: the uploaded error if any occurs func (c *Client) PutObject(bucket, object string, body *bce.Body, args *api.PutObjectArgs) (string, error) { - return api.PutObject(c, bucket, object, body, args) + etag, _, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, err } // BasicPutObject - the basic interface of uploading an object @@ -822,7 +850,8 @@ func (c *Client) PutObject(bucket, object string, body *bce.Body, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) BasicPutObject(bucket, object string, body *bce.Body) (string, error) { - return api.PutObject(c, bucket, object, body, nil) + etag , _, err := api.PutObject(c, bucket, object, body, nil, c.BosContext) + return etag, err } // PutObjectFromBytes - upload a new object or rewrite the existed object from a byte array @@ -841,7 +870,9 @@ func (c *Client) PutObjectFromBytes(bucket, object string, bytesArr []byte, if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + etag, _, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, err + } // PutObjectFromString - upload a new object or rewrite the existed object from a string @@ -860,7 +891,9 @@ func (c *Client) PutObjectFromString(bucket, object, content string, if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + etag , _, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, err + } // PutObjectFromFile - upload a new object or rewrite the existed object from a local file @@ -879,7 +912,8 @@ func (c *Client) PutObjectFromFile(bucket, object, fileName string, if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + etag , _, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, err } // PutObjectFromStream - upload a new object or rewrite the existed object from stream @@ -898,7 +932,24 @@ func (c *Client) PutObjectFromStream(bucket, object string, reader io.Reader, if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + etag , _, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, err +} + +func (c *Client) PutObjectFromFileWithCallback(bucket, object, fileName string, + args *api.PutObjectArgs) (string, *api.PutObjectResult, error) { + body, err := bce.NewBodyFromFile(fileName) + if err != nil { + return "", nil, err + } + etag, putObjectResult, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, putObjectResult, err +} + +func (c *Client) PutObjectWithCallback(bucket, object string, body *bce.Body, + args *api.PutObjectArgs) (string, *api.PutObjectResult, error) { + etag, putObjectResult, err := api.PutObject(c, bucket, object, body, args, c.BosContext) + return etag, putObjectResult, err } // CopyObject - copy a remote object to another one @@ -916,7 +967,7 @@ func (c *Client) PutObjectFromStream(bucket, object string, reader io.Reader, func (c *Client) CopyObject(bucket, object, srcBucket, srcObject string, args *api.CopyObjectArgs) (*api.CopyObjectResult, error) { source := fmt.Sprintf("/%s/%s", srcBucket, srcObject) - return api.CopyObject(c, bucket, object, source, args) + return api.CopyObject(c, bucket, object, source, args, c.BosContext) } // BasicCopyObject - the basic interface of copying a object to another one @@ -932,7 +983,7 @@ func (c *Client) CopyObject(bucket, object, srcBucket, srcObject string, func (c *Client) BasicCopyObject(bucket, object, srcBucket, srcObject string) (*api.CopyObjectResult, error) { source := fmt.Sprintf("/%s/%s", srcBucket, srcObject) - return api.CopyObject(c, bucket, object, source, nil) + return api.CopyObject(c, bucket, object, source, nil, c.BosContext) } // GetObject - get the given object with raw stream return @@ -940,15 +991,15 @@ func (c *Client) BasicCopyObject(bucket, object, srcBucket, // PARAMS: // - bucket: the name of the bucket // - object: the name of the object -// - responseHeaders: the optional response headers to get the given object +// - args: the optional args in querysring // - ranges: the optional range start and end to get the given object // RETURNS: // - *api.GetObjectResult: result struct which contains "Body" and header fields // for details reference https://cloud.baidu.com/doc/BOS/API.html#GetObject.E6.8E.A5.E5.8F.A3 // - error: any error if it occurs -func (c *Client) GetObject(bucket, object string, responseHeaders map[string]string, +func (c *Client) GetObject(bucket, object string, args map[string]string, ranges ...int64) (*api.GetObjectResult, error) { - return api.GetObject(c, bucket, object, responseHeaders, ranges...) + return api.GetObject(c, bucket, object, c.BosContext, args, ranges...) } // BasicGetObject - the basic interface of geting the given object @@ -961,7 +1012,7 @@ func (c *Client) GetObject(bucket, object string, responseHeaders map[string]str // for details reference https://cloud.baidu.com/doc/BOS/API.html#GetObject.E6.8E.A5.E5.8F.A3 // - error: any error if it occurs func (c *Client) BasicGetObject(bucket, object string) (*api.GetObjectResult, error) { - return api.GetObject(c, bucket, object, nil) + return api.GetObject(c, bucket, object, c.BosContext, nil) } // BasicGetObjectToFile - use basic interface to get the given object to the given file path @@ -973,7 +1024,7 @@ func (c *Client) BasicGetObject(bucket, object string) (*api.GetObjectResult, er // RETURNS: // - error: any error if it occurs func (c *Client) BasicGetObjectToFile(bucket, object, filePath string) error { - res, err := api.GetObject(c, bucket, object, nil) + res, err := api.GetObject(c, bucket, object, c.BosContext, nil) if err != nil { return err } @@ -1005,7 +1056,7 @@ func (c *Client) BasicGetObjectToFile(bucket, object, filePath string) error { // https://cloud.baidu.com/doc/BOS/API.html#GetObjectMeta.E6.8E.A5.E5.8F.A3 // - error: any error if it occurs func (c *Client) GetObjectMeta(bucket, object string) (*api.GetObjectMetaResult, error) { - return api.GetObjectMeta(c, bucket, object) + return api.GetObjectMeta(c, bucket, object, c.BosContext) } // SelectObject - select the object content @@ -1018,7 +1069,7 @@ func (c *Client) GetObjectMeta(bucket, object string) (*api.GetObjectMetaResult, // - *api.SelectObjectResult: select object result // - error: any error if it occurs func (c *Client) SelectObject(bucket, object string, args *api.SelectObjectArgs) (*api.SelectObjectResult, error) { - return api.SelectObject(c, bucket, object, args) + return api.SelectObject(c, bucket, object, args, c.BosContext) } // FetchObject - fetch the object content from the given source and store @@ -1033,7 +1084,7 @@ func (c *Client) SelectObject(bucket, object string, args *api.SelectObjectArgs) // - error: any error if it occurs func (c *Client) FetchObject(bucket, object, source string, args *api.FetchObjectArgs) (*api.FetchObjectResult, error) { - return api.FetchObject(c, bucket, object, source, args) + return api.FetchObject(c, bucket, object, source, args, c.BosContext) } // BasicFetchObject - the basic interface of the fetch object api @@ -1046,7 +1097,7 @@ func (c *Client) FetchObject(bucket, object, source string, // - *api.FetchObjectResult: result struct with Code, Message, RequestId and JobId fields // - error: any error if it occurs func (c *Client) BasicFetchObject(bucket, object, source string) (*api.FetchObjectResult, error) { - return api.FetchObject(c, bucket, object, source, nil) + return api.FetchObject(c, bucket, object, source, nil, c.BosContext) } // SimpleFetchObject - fetch object with simple arguments interface @@ -1063,7 +1114,7 @@ func (c *Client) BasicFetchObject(bucket, object, source string) (*api.FetchObje func (c *Client) SimpleFetchObject(bucket, object, source, mode, storageClass string) (*api.FetchObjectResult, error) { args := &api.FetchObjectArgs{mode, storageClass} - return api.FetchObject(c, bucket, object, source, args) + return api.FetchObject(c, bucket, object, source, args, c.BosContext) } // AppendObject - append the given content to a new or existed object which is appendable @@ -1078,7 +1129,7 @@ func (c *Client) SimpleFetchObject(bucket, object, source, mode, // - error: any error if it occurs func (c *Client) AppendObject(bucket, object string, content *bce.Body, args *api.AppendObjectArgs) (*api.AppendObjectResult, error) { - return api.AppendObject(c, bucket, object, content, args) + return api.AppendObject(c, bucket, object, content, args, c.BosContext) } // SimpleAppendObject - the interface to append object with simple offset argument @@ -1093,7 +1144,7 @@ func (c *Client) AppendObject(bucket, object string, content *bce.Body, // - error: any error if it occurs func (c *Client) SimpleAppendObject(bucket, object string, content *bce.Body, offset int64) (*api.AppendObjectResult, error) { - return api.AppendObject(c, bucket, object, content, &api.AppendObjectArgs{Offset: offset}) + return api.AppendObject(c, bucket, object, content, &api.AppendObjectArgs{Offset: offset}, c.BosContext) } // SimpleAppendObjectFromString - the simple interface of appending an object from a string @@ -1112,7 +1163,7 @@ func (c *Client) SimpleAppendObjectFromString(bucket, object, content string, if err != nil { return nil, err } - return api.AppendObject(c, bucket, object, body, &api.AppendObjectArgs{Offset: offset}) + return api.AppendObject(c, bucket, object, body, &api.AppendObjectArgs{Offset: offset}, c.BosContext) } // SimpleAppendObjectFromFile - the simple interface of appending an object from a file @@ -1131,7 +1182,7 @@ func (c *Client) SimpleAppendObjectFromFile(bucket, object, filePath string, if err != nil { return nil, err } - return api.AppendObject(c, bucket, object, body, &api.AppendObjectArgs{Offset: offset}) + return api.AppendObject(c, bucket, object, body, &api.AppendObjectArgs{Offset: offset}, c.BosContext) } // DeleteObject - delete the given object @@ -1142,7 +1193,7 @@ func (c *Client) SimpleAppendObjectFromFile(bucket, object, filePath string, // RETURNS: // - error: any error if it occurs func (c *Client) DeleteObject(bucket, object string) error { - return api.DeleteObject(c, bucket, object) + return api.DeleteObject(c, bucket, object, c.BosContext) } // DeleteMultipleObjects - delete a list of objects @@ -1155,7 +1206,7 @@ func (c *Client) DeleteObject(bucket, object string) error { // - error: any error if it occurs func (c *Client) DeleteMultipleObjects(bucket string, objectListStream *bce.Body) (*api.DeleteMultipleObjectsResult, error) { - return api.DeleteMultipleObjects(c, bucket, objectListStream) + return api.DeleteMultipleObjects(c, bucket, objectListStream, c.BosContext) } // DeleteMultipleObjectsFromString - delete a list of objects with json format string @@ -1172,7 +1223,7 @@ func (c *Client) DeleteMultipleObjectsFromString(bucket, if err != nil { return nil, err } - return api.DeleteMultipleObjects(c, bucket, body) + return api.DeleteMultipleObjects(c, bucket, body, c.BosContext) } // DeleteMultipleObjectsFromStruct - delete a list of objects with object list struct @@ -1193,7 +1244,7 @@ func (c *Client) DeleteMultipleObjectsFromStruct(bucket string, if err != nil { return nil, err } - return api.DeleteMultipleObjects(c, bucket, body) + return api.DeleteMultipleObjects(c, bucket, body, c.BosContext) } // DeleteMultipleObjectsFromKeyList - delete a list of objects with given key string array @@ -1223,7 +1274,7 @@ func (c *Client) DeleteMultipleObjectsFromKeyList(bucket string, if err != nil { return nil, err } - return api.DeleteMultipleObjects(c, bucket, body) + return api.DeleteMultipleObjects(c, bucket, body, c.BosContext) } // InitiateMultipartUpload - initiate a multipart upload to get a upload ID @@ -1239,7 +1290,7 @@ func (c *Client) DeleteMultipleObjectsFromKeyList(bucket string, // - error: nil if ok otherwise the specific error func (c *Client) InitiateMultipartUpload(bucket, object, contentType string, args *api.InitiateMultipartUploadArgs) (*api.InitiateMultipartUploadResult, error) { - return api.InitiateMultipartUpload(c, bucket, object, contentType, args) + return api.InitiateMultipartUpload(c, bucket, object, contentType, args, c.BosContext) } // BasicInitiateMultipartUpload - basic interface to initiate a multipart upload @@ -1252,7 +1303,7 @@ func (c *Client) InitiateMultipartUpload(bucket, object, contentType string, // - error: nil if ok otherwise the specific error func (c *Client) BasicInitiateMultipartUpload(bucket, object string) (*api.InitiateMultipartUploadResult, error) { - return api.InitiateMultipartUpload(c, bucket, object, "", nil) + return api.InitiateMultipartUpload(c, bucket, object, "", nil, c.BosContext) } // UploadPart - upload the single part in the multipart upload process @@ -1269,7 +1320,7 @@ func (c *Client) BasicInitiateMultipartUpload(bucket, // - error: nil if ok otherwise the specific error func (c *Client) UploadPart(bucket, object, uploadId string, partNumber int, content *bce.Body, args *api.UploadPartArgs) (string, error) { - return api.UploadPart(c, bucket, object, uploadId, partNumber, content, args) + return api.UploadPart(c, bucket, object, uploadId, partNumber, content, args, c.BosContext) } // BasicUploadPart - basic interface to upload the single part in the multipart upload process @@ -1285,7 +1336,7 @@ func (c *Client) UploadPart(bucket, object, uploadId string, partNumber int, // - error: nil if ok otherwise the specific error func (c *Client) BasicUploadPart(bucket, object, uploadId string, partNumber int, content *bce.Body) (string, error) { - return api.UploadPart(c, bucket, object, uploadId, partNumber, content, nil) + return api.UploadPart(c, bucket, object, uploadId, partNumber, content, nil, c.BosContext) } // UploadPartFromBytes - upload the single part in the multipart upload process @@ -1302,7 +1353,7 @@ func (c *Client) BasicUploadPart(bucket, object, uploadId string, partNumber int // - error: nil if ok otherwise the specific error func (c *Client) UploadPartFromBytes(bucket, object, uploadId string, partNumber int, content []byte, args *api.UploadPartArgs) (string, error) { - return api.UploadPartFromBytes(c, bucket, object, uploadId, partNumber, content, args) + return api.UploadPartFromBytes(c, bucket, object, uploadId, partNumber, content, args, c.BosContext) } // UploadPartCopy - copy the multipart object @@ -1321,7 +1372,7 @@ func (c *Client) UploadPartFromBytes(bucket, object, uploadId string, partNumber func (c *Client) UploadPartCopy(bucket, object, srcBucket, srcObject, uploadId string, partNumber int, args *api.UploadPartCopyArgs) (*api.CopyObjectResult, error) { source := fmt.Sprintf("/%s/%s", srcBucket, srcObject) - return api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, args) + return api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, args, c.BosContext) } // BasicUploadPartCopy - basic interface to copy the multipart object @@ -1339,7 +1390,7 @@ func (c *Client) UploadPartCopy(bucket, object, srcBucket, srcObject, uploadId s func (c *Client) BasicUploadPartCopy(bucket, object, srcBucket, srcObject, uploadId string, partNumber int) (*api.CopyObjectResult, error) { source := fmt.Sprintf("/%s/%s", srcBucket, srcObject) - return api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, nil) + return api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, nil, c.BosContext) } // CompleteMultipartUpload - finish a multipart upload operation with parts stream @@ -1355,7 +1406,7 @@ func (c *Client) BasicUploadPartCopy(bucket, object, srcBucket, srcObject, uploa // - error: nil if ok otherwise the specific error func (c *Client) CompleteMultipartUpload(bucket, object, uploadId string, body *bce.Body, args *api.CompleteMultipartUploadArgs) (*api.CompleteMultipartUploadResult, error) { - return api.CompleteMultipartUpload(c, bucket, object, uploadId, body, args) + return api.CompleteMultipartUpload(c, bucket, object, uploadId, body, args, c.BosContext) } // CompleteMultipartUploadFromStruct - finish a multipart upload operation with parts struct @@ -1378,7 +1429,7 @@ func (c *Client) CompleteMultipartUploadFromStruct(bucket, object, uploadId stri if err != nil { return nil, err } - return api.CompleteMultipartUpload(c, bucket, object, uploadId, body, args) + return api.CompleteMultipartUpload(c, bucket, object, uploadId, body, args, c.BosContext) } // AbortMultipartUpload - abort a multipart upload operation @@ -1390,7 +1441,7 @@ func (c *Client) CompleteMultipartUploadFromStruct(bucket, object, uploadId stri // RETURNS: // - error: nil if ok otherwise the specific error func (c *Client) AbortMultipartUpload(bucket, object, uploadId string) error { - return api.AbortMultipartUpload(c, bucket, object, uploadId) + return api.AbortMultipartUpload(c, bucket, object, uploadId, c.BosContext) } // ListParts - list the successfully uploaded parts info by upload id @@ -1405,7 +1456,7 @@ func (c *Client) AbortMultipartUpload(bucket, object, uploadId string) error { // - error: nil if ok otherwise the specific error func (c *Client) ListParts(bucket, object, uploadId string, args *api.ListPartsArgs) (*api.ListPartsResult, error) { - return api.ListParts(c, bucket, object, uploadId, args) + return api.ListParts(c, bucket, object, uploadId, args, c.BosContext) } // BasicListParts - basic interface to list the successfully uploaded parts info by upload id @@ -1418,7 +1469,7 @@ func (c *Client) ListParts(bucket, object, uploadId string, // - *ListPartsResult: the uploaded parts info result // - error: nil if ok otherwise the specific error func (c *Client) BasicListParts(bucket, object, uploadId string) (*api.ListPartsResult, error) { - return api.ListParts(c, bucket, object, uploadId, nil) + return api.ListParts(c, bucket, object, uploadId, nil, c.BosContext) } // ListMultipartUploads - list the unfinished uploaded parts of the given bucket @@ -1431,7 +1482,7 @@ func (c *Client) BasicListParts(bucket, object, uploadId string) (*api.ListParts // - error: nil if ok otherwise the specific error func (c *Client) ListMultipartUploads(bucket string, args *api.ListMultipartUploadsArgs) (*api.ListMultipartUploadsResult, error) { - return api.ListMultipartUploads(c, bucket, args) + return api.ListMultipartUploads(c, bucket, args, c.BosContext) } // BasicListMultipartUploads - basic interface to list the unfinished uploaded parts @@ -1443,7 +1494,7 @@ func (c *Client) ListMultipartUploads(bucket string, // - error: nil if ok otherwise the specific error func (c *Client) BasicListMultipartUploads(bucket string) ( *api.ListMultipartUploadsResult, error) { - return api.ListMultipartUploads(c, bucket, nil) + return api.ListMultipartUploads(c, bucket, nil, c.BosContext) } // UploadSuperFile - parallel upload the super file by using the multipart upload interface @@ -1691,7 +1742,7 @@ func (c *Client) BasicGeneratePresignedUrl(bucket, object string, expireInSecond // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutObjectAcl(bucket, object string, aclBody *bce.Body) error { - return api.PutObjectAcl(c, bucket, object, "", nil, nil, aclBody) + return api.PutObjectAcl(c, bucket, object, "", nil, nil, aclBody, c.BosContext) } // PutObjectAclFromCanned - set the canned acl of the given object @@ -1703,7 +1754,7 @@ func (c *Client) PutObjectAcl(bucket, object string, aclBody *bce.Body) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutObjectAclFromCanned(bucket, object, cannedAcl string) error { - return api.PutObjectAcl(c, bucket, object, cannedAcl, nil, nil, nil) + return api.PutObjectAcl(c, bucket, object, cannedAcl, nil, nil, nil, c.BosContext) } // PutObjectAclGrantRead - set the canned grant read acl of the given object @@ -1715,7 +1766,7 @@ func (c *Client) PutObjectAclFromCanned(bucket, object, cannedAcl string) error // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutObjectAclGrantRead(bucket, object string, ids ...string) error { - return api.PutObjectAcl(c, bucket, object, "", ids, nil, nil) + return api.PutObjectAcl(c, bucket, object, "", ids, nil, nil, c.BosContext) } // PutObjectAclGrantFullControl - set the canned grant full-control acl of the given object @@ -1727,7 +1778,7 @@ func (c *Client) PutObjectAclGrantRead(bucket, object string, ids ...string) err // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutObjectAclGrantFullControl(bucket, object string, ids ...string) error { - return api.PutObjectAcl(c, bucket, object, "", nil, ids, nil) + return api.PutObjectAcl(c, bucket, object, "", nil, ids, nil, c.BosContext) } // PutObjectAclFromFile - set the acl of the given object with acl json file name @@ -1743,7 +1794,7 @@ func (c *Client) PutObjectAclFromFile(bucket, object, aclFile string) error { if err != nil { return err } - return api.PutObjectAcl(c, bucket, object, "", nil, nil, body) + return api.PutObjectAcl(c, bucket, object, "", nil, nil, body, c.BosContext) } // PutObjectAclFromString - set the acl of the given object with acl json string @@ -1759,7 +1810,7 @@ func (c *Client) PutObjectAclFromString(bucket, object, aclString string) error if err != nil { return err } - return api.PutObjectAcl(c, bucket, object, "", nil, nil, body) + return api.PutObjectAcl(c, bucket, object, "", nil, nil, body, c.BosContext) } // PutObjectAclFromStruct - set the acl of the given object with acl data structure @@ -1778,7 +1829,7 @@ func (c *Client) PutObjectAclFromStruct(bucket, object string, aclObj *api.PutOb if err != nil { return err } - return api.PutObjectAcl(c, bucket, object, "", nil, nil, body) + return api.PutObjectAcl(c, bucket, object, "", nil, nil, body, c.BosContext) } // GetObjectAcl - get the acl of the given object @@ -1790,7 +1841,7 @@ func (c *Client) PutObjectAclFromStruct(bucket, object string, aclObj *api.PutOb // - *api.GetObjectAclResult: the result of the object acl // - error: nil if success otherwise the specific error func (c *Client) GetObjectAcl(bucket, object string) (*api.GetObjectAclResult, error) { - return api.GetObjectAcl(c, bucket, object) + return api.GetObjectAcl(c, bucket, object, c.BosContext) } // DeleteObjectAcl - delete the acl of the given object @@ -1801,7 +1852,7 @@ func (c *Client) GetObjectAcl(bucket, object string) (*api.GetObjectAclResult, e // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteObjectAcl(bucket, object string) error { - return api.DeleteObjectAcl(c, bucket, object) + return api.DeleteObjectAcl(c, bucket, object, c.BosContext) } // RestoreObject - restore the archive object @@ -1826,7 +1877,7 @@ func (c *Client) RestoreObject(bucket string, object string, restoreDays int, re RestoreTier: restoreTier, RestoreDays: restoreDays, } - return api.RestoreObject(c, bucket, object, args) + return api.RestoreObject(c, bucket, object, args, c.BosContext) } // PutBucketTrash - put the bucket trash @@ -1837,7 +1888,7 @@ func (c *Client) RestoreObject(bucket string, object string, restoreDays int, re // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketTrash(bucket string, trashReq api.PutBucketTrashReq) error { - return api.PutBucketTrash(c, bucket, trashReq) + return api.PutBucketTrash(c, bucket, trashReq, c.BosContext) } // GetBucketTrash - get the bucket trash @@ -1848,7 +1899,7 @@ func (c *Client) PutBucketTrash(bucket string, trashReq api.PutBucketTrashReq) e // - *api.GetBucketTrashResult,: the result of the bucket trash // - error: nil if success otherwise the specific error func (c *Client) GetBucketTrash(bucket string) (*api.GetBucketTrashResult, error) { - return api.GetBucketTrash(c, bucket) + return api.GetBucketTrash(c, bucket, c.BosContext) } // DeleteBucketTrash - delete the trash of the given bucket @@ -1858,7 +1909,7 @@ func (c *Client) GetBucketTrash(bucket string) (*api.GetBucketTrashResult, error // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketTrash(bucket string) error { - return api.DeleteBucketTrash(c, bucket) + return api.DeleteBucketTrash(c, bucket, c.BosContext) } // PutBucketNotification - put the bucket notification @@ -1869,7 +1920,7 @@ func (c *Client) DeleteBucketTrash(bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketNotification(bucket string, putBucketNotificationReq api.PutBucketNotificationReq) error { - return api.PutBucketNotification(c, bucket, putBucketNotificationReq) + return api.PutBucketNotification(c, bucket, putBucketNotificationReq, c.BosContext) } // GetBucketNotification - get the bucket notification @@ -1880,7 +1931,7 @@ func (c *Client) PutBucketNotification(bucket string, putBucketNotificationReq a // - *api.PutBucketNotificationReq,: the result of the bucket notification // - error: nil if success otherwise the specific error func (c *Client) GetBucketNotification(bucket string) (*api.PutBucketNotificationReq, error) { - return api.GetBucketNotification(c, bucket) + return api.GetBucketNotification(c, bucket, c.BosContext) } // DeleteBucketNotification - delete the notification of the given bucket @@ -1890,7 +1941,7 @@ func (c *Client) GetBucketNotification(bucket string) (*api.PutBucketNotificatio // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) DeleteBucketNotification(bucket string) error { - return api.DeleteBucketNotification(c, bucket) + return api.DeleteBucketNotification(c, bucket, c.BosContext) } // ParallelUpload - auto multipart upload object @@ -1906,7 +1957,7 @@ func (c *Client) DeleteBucketNotification(bucket string) error { // - error: nil if success otherwise the specific error func (c *Client) ParallelUpload(bucket string, object string, filename string, contentType string, args *api.InitiateMultipartUploadArgs) (*api.CompleteMultipartUploadResult, error) { - initiateMultipartUploadResult, err := api.InitiateMultipartUpload(c, bucket, object, contentType, args) + initiateMultipartUploadResult, err := api.InitiateMultipartUpload(c, bucket, object, contentType, args, c.BosContext) if err != nil { return nil, err } @@ -2028,7 +2079,7 @@ func (c *Client) singlePartUpload( var args api.UploadPartArgs args.ContentMD5 = content.ContentMD5() - etag, err := api.UploadPart(c, bucket, object, uploadId, partNumber, content, &args) + etag, err := api.UploadPart(c, bucket, object, uploadId, partNumber, content, &args, c.BosContext) if err != nil { errChan <- err log.Error("upload part fail,err:%v", err) @@ -2073,7 +2124,7 @@ func (c *Client) ParallelCopy(srcBucketName string, srcObjectName string, initArgs.StorageClass = args.StorageClass } } - initiateMultipartUploadResult, err := api.InitiateMultipartUpload(c, destBucketName, destObjectName, objectMeta.ContentType, &initArgs) + initiateMultipartUploadResult, err := api.InitiateMultipartUpload(c, destBucketName, destObjectName, objectMeta.ContentType, &initArgs, c.BosContext) if err != nil { return nil, err @@ -2110,7 +2161,10 @@ func (c *Client) parallelPartCopy(srcMeta api.GetObjectMetaResult, source string var err error size := srcMeta.ContentLength partSize := int64(DEFAULT_MULTIPART_SIZE) - + if partSize*MAX_PART_NUMBER < size { + lowerLimit := int64(math.Ceil(float64(size) / MAX_PART_NUMBER)) + partSize = int64(math.Ceil(float64(lowerLimit)/float64(partSize))) * partSize + } partNum := (size + partSize - 1) / partSize parallelChan := make(chan int, c.MaxParallel) @@ -2184,7 +2238,7 @@ func (c *Client) singlePartCopy(source string, bucket string, object string, upl <-parallelChan }() - copyObjectResult, err := api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, args) + copyObjectResult, err := api.UploadPartCopy(c, bucket, object, source, uploadId, partNumber, args, c.BosContext) if err != nil { errChan <- err log.Error("upload part fail,err:%v", err) @@ -2204,7 +2258,7 @@ func (c *Client) singlePartCopy(source string, bucket string, object string, upl // RETURNS: // - error: the put error if any occurs func (c *Client) PutSymlink(bucket string, object string, symlinkKey string, symlinkArgs *api.PutSymlinkArgs) error { - return api.PutObjectSymlink(c, bucket, object, symlinkKey, symlinkArgs) + return api.PutObjectSymlink(c, bucket, object, symlinkKey, symlinkArgs, c.BosContext) } // PutSymlink - create symlink for exist target object @@ -2216,5 +2270,41 @@ func (c *Client) PutSymlink(bucket string, object string, symlinkKey string, sym // - string: the target of the symlink // - error: the put error if any occurs func (c *Client) GetSymlink(bucket string, object string) (string, error) { - return api.GetObjectSymlink(c, bucket, object) + return api.GetObjectSymlink(c, bucket, object, c.BosContext) +} + +func (c *Client) PutBucketMirror(bucket string, putBucketMirrorArgs *api.PutBucketMirrorArgs) error { + return api.PutBucketMirror(c, bucket, putBucketMirrorArgs, c.BosContext) +} + +func (c *Client) GetBucketMirror(bucket string) (*api.PutBucketMirrorArgs, error) { + return api.GetBucketMirror(c, bucket, c.BosContext) +} + +func (c *Client) DeleteBucketMirror(bucket string) error { + return api.DeleteBucketMirror(c, bucket, c.BosContext) +} + +func (c *Client) PutBucketTag(bucket string, putBucketTagArgs *api.PutBucketTagArgs) error { + return api.PutBucketTag(c, bucket, putBucketTagArgs, c.BosContext) +} + +func (c *Client) GetBucketTag(bucket string) (*api.GetBucketTagResult, error) { + return api.GetBucketTag(c, bucket, c.BosContext) +} + +func (c *Client) DeleteBucketTag(bucket string) error { + return api.DeleteBucketTag(c, bucket, c.BosContext) +} + +func (c *Client) PutObjectTag(bucket string, object string, putObjectTagArgs *api.PutObjectTagArgs) error { + return api.PutObjectTag(c, bucket, object, putObjectTagArgs, c.BosContext) +} + +func (c *Client) GetObjectTag(bucket string, object string) (map[string]interface{}, error) { + return api.GetObjectTag(c, bucket, object, c.BosContext) +} + +func (c *Client) DeleteObjectTag(bucket string, object string) error { + return api.DeleteObjectTag(c, bucket, object, c.BosContext) } diff --git a/vendor/modules.txt b/vendor/modules.txt index bcbe049abf823..79399e154d408 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -467,7 +467,7 @@ github.com/aws/smithy-go/transport/http/internal/io # github.com/axiomhq/hyperloglog v0.0.0-20240507144631-af9851f82b27 ## explicit; go 1.12 github.com/axiomhq/hyperloglog -# github.com/baidubce/bce-sdk-go v0.9.141 +# github.com/baidubce/bce-sdk-go v0.9.186 ## explicit; go 1.11 github.com/baidubce/bce-sdk-go/auth github.com/baidubce/bce-sdk-go/bce