Skip to content

Commit

Permalink
3.22.11
Browse files Browse the repository at this point in the history
  • Loading branch information
lenovo committed Nov 23, 2022
1 parent 3d0639d commit 3d12ece
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 19 deletions.
9 changes: 8 additions & 1 deletion obs/client_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(ak, sk, endpoint string, configurers ...configurer) (*ObsClient, error)

if isWarnLogEnabled() {
info := make([]string, 3)
info[0] = fmt.Sprintf("[OBS SDK Version=%s", obsSdkVersion)
info[0] = fmt.Sprintf("[OBS SDK Version=%s", OBS_SDK_VERSION)
info[1] = fmt.Sprintf("Endpoint=%s", conf.endpoint)
accessMode := "Virtual Hosting"
if conf.pathStyle {
Expand All @@ -55,6 +55,13 @@ func New(ak, sk, endpoint string, configurers ...configurer) (*ObsClient, error)
info[2] = fmt.Sprintf("Access Mode=%s]", accessMode)
doLog(LEVEL_WARN, strings.Join(info, "];["))
}

if conf.httpClient != nil {
doLog(LEVEL_DEBUG, "Create obsclient with config:\n%s\n", conf)
obsClient := &ObsClient{conf: conf, httpClient: conf.httpClient}
return obsClient, nil
}

doLog(LEVEL_DEBUG, "Create obsclient with config:\n%s\n", conf)
obsClient := &ObsClient{conf: conf, httpClient: &http.Client{Transport: conf.transport, CheckRedirect: checkRedirectFunc}}
return obsClient, nil
Expand Down
11 changes: 11 additions & 0 deletions obs/client_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ func (obsClient ObsClient) GetBucketMetadata(input *GetBucketMetadataInput, exte
return
}

func (obsClient ObsClient) GetBucketFSStatus(input *GetBucketFSStatusInput, extensions ...extensionOptions) (output *GetBucketFSStatusOutput, err error) {
output = &GetBucketFSStatusOutput{}
err = obsClient.doActionWithBucket("GetBucketFSStatus", HTTP_HEAD, input.Bucket, input, output, extensions)
if err != nil {
output = nil
} else {
ParseGetBucketFSStatusOutput(output)
}
return
}

// GetBucketStorageInfo gets storage information about a bucket.
//
// You can use this API to obtain storage information about a bucket, including the
Expand Down
79 changes: 76 additions & 3 deletions obs/client_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package obs

import (
"errors"
"fmt"
"io"
"os"
"strings"
Expand Down Expand Up @@ -200,6 +201,20 @@ func (obsClient ObsClient) GetObjectMetadata(input *GetObjectMetadataInput, exte
return
}

func (obsClient ObsClient) GetAttribute(input *GetAttributeInput, extensions ...extensionOptions) (output *GetAttributeOutput, err error) {
if input == nil {
return nil, errors.New("GetAttributeInput is nil")
}
output = &GetAttributeOutput{}
err = obsClient.doActionWithBucketAndKey("GetAttribute", HTTP_HEAD, input.Bucket, input.Key, input, output, extensions)
if err != nil {
output = nil
} else {
ParseGetAttributeOutput(output)
}
return
}

// GetObject downloads object.
//
// You can use this API to download an object in a specified bucket.
Expand Down Expand Up @@ -231,7 +246,9 @@ func (obsClient ObsClient) PutObject(input *PutObjectInput, extensions ...extens
output = &PutObjectOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if _, ok := input.Body.(*strings.Reader); !ok {
repeatable = false
}
if input.ContentLength > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
}
Expand Down Expand Up @@ -266,6 +283,26 @@ func (obsClient ObsClient) isGetContentType(input *PutObjectInput) bool {
return false
}

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

if !strings.HasSuffix(input.Key, "/") {
input.Key += "/"
}

output = &NewFolderOutput{}
err = obsClient.doActionWithBucketAndKey("NewFolder", HTTP_PUT, input.Bucket, input.Key, input, output, extensions)
if err != nil {
output = nil
} else {
ParseNewFolderOutput(output)
output.ObjectUrl = fmt.Sprintf("%s/%s/%s", obsClient.conf.endpoint, input.Bucket, input.Key)
}
return
}

// PutFile uploads a file to the specified bucket.
func (obsClient ObsClient) PutFile(input *PutFileInput, extensions ...extensionOptions) (output *PutObjectOutput, err error) {
if input == nil {
Expand Down Expand Up @@ -361,7 +398,9 @@ func (obsClient ObsClient) AppendObject(input *AppendObjectInput, extensions ...
output = &AppendObjectOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if _, ok := input.Body.(*strings.Reader); !ok {
repeatable = false
}
if input.ContentLength > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
}
Expand Down Expand Up @@ -389,7 +428,9 @@ func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput, extensions ...
output = &ModifyObjectOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if _, ok := input.Body.(*strings.Reader); !ok {
repeatable = false
}
if input.ContentLength > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
}
Expand All @@ -406,3 +447,35 @@ func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput, extensions ...
}
return
}

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

