Skip to content

Commit 3d12ece

Browse files
author
lenovo
committed
3.22.11
1 parent 3d0639d commit 3d12ece

15 files changed

Lines changed: 258 additions & 19 deletions

obs/client_base.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func New(ak, sk, endpoint string, configurers ...configurer) (*ObsClient, error)
4646

4747
if isWarnLogEnabled() {
4848
info := make([]string, 3)
49-
info[0] = fmt.Sprintf("[OBS SDK Version=%s", obsSdkVersion)
49+
info[0] = fmt.Sprintf("[OBS SDK Version=%s", OBS_SDK_VERSION)
5050
info[1] = fmt.Sprintf("Endpoint=%s", conf.endpoint)
5151
accessMode := "Virtual Hosting"
5252
if conf.pathStyle {
@@ -55,6 +55,13 @@ func New(ak, sk, endpoint string, configurers ...configurer) (*ObsClient, error)
5555
info[2] = fmt.Sprintf("Access Mode=%s]", accessMode)
5656
doLog(LEVEL_WARN, strings.Join(info, "];["))
5757
}
58+
59+
if conf.httpClient != nil {
60+
doLog(LEVEL_DEBUG, "Create obsclient with config:\n%s\n", conf)
61+
obsClient := &ObsClient{conf: conf, httpClient: conf.httpClient}
62+
return obsClient, nil
63+
}
64+
5865
doLog(LEVEL_DEBUG, "Create obsclient with config:\n%s\n", conf)
5966
obsClient := &ObsClient{conf: conf, httpClient: &http.Client{Transport: conf.transport, CheckRedirect: checkRedirectFunc}}
6067
return obsClient, nil

obs/client_bucket.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ func (obsClient ObsClient) GetBucketMetadata(input *GetBucketMetadataInput, exte
167167
return
168168
}
169169

170+
func (obsClient ObsClient) GetBucketFSStatus(input *GetBucketFSStatusInput, extensions ...extensionOptions) (output *GetBucketFSStatusOutput, err error) {
171+
output = &GetBucketFSStatusOutput{}
172+
err = obsClient.doActionWithBucket("GetBucketFSStatus", HTTP_HEAD, input.Bucket, input, output, extensions)
173+
if err != nil {
174+
output = nil
175+
} else {
176+
ParseGetBucketFSStatusOutput(output)
177+
}
178+
return
179+
}
180+
170181
// GetBucketStorageInfo gets storage information about a bucket.
171182
//
172183
// You can use this API to obtain storage information about a bucket, including the

obs/client_object.go

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package obs
1414

1515
import (
1616
"errors"
17+
"fmt"
1718
"io"
1819
"os"
1920
"strings"
@@ -200,6 +201,20 @@ func (obsClient ObsClient) GetObjectMetadata(input *GetObjectMetadataInput, exte
200201
return
201202
}
202203

204+
func (obsClient ObsClient) GetAttribute(input *GetAttributeInput, extensions ...extensionOptions) (output *GetAttributeOutput, err error) {
205+
if input == nil {
206+
return nil, errors.New("GetAttributeInput is nil")
207+
}
208+
output = &GetAttributeOutput{}
209+
err = obsClient.doActionWithBucketAndKey("GetAttribute", HTTP_HEAD, input.Bucket, input.Key, input, output, extensions)
210+
if err != nil {
211+
output = nil
212+
} else {
213+
ParseGetAttributeOutput(output)
214+
}
215+
return
216+
}
217+
203218
// GetObject downloads object.
204219
//
205220
// You can use this API to download an object in a specified bucket.
@@ -231,7 +246,9 @@ func (obsClient ObsClient) PutObject(input *PutObjectInput, extensions ...extens
231246
output = &PutObjectOutput{}
232247
var repeatable bool
233248
if input.Body != nil {
234-
_, repeatable = input.Body.(*strings.Reader)
249+
if _, ok := input.Body.(*strings.Reader); !ok {
250+
repeatable = false
251+
}
235252
if input.ContentLength > 0 {
236253
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
237254
}
@@ -266,6 +283,26 @@ func (obsClient ObsClient) isGetContentType(input *PutObjectInput) bool {
266283
return false
267284
}
268285

286+
func (obsClient ObsClient) NewFolder(input *NewFolderInput, extensions ...extensionOptions) (output *NewFolderOutput, err error) {
287+
if input == nil {
288+
return nil, errors.New("NewFolderInput is nil")
289+
}
290+
291+
if !strings.HasSuffix(input.Key, "/") {
292+
input.Key += "/"
293+
}
294+
295+
output = &NewFolderOutput{}
296+
err = obsClient.doActionWithBucketAndKey("NewFolder", HTTP_PUT, input.Bucket, input.Key, input, output, extensions)
297+
if err != nil {
298+
output = nil
299+
} else {
300+
ParseNewFolderOutput(output)
301+
output.ObjectUrl = fmt.Sprintf("%s/%s/%s", obsClient.conf.endpoint, input.Bucket, input.Key)
302+
}
303+
return
304+
}
305+
269306
// PutFile uploads a file to the specified bucket.
270307
func (obsClient ObsClient) PutFile(input *PutFileInput, extensions ...extensionOptions) (output *PutObjectOutput, err error) {
271308
if input == nil {
@@ -361,7 +398,9 @@ func (obsClient ObsClient) AppendObject(input *AppendObjectInput, extensions ...
361398
output = &AppendObjectOutput{}
362399
var repeatable bool
363400
if input.Body != nil {
364-
_, repeatable = input.Body.(*strings.Reader)
401+
if _, ok := input.Body.(*strings.Reader); !ok {
402+
repeatable = false
403+
}
365404
if input.ContentLength > 0 {
366405
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
367406
}
@@ -389,7 +428,9 @@ func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput, extensions ...
389428
output = &ModifyObjectOutput{}
390429
var repeatable bool
391430
if input.Body != nil {
392-
_, repeatable = input.Body.(*strings.Reader)
431+
if _, ok := input.Body.(*strings.Reader); !ok {
432+
repeatable = false
433+
}
393434
if input.ContentLength > 0 {
394435
input.Body = &readerWrapper{reader: input.Body, totalCount: input.ContentLength}
395436
}
@@ -406,3 +447,35 @@ func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput, extensions ...
406447
}
407448
return
408449
}
450+
451+
func (obsClient ObsClient) RenameFile(input *RenameFileInput, extensions ...extensionOptions) (output *RenameFileOutput, err error) {
452+
if input == nil {
453+
return nil, errors.New("RenameFileInput is nil")
454+
}
455+
456+
output = &RenameFileOutput{}
457+
err = obsClient.doActionWithBucketAndKey("RenameFile", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
458+
if err != nil {
459+
output = nil
460+
}
461+
return
462+
}
463+
464+
func (obsClient ObsClient) RenameFolder(input *RenameFolderInput, extensions ...extensionOptions) (output *RenameFolderOutput, err error) {
465+
if input == nil {
466+
return nil, errors.New("RenameFolderInput is nil")
467+
}
468+
469+
if !strings.HasSuffix(input.Key, "/") {
470+
input.Key += "/"
471+
}
472+
if !strings.HasSuffix(input.NewObjectKey, "/") {
473+
input.NewObjectKey += "/"
474+
}
475+
output = &RenameFolderOutput{}
476+
err = obsClient.doActionWithBucketAndKey("RenameFolder", HTTP_POST, input.Bucket, input.Key, input, output, extensions)
477+
if err != nil {
478+
output = nil
479+
}
480+
return
481+
}

obs/client_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (obsClient ObsClient) getSecurity() securityHolder {
4242
}
4343

4444
// Close closes ObsClient.
45-
func (obsClient ObsClient) Close() {
45+
func (obsClient *ObsClient) Close() {
4646
obsClient.httpClient = nil
4747
obsClient.conf.transport.CloseIdleConnections()
4848
obsClient.conf = nil

obs/client_part.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ func (obsClient ObsClient) UploadPart(_input *UploadPartInput, extensions ...ext
115115
output = &UploadPartOutput{}
116116
var repeatable bool
117117
if input.Body != nil {
118-
_, repeatable = input.Body.(*strings.Reader)
118+
if _, ok := input.Body.(*strings.Reader); !ok {
119+
repeatable = false
120+
}
119121
if _, ok := input.Body.(*readerWrapper); !ok && input.PartSize > 0 {
120122
input.Body = &readerWrapper{reader: input.Body, totalCount: input.PartSize}
121123
}

obs/conf.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type config struct {
5252
maxConnsPerHost int
5353
pemCerts []byte
5454
transport *http.Transport
55+
roundTripper http.RoundTripper
56+
httpClient *http.Client
5557
ctx context.Context
5658
maxRedirectCount int
5759
userAgent string
@@ -186,6 +188,12 @@ func WithHttpTransport(transport *http.Transport) configurer {
186188
}
187189
}
188190

191+
func WithHttpClient(httpClient *http.Client) configurer {
192+
return func(conf *config) {
193+
conf.httpClient = httpClient
194+
}
195+
}
196+
189197
// WithRequestContext is a configurer for ObsClient to set the context for each HTTP request.
190198
func WithRequestContext(ctx context.Context) configurer {
191199
return func(conf *config) {

obs/const.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
package obs
1414

1515
const (
16-
obsSdkVersion = "3.21.12"
17-
USER_AGENT = "obs-sdk-go/" + obsSdkVersion
16+
OBS_SDK_VERSION = "3.22.11"
17+
USER_AGENT = "obs-sdk-go/" + OBS_SDK_VERSION
1818
HEADER_PREFIX = "x-amz-"
1919
HEADER_PREFIX_META = "x-amz-meta-"
2020
HEADER_PREFIX_OBS = "x-obs-"
@@ -37,7 +37,10 @@ const (
3737
HEADER_RANGE = "Range"
3838
HEADER_STORAGE_CLASS = "x-default-storage-class"
3939
HEADER_STORAGE_CLASS_OBS = "x-obs-storage-class"
40+
HEADER_FS_FILE_INTERFACE_OBS = "x-obs-fs-file-interface"
41+
HEADER_MODE = "mode"
4042
HEADER_VERSION_OBS = "version"
43+
HEADER_REQUEST_PAYER = "x-amz-request-payer"
4144
HEADER_GRANT_READ_OBS = "grant-read"
4245
HEADER_GRANT_WRITE_OBS = "grant-write"
4346
HEADER_GRANT_READ_ACP_OBS = "grant-read-acp"
@@ -274,6 +277,8 @@ var (
274277
"x-image-save-bucket": true,
275278
"x-image-save-object": true,
276279
"ignore-sign-in-query": true,
280+
"name": true,
281+
"rename": true,
277282
}
278283

279284
mimeTypes = map[string]string{
@@ -653,6 +658,13 @@ var (
653658
"yaml": "text/yaml",
654659
"yml": "text/yaml",
655660
"zip": "application/zip",
661+
"dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
662+
"wps": "application/vnd.ms-works",
663+
"wpt": "x-lml/x-gps",
664+
"pptm": "application/vnd.ms-powerpoint.presentation.macroenabled.12",
665+
"heic": "image/heic",
666+
"mkv": "video/x-matroska",
667+
"raw": "image/x-panasonic-raw",
656668
}
657669
)
658670

@@ -740,6 +752,8 @@ const (
740752

741753
// SubResourceModify subResource value: modify
742754
SubResourceModify SubResourceType = "modify"
755+
756+
SubResourceRename SubResourceType = "rename"
743757
)
744758

745759
// objectKeyType defines the objectKey value

obs/convert.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ func ParseStringToStorageClassType(value string) (ret StorageClassType) {
8080
return
8181
}
8282

83+
func ParseStringToFSStatusType(value string) (ret FSStatusType) {
84+
switch value {
85+
case "Enabled":
86+
ret = FSStatusEnabled
87+
case "Disabled":
88+
ret = FSStatusDisabled
89+
default:
90+
ret = ""
91+
}
92+
return
93+
}
94+
8395
func prepareGrantURI(grant Grant) string {
8496
if grant.Grantee.URI == GroupAllUsers || grant.Grantee.URI == GroupAuthenticatedUsers {
8597
return fmt.Sprintf("<URI>%s%s</URI>", "http://acs.amazonaws.com/groups/global/", grant.Grantee.URI)
@@ -1112,3 +1124,24 @@ func ParseModifyObjectOutput(output *ModifyObjectOutput) {
11121124
output.ETag = ret[0]
11131125
}
11141126
}
1127+
1128+
func ParseGetBucketFSStatusOutput(output *GetBucketFSStatusOutput) {
1129+
ParseGetBucketMetadataOutput(&output.GetBucketMetadataOutput)
1130+
1131+
if ret, ok := output.ResponseHeaders[HEADER_FS_FILE_INTERFACE_OBS]; ok {
1132+
output.FSStatus = ParseStringToFSStatusType(ret[0])
1133+
}
1134+
}
1135+
1136+
func ParseGetAttributeOutput(output *GetAttributeOutput) {
1137+
ParseGetObjectMetadataOutput(&output.GetObjectMetadataOutput)
1138+
if ret, ok := output.ResponseHeaders[HEADER_MODE]; ok {
1139+
output.Mode = StringToInt(ret[0], -1)
1140+
} else {
1141+
output.Mode = -1
1142+
}
1143+
}
1144+
1145+
func ParseNewFolderOutput(output *NewFolderOutput) {
1146+
ParsePutObjectOutput(&output.PutObjectOutput)
1147+
}

obs/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ func prepareRetry(resp *http.Response, headers map[string][]string, _data io.Rea
464464
if err != nil {
465465
return nil, nil, err
466466
}
467+
r.readedCount = 0
467468
}
468469
return _data, resp, nil
469470
}

obs/log.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func initLogFile(_fullPath string) (os.FileInfo, *os.File, error) {
268268

269269
fd, err := os.OpenFile(_fullPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
270270
if err != nil {
271+
_err := fd.Close()
272+
if _err != nil {
273+
doLog(LEVEL_WARN, "Failed to close file with reason: %v", _err)
274+
}
271275
return nil, nil, err
272276
}
273277

0 commit comments

Comments
 (0)