Skip to content

Commit

Permalink
update 3.21.8
Browse files Browse the repository at this point in the history
  • Loading branch information
redabc committed Sep 3, 2021
1 parent fec1251 commit 782df33
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 3 deletions.
18 changes: 18 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Version 3.21.8

New Features:
1. Added bucket encryption-related APIs, including SetBucketEncryption, GetBucketEncryption, and DeleteBucketEncryption.
2. Added the AppendObject API.
3. Added the ModifyObject API.
4. Allowed you to specify a type in the ListBuckets API to list the buckets of this type.

Documentation & Demo:
1. Added descriptions about bucket encryption APIs.
2. Added descriptions about the AppendObject API.
3. Added descriptions about the ModifyObject API.
4. Added descriptions about the new parameter for specifying a bucket type in the ListBuckets API.

Resolved Issues:

-----------------------------------------------------------------------------------

Version 3.21.1

New Features:
Expand Down
18 changes: 18 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Version 3.21.8

新特性:
1. 新增桶加密相关接口:设置桶加密配置(SetBucketEncryption), 获取桶加密配置(GetBucketEncryption), 删除桶加密配置(DeleteBucketEncryption);
2. 新增追加上传接口(AppendObject);
3. 新增修改写接口(ModifyObject);
4. 列举桶接口(ListBuckets)支持指定桶类型列举;

资料&demo:
1. 补充桶加密相关接口描述;
2. 补充追加上传接口描述;
3. 补充修改写接口描述;
4. 补充列举桶新增参数说明;

修复问题:

-----------------------------------------------------------------------------------

Version 3.21.1

新特性:
Expand Down
Binary file added huaweicloud-obs-sdk-go_3.21.8.tar.gz
Binary file not shown.
58 changes: 58 additions & 0 deletions obs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,3 +1411,61 @@ func (obsClient ObsClient) GetBucketFetchJob(input *GetBucketFetchJobInput, exte
}
return
}
func (obsClient ObsClient) AppendObject(input *AppendObjectInput, extensions ...extensionOptions) (output *AppendObjectOutput, err error) {
if input == nil {
return nil, errors.New("AppendObjectInput is nil")
}

if input.ContentType == "" && input.Key != "" {
if contentType, ok := mimeTypes[strings.ToLower(input.Key[strings.LastIndex(input.Key, ".")+1:])]; ok {
input.ContentType = contentType
}
}
output = &AppendObjectOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if input.ContentLength > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
}
}
if repeatable {
err = obsClient.doActionWithBucketAndKey("AppendObject", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
} else {
err = obsClient.doActionWithBucketAndKeyUnRepeatable("AppendObject", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
}
if err != nil {
output = nil
} else {
if err = ParseAppendObjectOutput(output); err != nil {
output = nil
}
}
return
}

func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput, extensions ...extensionOptions) (output *ModifyObjectOutput, err error) {
if input == nil {
return nil, errors.New("ModifyObjectInput is nil")
}

output = &ModifyObjectOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if input.ContentLength > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
}
}
if repeatable {
err = obsClient.doActionWithBucketAndKey("ModifyObject", HTTP_PUT, input.Bucket, input.Key, input, output, extensions)
} else {
err = obsClient.doActionWithBucketAndKeyUnRepeatable("ModifyObject", HTTP_PUT, input.Bucket, input.Key, input, output, extensions)
}
if err != nil {
output = nil
} else {
ParseModifyObjectOutput(output)
}
return
}
18 changes: 17 additions & 1 deletion obs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package obs

