From fed907b98ca359fb8be1c7188054035c4db8824c Mon Sep 17 00:00:00 2001 From: zhangtingwei998 Date: Sun, 28 Apr 2024 16:37:00 +0800 Subject: [PATCH] update 3.24.3 --- README.MD | 12 ++++++++ README_CN.MD | 12 ++++++++ main/obs_go_sample.go | 64 +++++++++++++++++++++++++++++++++++++++++-- obs/client_bucket.go | 8 +++--- obs/client_object.go | 36 ++++++++++++++++++++++++ obs/const.go | 1 + obs/convert.go | 25 ++++++++--------- obs/log.go | 36 ++++++++++++------------ obs/model_bucket.go | 33 +++++++++++++++++++--- obs/model_object.go | 31 ++++++--------------- obs/model_part.go | 2 +- obs/trait_bucket.go | 4 +-- obs/trait_object.go | 37 +++++++++++++++++++++---- obs/trait_part.go | 15 ++++++++++ obs/transfer.go | 8 +++--- obs/type.go | 3 ++ obs/util.go | 14 ++++++++-- 17 files changed, 262 insertions(+), 79 deletions(-) diff --git a/README.MD b/README.MD index 72ca392..c25b0cf 100644 --- a/README.MD +++ b/README.MD @@ -1,3 +1,15 @@ +Version 3.24.3 + +New Features: +1. Added directory accesslable-related APIs, including SetDirAccesslabel, GetDirAccesslabel, and DeleteDirAccesslabel. + +Documentation & Demo: +1. Added descriptions about directory accesslable-related APIs. + +Resolved Issues: + +----------------------------------------------------------------------------------- + Version 3.23.12 New Features: diff --git a/README_CN.MD b/README_CN.MD index 1415b5b..7af9417 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -1,3 +1,15 @@ +Version 3.24.3 + +新特性: +1. 新增accesslabel相关接口:设置对象accesslabel(SetDirAccesslabel), 获取对象accesslabel(GetDirAccesslabel), 删除对象accesslabel(DeleteDirAccesslabel); + +资料&demo: +1. 补充accesslabel相关接口描述; + +修复问题: + +----------------------------------------------------------------------------------- + Version 3.23.12 新特性: diff --git a/main/obs_go_sample.go b/main/obs_go_sample.go index cc3f0dc..0a9ef52 100644 --- a/main/obs_go_sample.go +++ b/main/obs_go_sample.go @@ -1701,11 +1701,11 @@ func putFileWithProgress() { func appendObjectWithProgress() { input := &obs.AppendObjectInput{} - input.Bucket = bucketName + input.Bucket = bucketName input.Key = objectKey input.Position = 9 - input.Body = strings.NewReader("Hello OBS") - output, err := getObsClient().AppendObject(input, obs.WithProgress(&ObsProgressListener{})) + input.Body = strings.NewReader("Hello OBS") + output, err := getObsClient().AppendObject(input, obs.WithProgress(&ObsProgressListener{})) if err == nil { fmt.Printf("Append object(%s) under the bucket(%s) successful!\n", input.Key, input.Bucket) fmt.Printf("ETag:%s, NextAppendPosition:%d\n", output.ETag, output.NextAppendPosition) @@ -1722,6 +1722,61 @@ func appendObjectWithProgress() { } +func setDirAccesslabel() { + input := &obs.SetDirAccesslabelInput{} + input.Bucket = posixBucketName + input.Key = posixFileKey + input.Accesslabel = []string{"role_label_01", "role_label_02"} + output, err := getObsClient().SetDirAccesslabel(input) + if err == nil { + fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId) + } else { + if obsError, ok := err.(obs.ObsError); ok { + fmt.Println(obsError.StatusCode) + fmt.Println(obsError.Code) + fmt.Println(obsError.Message) + } else { + fmt.Println(err) + } + } +} + +func getDirAccesslabel() { + input := &obs.GetDirAccesslabelInput{} + input.Bucket = posixBucketName + input.Key = posixFileKey + output, err := getObsClient().GetDirAccesslabel(input) + if err == nil { + fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId) + } else { + if obsError, ok := err.(obs.ObsError); ok { + fmt.Println(obsError.StatusCode) + fmt.Println(obsError.Code) + fmt.Println(obsError.Message) + } else { + fmt.Println(err) + } + } +} + +func deleteDirAccesslabel() { + input := &obs.DeleteDirAccesslabelInput{} + input.Bucket = posixBucketName + input.Key = posixFileKey + output, err := getObsClient().DeleteDirAccesslabel(input) + if err == nil { + fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId) + } else { + if obsError, ok := err.(obs.ObsError); ok { + fmt.Println(obsError.StatusCode) + fmt.Println(obsError.Code) + fmt.Println(obsError.Message) + } else { + fmt.Println(err) + } + } +} + func runExamples() { examples.RunBucketOperationsSample() // examples.RunObjectOperationsSample() @@ -1823,4 +1878,7 @@ func main() { // getObjectWithProgress() // putObjectWithCallback() // deleteBucket() + // setDirAccesslabel() + // getDirAccesslabel() + // deleteDirAccesslabel() } diff --git a/obs/client_bucket.go b/obs/client_bucket.go index 66270ae..d3c9f87 100644 --- a/obs/client_bucket.go +++ b/obs/client_bucket.go @@ -44,8 +44,8 @@ func (obsClient ObsClient) SetBucketCustomDomain(input *SetBucketCustomDomainInp return } -func (obsClient ObsClient) GetBucketCustomDomain(bucketName string, extensions ...extensionOptions) (output *GetBucketCustomDomainOuput, err error) { - output = &GetBucketCustomDomainOuput{} +func (obsClient ObsClient) GetBucketCustomDomain(bucketName string, extensions ...extensionOptions) (output *GetBucketCustomDomainOutput, err error) { + output = &GetBucketCustomDomainOutput{} err = obsClient.doActionWithBucket("GetBucketCustomDomain", HTTP_GET, bucketName, newSubResourceSerial(SubResourceCustomDomain), output, extensions) if err != nil { output = nil @@ -72,8 +72,8 @@ func (obsClient ObsClient) DeleteBucketMirrorBackToSource(bucketName string, ext return } -func (obsClient ObsClient) GetBucketMirrorBackToSource(bucketName string, extensions ...extensionOptions) (output *GetBucketMirrorBackToSourceOuput, err error) { - output = &GetBucketMirrorBackToSourceOuput{} +func (obsClient ObsClient) GetBucketMirrorBackToSource(bucketName string, extensions ...extensionOptions) (output *GetBucketMirrorBackToSourceOutput, err error) { + output = &GetBucketMirrorBackToSourceOutput{} err = obsClient.doActionWithBucketV2("GetBucketMirrorBackToSource", HTTP_GET, bucketName, newSubResourceSerial(SubResourceMirrorBackToSource), output, extensions) if err != nil { output = nil diff --git a/obs/client_object.go b/obs/client_object.go index 7835e98..818f47b 100644 --- a/obs/client_object.go +++ b/obs/client_object.go @@ -504,3 +504,39 @@ func (obsClient ObsClient) RenameFolder(input *RenameFolderInput, extensions ... } return } + +func (obsClient ObsClient) SetDirAccesslabel(input *SetDirAccesslabelInput, extensions ...extensionOptions) (output *BaseModel, err error) { + if input == nil { + return nil, errors.New("SetDirAccesslabelInput is nil") + } + output = &BaseModel{} + err = obsClient.doActionWithBucketAndKeyV2("SetDirAccesslabel", HTTP_PUT, input.Bucket, input.Key, input, output, extensions) + if err != nil { + output = nil + } + return +} + +func (obsClient ObsClient) GetDirAccesslabel(input *GetDirAccesslabelInput, extensions ...extensionOptions) (output *GetDirAccesslabelOutput, err error) { + if input == nil { + return nil, errors.New("GetDirAccesslabelInput is nil") + } + output = &GetDirAccesslabelOutput{} + err = obsClient.doActionWithBucketAndKeyV2("GetDirAccesslabel", HTTP_GET, input.Bucket, input.Key, input, output, extensions) + if err != nil { + output = nil + } + return +} + +func (obsClient ObsClient) DeleteDirAccesslabel(input *DeleteDirAccesslabelInput, extensions ...extensionOptions) (output *BaseModel, err error) { + if input == nil { + return nil, errors.New("DeleteDirAccesslabelInput is nil") + } + output = &BaseModel{} + err = obsClient.doActionWithBucketAndKeyV2("DeleteDirAccesslabel", HTTP_DELETE, input.Bucket, input.Key, input, output, extensions) + if err != nil { + output = nil + } + return +} diff --git a/obs/const.go b/obs/const.go index 148d92a..d5872ff 100644 --- a/obs/const.go +++ b/obs/const.go @@ -290,6 +290,7 @@ var ( "rename": true, "customdomain": true, "mirrorbacktosource": true, + "x-obs-accesslabel": true, } obsStorageClasses = []string{ diff --git a/obs/convert.go b/obs/convert.go index 56e6166..81099a6 100644 --- a/obs/convert.go +++ b/obs/convert.go @@ -538,8 +538,8 @@ func converntConfigureToXML(topicConfiguration TopicConfiguration, xmlElem strin return strings.Join(xml, "") } -// ConverntObsRestoreToXml converts RestoreObjectInput value to XML data and returns it -func ConverntObsRestoreToXml(restoreObjectInput RestoreObjectInput) string { +// ConventObsRestoreToXml converts RestoreObjectInput value to XML data and returns it +func ConventObsRestoreToXml(restoreObjectInput RestoreObjectInput) string { xml := make([]string, 0, 2) xml = append(xml, fmt.Sprintf("%d", restoreObjectInput.Days)) if restoreObjectInput.Tier != "Bulk" { @@ -669,26 +669,24 @@ func parseUnCommonHeader(output *GetObjectMetadataOutput) { } func parseStandardMetadataHeader(output *GetObjectMetadataOutput) { - httpHeader := HttpHeader{} if ret, ok := output.ResponseHeaders[HEADER_CONTENT_TYPE]; ok { - httpHeader.ContentType = ret[0] + output.ContentType = ret[0] } if ret, ok := output.ResponseHeaders[HEADER_CONTENT_ENCODING]; ok { - httpHeader.ContentEncoding = ret[0] + output.ContentEncoding = ret[0] } if ret, ok := output.ResponseHeaders[HEADER_CACHE_CONTROL]; ok { - httpHeader.CacheControl = ret[0] + output.CacheControl = ret[0] } if ret, ok := output.ResponseHeaders[HEADER_CONTENT_DISPOSITION]; ok { - httpHeader.ContentDisposition = ret[0] + output.ContentDisposition = ret[0] } if ret, ok := output.ResponseHeaders[HEADER_CONTENT_LANGUAGE]; ok { - httpHeader.ContentLanguage = ret[0] + output.ContentLanguage = ret[0] } if ret, ok := output.ResponseHeaders[HEADER_EXPIRES]; ok { - httpHeader.HttpExpires = ret[0] + output.HttpExpires = ret[0] } - output.HttpHeader = httpHeader } // ParseGetObjectMetadataOutput sets GetObjectMetadataOutput field values with response headers @@ -702,9 +700,6 @@ func ParseGetObjectMetadataOutput(output *GetObjectMetadataOutput) { if ret, ok := output.ResponseHeaders[HEADER_ETAG]; ok { output.ETag = ret[0] } - if ret, ok := output.ResponseHeaders[HEADER_CONTENT_TYPE]; ok { - output.ContentType = ret[0] - } output.SseHeader = parseSseHeader(output.ResponseHeaders) if ret, ok := output.ResponseHeaders[HEADER_LASTMODIFIED]; ok { @@ -888,6 +883,9 @@ func ParseGetObjectOutput(output *GetObjectOutput) { if ret, ok := output.ResponseHeaders[HEADER_DELETE_MARKER]; ok { output.DeleteMarker = ret[0] == "true" } + if ret, ok := output.ResponseHeaders[HEADER_CONTENT_TYPE]; ok { + output.ContentType = ret[0] + } if ret, ok := output.ResponseHeaders[HEADER_CACHE_CONTROL]; ok { output.CacheControl = ret[0] } @@ -902,6 +900,7 @@ func ParseGetObjectOutput(output *GetObjectOutput) { } if ret, ok := output.ResponseHeaders[HEADER_EXPIRES]; ok { output.Expires = ret[0] + output.HttpExpires = ret[0] } } diff --git a/obs/log.go b/obs/log.go index 184ac96..9788d9a 100644 --- a/obs/log.go +++ b/obs/log.go @@ -21,6 +21,7 @@ import ( "runtime" "strings" "sync" + "time" ) // Level defines the level of the log @@ -63,24 +64,24 @@ func getDefaultLogConf() logConfType { var logConf logConfType type loggerWrapper struct { - fullPath string - fd *os.File - ch chan string - wg sync.WaitGroup - queue []string - logger *log.Logger - index int - cacheCount int - closed bool - formatLoggerNow func(string) string + fullPath string + fd *os.File + ch chan string + wg sync.WaitGroup + queue []string + logger *log.Logger + index int + cacheCount int + closed bool + loc *time.Location } func (lw *loggerWrapper) doInit() { lw.queue = make([]string, 0, lw.cacheCount) lw.logger = log.New(lw.fd, "", 0) lw.ch = make(chan string, lw.cacheCount) - if lw.formatLoggerNow == nil { - lw.formatLoggerNow = FormatUtcNow + if lw.loc == nil { + lw.loc = time.FixedZone("UTC", 0) } lw.wg.Add(1) go lw.doWrite() @@ -98,7 +99,7 @@ func (lw *loggerWrapper) rotate() { if stat.Size() >= logConf.maxLogSize { _err := lw.fd.Sync() if _err != nil { - panic(err) + panic(_err) } _err = lw.fd.Close() if _err != nil { @@ -109,7 +110,7 @@ func (lw *loggerWrapper) rotate() { } _err = os.Rename(lw.fullPath, lw.fullPath+"."+IntToString(lw.index)) if _err != nil { - panic(err) + panic(_err) } lw.index++ @@ -198,9 +199,9 @@ func reset() { type logConfig func(lw *loggerWrapper) -func WithFormatLoggerTime(formatNow func(string) string) logConfig { +func WithLoggerTimeLoc(loc *time.Location) logConfig { return func(lw *loggerWrapper) { - lw.formatLoggerNow = formatNow + lw.loc = loc } } @@ -339,11 +340,12 @@ func doLog(level Level, format string, v ...interface{}) { _ = recover() // ignore ch closed error }() + nowDate := FormatNowWithLoc("2006-01-02T15:04:05.000ZZ", fileLogger.loc) + if consoleLogger != nil { consoleLogger.Printf("%s%s", prefix, msg) } if fileLogger != nil { - nowDate := fileLogger.formatLoggerNow("2006-01-02T15:04:05.000ZZ") fileLogger.Printf("%s %s%s", nowDate, prefix, msg) } } diff --git a/obs/model_bucket.go b/obs/model_bucket.go index 9050428..1b90f6b 100644 --- a/obs/model_bucket.go +++ b/obs/model_bucket.go @@ -22,8 +22,8 @@ type DeleteBucketCustomDomainInput struct { CustomDomain string } -// GetBucketCustomDomainOuput is the result of GetBucketCustomdomain function -type GetBucketCustomDomainOuput struct { +// GetBucketCustomDomainOutput is the result of GetBucketCustomDomain function +type GetBucketCustomDomainOutput struct { BaseModel Domains []Domain `xml:"Domains"` } @@ -34,8 +34,8 @@ type SetBucketCustomDomainInput struct { CustomDomain string } -// GetBucketMirrorBackToSourceOuput is the result of GetBucketMirrorBackToSource function -type GetBucketMirrorBackToSourceOuput struct { +// GetBucketMirrorBackToSourceOutput is the result of GetBucketMirrorBackToSource function +type GetBucketMirrorBackToSourceOutput struct { BaseModel Rules string `json:"body"` } @@ -377,3 +377,28 @@ type GetBucketFSStatusOutput struct { GetBucketMetadataOutput FSStatus FSStatusType } + +type SetDirAccesslabelInput struct { + BaseDirAccesslabelInput + Accesslabel []string +} + +type GetDirAccesslabelInput struct { + BaseDirAccesslabelInput +} + +type GetDirAccesslabelOutput struct { + BaseModel + Accesslabel []string +} + +type DeleteDirAccesslabelInput struct { + BaseDirAccesslabelInput + Accesslabel []string +} + +type BaseDirAccesslabelInput struct { + Bucket string + Key string + Accesslabel []string +} diff --git a/obs/model_object.go b/obs/model_object.go index e1bc4a8..3305bb6 100644 --- a/obs/model_object.go +++ b/obs/model_object.go @@ -167,7 +167,6 @@ type GetObjectMetadataOutput struct { NextAppendPosition string StorageClass StorageClassType ContentLength int64 - ContentType string ETag string AllowOrigin string AllowHeader string @@ -211,13 +210,9 @@ type GetObjectInput struct { // GetObjectOutput is the result of GetObject function type GetObjectOutput struct { GetObjectMetadataOutput - DeleteMarker bool - CacheControl string - ContentDisposition string - ContentEncoding string - ContentLanguage string - Expires string - Body io.ReadCloser + DeleteMarker bool + Expires string + Body io.ReadCloser } // ObjectOperationInput defines the object operation properties @@ -234,12 +229,12 @@ type ObjectOperationInput struct { Expires int64 SseHeader ISseHeader Metadata map[string]string - HttpHeader } // PutObjectBasicInput defines the basic object operation properties type PutObjectBasicInput struct { ObjectOperationInput + HttpHeader ContentMD5 string ContentLength int64 } @@ -287,14 +282,10 @@ type CopyObjectInput struct { CopySourceIfUnmodifiedSince time.Time CopySourceIfModifiedSince time.Time SourceSseHeader ISseHeader - CacheControl string - ContentDisposition string - ContentEncoding string - ContentLanguage string - ContentType string Expires string MetadataDirective MetadataDirectiveType SuccessActionRedirect string + HttpHeader } // CopyObjectOutput is the result of CopyObject function @@ -311,13 +302,13 @@ type CopyObjectOutput struct { // UploadFileInput is the input parameter of UploadFile function type UploadFileInput struct { ObjectOperationInput - ContentType string UploadFile string PartSize int64 TaskNum int EnableCheckpoint bool CheckpointFile string EncodingType string + HttpHeader } // DownloadFileInput is the input parameter of DownloadFile function @@ -403,15 +394,11 @@ type SetObjectMetadataInput struct { HttpHeader } -//SetObjectMetadataOutput is the result of SetObjectMetadata function +// SetObjectMetadataOutput is the result of SetObjectMetadata function type SetObjectMetadataOutput struct { BaseModel - MetadataDirective MetadataDirectiveType - CacheControl string - ContentDisposition string - ContentEncoding string - ContentLanguage string - ContentType string + MetadataDirective MetadataDirectiveType + HttpHeader Expires string WebsiteRedirectLocation string StorageClass StorageClassType diff --git a/obs/model_part.go b/obs/model_part.go index 66f485e..85bd3b2 100644 --- a/obs/model_part.go +++ b/obs/model_part.go @@ -57,7 +57,7 @@ type AbortMultipartUploadInput struct { // InitiateMultipartUploadInput is the input parameter of InitiateMultipartUpload function type InitiateMultipartUploadInput struct { ObjectOperationInput - ContentType string + HttpHeader EncodingType string } diff --git a/obs/trait_bucket.go b/obs/trait_bucket.go index 645fddb..e3063c6 100644 --- a/obs/trait_bucket.go +++ b/obs/trait_bucket.go @@ -269,10 +269,8 @@ func (input GetBucketFetchJobInput) trans(isObs bool) (params map[string]string, func (input SetBucketMirrorBackToSourceInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) { params = map[string]string{string(SubResourceMirrorBackToSource): ""} - - contentType, _ := mimeTypes["json"] headers = make(map[string][]string, 1) - headers[HEADER_CONTENT_TYPE] = []string{contentType} + headers[HEADER_CONTENT_TYPE] = []string{mimeTypes["json"]} data = input.Rules return } diff --git a/obs/trait_object.go b/obs/trait_object.go index 48011ca..ba93e9c 100644 --- a/obs/trait_object.go +++ b/obs/trait_object.go @@ -124,7 +124,7 @@ func (input RestoreObjectInput) trans(isObs bool) (params map[string]string, hea if !isObs { data, err = ConvertRequestToIoReader(input) } else { - data = ConverntObsRestoreToXml(input) + data = ConventObsRestoreToXml(input) } return } @@ -386,6 +386,9 @@ func (input ModifyObjectInput) trans(isObs bool) (params map[string]string, head } func (input CopyObjectInput) prepareReplaceHeaders(headers map[string][]string) { + if input.ContentType != "" { + headers[HEADER_CONTENT_TYPE] = []string{input.ContentType} + } if input.CacheControl != "" { headers[HEADER_CACHE_CONTROL] = []string{input.CacheControl} } @@ -398,11 +401,11 @@ func (input CopyObjectInput) prepareReplaceHeaders(headers map[string][]string) if input.ContentLanguage != "" { headers[HEADER_CONTENT_LANGUAGE] = []string{input.ContentLanguage} } - if input.ContentType != "" { - headers[HEADER_CONTENT_TYPE] = []string{input.ContentType} - } + // 这里为了兼容老版本,默认以Expire值为准,但如果Expires没有,则以HttpExpires为准。 if input.Expires != "" { - headers[HEADER_EXPIRES] = []string{input.Expires} + headers[HEADER_EXPIRES_CAMEL] = []string{input.Expires} + } else if input.HttpExpires != "" { + headers[HEADER_EXPIRES_CAMEL] = []string{input.HttpExpires} } } @@ -484,3 +487,27 @@ func (input RenameFolderInput) trans(isObs bool) (params map[string]string, head } return } + +func (input SetDirAccesslabelInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) { + params = map[string]string{string(SubResourceAccesslabel): ""} + + accesslabelJson, err := TransToJSON(input.Accesslabel) + if err != nil { + return + } + json := make([]string, 0, 2) + json = append(json, fmt.Sprintf("{\"accesslabel\": %s}", accesslabelJson)) + data = strings.Join(json, "") + + return +} + +func (input GetDirAccesslabelInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) { + params = map[string]string{string(SubResourceAccesslabel): ""} + return +} + +func (input DeleteDirAccesslabelInput) trans(isObs bool) (params map[string]string, headers map[string][]string, data interface{}, err error) { + params = map[string]string{string(SubResourceAccesslabel): ""} + return +} diff --git a/obs/trait_part.go b/obs/trait_part.go index 3f60f99..0769768 100644 --- a/obs/trait_part.go +++ b/obs/trait_part.go @@ -52,6 +52,21 @@ func (input InitiateMultipartUploadInput) trans(isObs bool) (params map[string]s if input.ContentType != "" { headers[HEADER_CONTENT_TYPE_CAML] = []string{input.ContentType} } + if input.ContentEncoding != "" { + headers[HEADER_CONTENT_ENCODING_CAMEL] = []string{input.ContentEncoding} + } + if input.CacheControl != "" { + headers[HEADER_CACHE_CONTROL_CAMEL] = []string{input.CacheControl} + } + if input.ContentDisposition != "" { + headers[HEADER_CONTENT_DISPOSITION_CAMEL] = []string{input.ContentDisposition} + } + if input.ContentLanguage != "" { + headers[HEADER_CONTENT_LANGUAGE_CAMEL] = []string{input.ContentLanguage} + } + if input.HttpExpires != "" { + headers[HEADER_EXPIRES_CAMEL] = []string{input.HttpExpires} + } params[string(SubResourceUploads)] = "" if input.EncodingType != "" { params["encoding-type"] = input.EncodingType diff --git a/obs/transfer.go b/obs/transfer.go index d1a783c..a1067e7 100644 --- a/obs/transfer.go +++ b/obs/transfer.go @@ -140,7 +140,7 @@ func updateCheckpointFile(fc interface{}, checkpointFilePath string) error { if err != nil { return err } - err = ioutil.WriteFile(checkpointFilePath, result, 0666) + err = ioutil.WriteFile(checkpointFilePath, result, 0640) return err } @@ -634,7 +634,7 @@ func sliceObject(objectSize, partSize int64, dfc *DownloadCheckpoint) { } func createFile(tempFileURL string, fileSize int64) error { - fd, err := syscall.Open(tempFileURL, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) + fd, err := syscall.Open(tempFileURL, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640) if err != nil { doLog(LEVEL_WARN, "Failed to open temp download file [%s].", tempFileURL) return err @@ -671,7 +671,7 @@ func prepareTempFile(tempFileURL string, fileSize int64) error { if err == nil { return nil } - fd, err := os.OpenFile(tempFileURL, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) + fd, err := os.OpenFile(tempFileURL, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640) if err != nil { doLog(LEVEL_ERROR, "Failed to open temp download file [%s].", tempFileURL) return err @@ -780,7 +780,7 @@ func (obsClient ObsClient) resumeDownload(input *DownloadFileInput, extensions [ } func updateDownloadFile(filePath string, rangeStart int64, output *GetObjectOutput) error { - fd, err := os.OpenFile(filePath, os.O_WRONLY, 0666) + fd, err := os.OpenFile(filePath, os.O_WRONLY, 0640) if err != nil { doLog(LEVEL_ERROR, "Failed to open file [%s].", filePath) return err diff --git a/obs/type.go b/obs/type.go index 12273ad..0048c42 100644 --- a/obs/type.go +++ b/obs/type.go @@ -117,6 +117,9 @@ const ( // SubResourceMirrorBackToSource subResource value: mirrorBackToSource SubResourceMirrorBackToSource SubResourceType = "mirrorBackToSource" + + // SubResourceMirrorBackToSource subResource value: mirrorBackToSource + SubResourceAccesslabel SubResourceType = "x-obs-accesslabel" ) // objectKeyType defines the objectKey value diff --git a/obs/util.go b/obs/util.go index f9df54f..efbb51b 100644 --- a/obs/util.go +++ b/obs/util.go @@ -122,9 +122,9 @@ func FormatUtcNow(format string) string { return time.Now().UTC().Format(format) } -// FormatNow gets a textual representation of the format time value -func FormatNow(format string) string { - return time.Now().Format(format) +// FormatNowWithLoc gets a textual representation of the format time value with loc +func FormatNowWithLoc(format string, loc *time.Location) string { + return time.Now().In(loc).Format(format) } // FormatUtcToRfc1123 gets a textual representation of the RFC1123 format time value @@ -217,6 +217,14 @@ func TransToXml(value interface{}) ([]byte, error) { return xml.Marshal(value) } +// TransToJSON wrapper of json.Marshal +func TransToJSON(value interface{}) ([]byte, error) { + if value == nil { + return []byte{}, nil + } + return json.Marshal(value) +} + // Hex wrapper of hex.EncodeToString func Hex(value []byte) string { return hex.EncodeToString(value)