output = &RenameFileOutput{}
err = obsClient.doActionWithBucketAndKey("RenameFile", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
if err != nil {
output = nil
}
return
}

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

if !strings.HasSuffix(input.Key, "/") {
input.Key += "/"
}
if !strings.HasSuffix(input.NewObjectKey, "/") {
input.NewObjectKey += "/"
}
output = &RenameFolderOutput{}
err = obsClient.doActionWithBucketAndKey("RenameFolder", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
if err != nil {
output = nil
}
return
}
2 changes: 1 addition & 1 deletion obs/client_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (obsClient ObsClient) getSecurity() securityHolder {
}

// Close closes ObsClient.
func (obsClient ObsClient) Close() {
func (obsClient *ObsClient) Close() {
obsClient.httpClient = nil
obsClient.conf.transport.CloseIdleConnections()
obsClient.conf = nil
Expand Down
4 changes: 3 additions & 1 deletion obs/client_part.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func (obsClient ObsClient) UploadPart(_input *UploadPartInput, extensions ...ext
output = &UploadPartOutput{}
var repeatable bool
if input.Body != nil {
_, repeatable = input.Body.(*strings.Reader)
if _, ok := input.Body.(*strings.Reader); !ok {
repeatable = false
}
if _, ok := input.Body.(*readerWrapper); !ok && input.PartSize > 0 {
input.Body = &readerWrapper{reader: input.Body, totalCount: input.PartSize}
}
Expand Down
8 changes: 8 additions & 0 deletions obs/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type config struct {
maxConnsPerHost int
pemCerts []byte
transport *http.Transport
roundTripper http.RoundTripper
httpClient *http.Client
ctx context.Context
maxRedirectCount int
userAgent string
Expand Down Expand Up @@ -186,6 +188,12 @@ func WithHttpTransport(transport *http.Transport) configurer {
}
}

func WithHttpClient(httpClient *http.Client) configurer {
return func(conf *config) {
conf.httpClient = httpClient
}
}

// WithRequestContext is a configurer for ObsClient to set the context for each HTTP request.
func WithRequestContext(ctx context.Context) configurer {
return func(conf *config) {
Expand Down
18 changes: 16 additions & 2 deletions obs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package obs

const (
obsSdkVersion = "3.21.12"
USER_AGENT = "obs-sdk-go/" + obsSdkVersion
OBS_SDK_VERSION = "3.22.11"
USER_AGENT = "obs-sdk-go/" + OBS_SDK_VERSION
HEADER_PREFIX = "x-amz-"
HEADER_PREFIX_META = "x-amz-meta-"
HEADER_PREFIX_OBS = "x-obs-"
Expand All @@ -37,7 +37,10 @@ const (
HEADER_RANGE = "Range"
HEADER_STORAGE_CLASS = "x-default-storage-class"
HEADER_STORAGE_CLASS_OBS = "x-obs-storage-class"
HEADER_FS_FILE_INTERFACE_OBS = "x-obs-fs-file-interface"
HEADER_MODE = "mode"
HEADER_VERSION_OBS = "version"
HEADER_REQUEST_PAYER = "x-amz-request-payer"
HEADER_GRANT_READ_OBS = "grant-read"
HEADER_GRANT_WRITE_OBS = "grant-write"
HEADER_GRANT_READ_ACP_OBS = "grant-read-acp"
Expand Down Expand Up @@ -274,6 +277,8 @@ var (
"x-image-save-bucket": true,
"x-image-save-object": true,
"ignore-sign-in-query": true,
"name": true,
"rename": true,
}

mimeTypes = map[string]string{
Expand Down Expand Up @@ -653,6 +658,13 @@ var (
"yaml": "text/yaml",
"yml": "text/yaml",
"zip": "application/zip",
"dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
"wps": "application/vnd.ms-works",
"wpt": "x-lml/x-gps",
"pptm": "application/vnd.ms-powerpoint.presentation.macroenabled.12",
"heic": "image/heic",
"mkv": "video/x-matroska",
"raw": "image/x-panasonic-raw",
}
)

Expand Down Expand Up @@ -740,6 +752,8 @@ const (

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

SubResourceRename SubResourceType = "rename"
)

// objectKeyType defines the objectKey value
Expand Down
33 changes: 33 additions & 0 deletions obs/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ func ParseStringToStorageClassType(value string) (ret StorageClassType) {
return
}

func ParseStringToFSStatusType(value string) (ret FSStatusType) {
switch value {
case "Enabled":
ret = FSStatusEnabled
case "Disabled":
ret = FSStatusDisabled
default:
ret = ""
}
return
}

func prepareGrantURI(grant Grant) string {
if grant.Grantee.URI == GroupAllUsers || grant.Grantee.URI == GroupAuthenticatedUsers {
return fmt.Sprintf("<URI>%s%s</URI>", "http://acs.amazonaws.com/groups/global/", grant.Grantee.URI)
Expand Down Expand Up @@ -1112,3 +1124,24 @@ func ParseModifyObjectOutput(output *ModifyObjectOutput) {
output.ETag = ret[0]
}
}

func ParseGetBucketFSStatusOutput(output *GetBucketFSStatusOutput) {
ParseGetBucketMetadataOutput(&output.GetBucketMetadataOutput)

if ret, ok := output.ResponseHeaders[HEADER_FS_FILE_INTERFACE_OBS]; ok {
output.FSStatus = ParseStringToFSStatusType(ret[0])
}
}

func ParseGetAttributeOutput(output *GetAttributeOutput) {
ParseGetObjectMetadataOutput(&output.GetObjectMetadataOutput)
if ret, ok := output.ResponseHeaders[HEADER_MODE]; ok {
output.Mode = StringToInt(ret[0], -1)
} else {
output.Mode = -1
}
}

func ParseNewFolderOutput(output *NewFolderOutput) {
ParsePutObjectOutput(&output.PutObjectOutput)
}
1 change: 1 addition & 0 deletions obs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ func prepareRetry(resp *http.Response, headers map[string][]string, _data io.Rea
if err != nil {
return nil, nil, err
}
r.readedCount = 0
}
return _data, resp, nil
}
Expand Down
4 changes: 4 additions & 0 deletions obs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func initLogFile(_fullPath string) (os.FileInfo, *os.File, error) {

fd, err := os.OpenFile(_fullPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
_err := fd.Close()
if _err != nil {
doLog(LEVEL_WARN, "Failed to close file with reason: %v", _err)
}
return nil, nil, err
}

Expand Down
9 changes: 9 additions & 0 deletions obs/model_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,12 @@ type GetBucketFetchJobOutput struct {
BaseModel
GetBucketFetchJobResponse
}

type GetBucketFSStatusInput struct {
GetBucketMetadataInput
}

type GetBucketFSStatusOutput struct {
GetBucketMetadataOutput
FSStatus FSStatusType
}
Loading

0 comments on commit 3d12ece

Please sign in to comment.