const (
obsSdkVersion = "3.21.1"
obsSdkVersion = "3.21.8"
USER_AGENT = "obs-sdk-go/" + obsSdkVersion
HEADER_PREFIX = "x-amz-"
HEADER_PREFIX_META = "x-amz-meta-"
Expand Down Expand Up @@ -72,6 +72,7 @@ const (
HEADER_CONTENT_DISPOSITION = "content-disposition"
HEADER_CONTENT_ENCODING = "content-encoding"
HEADER_AZ_REDUNDANCY = "az-redundancy"
HEADER_BUCKET_TYPE = "bucket-type"
headerOefMarker = "oef-marker"

HEADER_ETAG = "etag"
Expand Down Expand Up @@ -258,6 +259,7 @@ var (
"encryption": true,
"tagging": true,
"append": true,
"modify": true,
"position": true,
"replication": true,
"response-content-type": true,
Expand Down Expand Up @@ -731,6 +733,12 @@ const (

// SubResourceRequestPayment subResource value: requestPayment
SubResourceRequestPayment SubResourceType = "requestPayment"

// SubResourceAppend subResource value: append
SubResourceAppend SubResourceType = "append"

// SubResourceModify subResource value: modify
SubResourceModify SubResourceType = "modify"
)

// objectKeyType defines the objectKey value
Expand Down Expand Up @@ -950,3 +958,11 @@ const (
FSStatusEnabled FSStatusType = "Enabled"
FSStatusDisabled FSStatusType = "Disabled"
)

// BucketType defines type of bucket
type BucketType string

const (
OBJECT BucketType = "OBJECT"
POSIX BucketType = "POSIX"
)
28 changes: 27 additions & 1 deletion obs/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"net/url"
"reflect"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -731,7 +732,7 @@ func ParseGetBucketMetadataOutput(output *GetBucketMetadataOutput) {
output.Epid = ret[0]
}
if ret, ok := output.ResponseHeaders[HEADER_AZ_REDUNDANCY]; ok {
output.AvailableZone = ret[0]
output.AZRedundancy = ret[0]
}
if ret, ok := output.ResponseHeaders[headerFSFileInterface]; ok {
output.FSStatus = parseStringToFSStatusType(ret[0])
Expand Down Expand Up @@ -1086,3 +1087,28 @@ func decodeCompleteMultipartUploadOutput(output *CompleteMultipartUploadOutput)
output.Key, err = url.QueryUnescape(output.Key)
return
}

// ParseAppendObjectOutput sets AppendObjectOutput field values with response headers
func ParseAppendObjectOutput(output *AppendObjectOutput) (err error) {
if ret, ok := output.ResponseHeaders[HEADER_VERSION_ID]; ok {
output.VersionId = ret[0]
}
output.SseHeader = parseSseHeader(output.ResponseHeaders)
if ret, ok := output.ResponseHeaders[HEADER_ETAG]; ok {
output.ETag = ret[0]
}
if ret, ok := output.ResponseHeaders[HEADER_NEXT_APPEND_POSITION]; ok {
output.NextAppendPosition, err = strconv.ParseInt(ret[0], 10, 64)
if err != nil {
err = fmt.Errorf("failed to parse next append position with error [%v]", err)
}
}
return
}

// ParseModifyObjectOutput sets ModifyObjectOutput field values with response headers
func ParseModifyObjectOutput(output *ModifyObjectOutput) {
if ret, ok := output.ResponseHeaders[HEADER_ETAG]; ok {
output.ETag = ret[0]
}
}
30 changes: 29 additions & 1 deletion obs/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Initiator struct {
// ListBucketsInput is the input parameter of ListBuckets function
type ListBucketsInput struct {
QueryLocation bool
BucketType BucketType
}

// ListBucketsOutput is the result of ListBuckets function
Expand Down Expand Up @@ -531,7 +532,7 @@ type GetBucketMetadataOutput struct {
MaxAgeSeconds int
ExposeHeader string
Epid string
AvailableZone string
AZRedundancy string
FSStatus FSStatusType
}

Expand Down Expand Up @@ -1271,3 +1272,30 @@ type JobResponse struct {
FileType string `json:"file_type"`
IgnoreSameKey bool `json:"ignore_same_key"`
}

type AppendObjectInput struct {
PutObjectBasicInput
Body io.Reader
Position int64
}

type AppendObjectOutput struct {
BaseModel
VersionId string
SseHeader ISseHeader
NextAppendPosition int64
ETag string
}

type ModifyObjectInput struct {
Bucket string
Key string
Position int64
Body io.Reader
ContentLength int64
}

type ModifyObjectOutput struct {
BaseModel
ETag string
}
56 changes: 56 additions & 0 deletions obs/temporary.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,59 @@ func (obsClient ObsClient) GetBucketRequestPaymentWithSignedUrl(signedUrl string
}
return
}

// SetBucketEncryptionWithSignedURL sets bucket encryption setting for a bucket with the specified signed url and signed request headers and data
func (obsClient ObsClient) SetBucketEncryptionWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error) {
output = &BaseModel{}
err = obsClient.doHTTPWithSignedURL("SetBucketEncryption", HTTP_PUT, signedURL, actualSignedRequestHeaders, data, output, true)
if err != nil {
output = nil
}
return
}

// GetBucketEncryptionWithSignedURL gets bucket encryption setting of a bucket with the specified signed url and signed request headers
func (obsClient ObsClient) GetBucketEncryptionWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header) (output *GetBucketEncryptionOutput, err error) {
output = &GetBucketEncryptionOutput{}
err = obsClient.doHTTPWithSignedURL("GetBucketEncryption", HTTP_GET, signedURL, actualSignedRequestHeaders, nil, output, true)
if err != nil {
output = nil
}
return
}

// DeleteBucketEncryptionWithSignedURL deletes bucket encryption setting of a bucket with the specified signed url and signed request headers
func (obsClient ObsClient) DeleteBucketEncryptionWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header) (output *BaseModel, err error) {
output = &BaseModel{}
err = obsClient.doHTTPWithSignedURL("DeleteBucketEncryption", HTTP_DELETE, signedURL, actualSignedRequestHeaders, nil, output, true)
if err != nil {
output = nil
}
return
}

// AppendObjectWithSignedUrl uploads an object to the specified bucket with the specified signed url and signed request headers and data
func (obsClient ObsClient) AppendObjectWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header, data io.Reader) (output *AppendObjectOutput, err error) {
output = &AppendObjectOutput{}
err = obsClient.doHTTPWithSignedURL("AppendObject", HTTP_POST, signedURL, actualSignedRequestHeaders, data, output, true)
if err != nil {
output = nil
} else {
if err = ParseAppendObjectOutput(output); err != nil {
output = nil
}
}
return
}

// ModifyObjectWithSignedUrl uploads an object to the specified bucket with the specified signed url and signed request headers and data
func (obsClient ObsClient) ModifyObjectWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header, data io.Reader) (output *ModifyObjectOutput, err error) {
output = &ModifyObjectOutput{}
err = obsClient.doHTTPWithSignedURL("ModifyObject", HTTP_PUT, signedURL, actualSignedRequestHeaders, data, output, true)
if err != nil {
output = nil
} else {
ParseModifyObjectOutput(output)
}
return
}
32 changes: 32 additions & 0 deletions obs/trait.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"net/url"
"os"
"strconv"
"strings"
)

Expand Down Expand Up @@ -103,6 +104,9 @@ func (input ListBucketsInput) trans(isObs bool) (params map[string]string, heade
if input.QueryLocation && !isObs {
setHeaders(headers, HEADER_LOCATION_AMZ, []string{"true"}, isObs)
}
if input.BucketType != "" {
setHeaders(headers, HEADER_BUCKET_TYPE, []string{string(input.BucketType)}, true)
}
return
}

Expand Down Expand Up @@ -678,6 +682,34 @@ func (input PutObjectInput) trans(isObs bool) (params map[string]string, headers
return
}

func (input AppendObjectInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) {
params, headers, data, err = input.PutObjectBasicInput.trans(isObs)
if err != nil {
return
}
params[string(SubResourceAppend)] = ""
params["position"] = strconv.FormatInt(input.Position, 10)
if input.Body != nil {
data = input.Body
}
return
}

func (input ModifyObjectInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) {
headers = make(map[string][]string)
params = make(map[string]string)
params[string(SubResourceModify)] = ""
params["position"] = strconv.FormatInt(input.Position, 10)
if input.ContentLength > 0 {
headers[HEADER_CONTENT_LENGTH_CAMEL] = []string{Int64ToString(input.ContentLength)}
}

if input.Body != nil {
data = input.Body
}
return
}

func (input CopyObjectInput) prepareReplaceHeaders(headers map[string][]string) {
if input.CacheControl != "" {
headers[HEADER_CACHE_CONTROL] = []string{input.CacheControl}
Expand Down

0 comments on commit 782df33

Please sign in to comment.