Skip to content

Commit

Permalink
update 3.24.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtingwei998 committed Apr 28, 2024
1 parent ecf74b3 commit fed907b
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 79 deletions.
12 changes: 12 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 12 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Version 3.24.3

新特性:
1. 新增accesslabel相关接口:设置对象accesslabel(SetDirAccesslabel), 获取对象accesslabel(GetDirAccesslabel), 删除对象accesslabel(DeleteDirAccesslabel);

资料&demo:
1. 补充accesslabel相关接口描述;

修复问题:

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

Version 3.23.12

新特性:
Expand Down
64 changes: 61 additions & 3 deletions main/obs_go_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -1823,4 +1878,7 @@ func main() {
// getObjectWithProgress()
// putObjectWithCallback()
// deleteBucket()
// setDirAccesslabel()
// getDirAccesslabel()
// deleteDirAccesslabel()
}
8 changes: 4 additions & 4 deletions obs/client_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions obs/client_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions obs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ var (
"rename": true,
"customdomain": true,
"mirrorbacktosource": true,
"x-obs-accesslabel": true,
}

obsStorageClasses = []string{
Expand Down
25 changes: 12 additions & 13 deletions obs/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<RestoreRequest><Days>%d</Days>", restoreObjectInput.Days))
if restoreObjectInput.Tier != "Bulk" {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
}
Expand All @@ -902,6 +900,7 @@ func ParseGetObjectOutput(output *GetObjectOutput) {
}
if ret, ok := output.ResponseHeaders[HEADER_EXPIRES]; ok {
output.Expires = ret[0]
output.HttpExpires = ret[0]
}
}

Expand Down
36 changes: 19 additions & 17 deletions obs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"runtime"
"strings"
"sync"
"time"
)

// Level defines the level of the log
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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++

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
33 changes: 29 additions & 4 deletions obs/model_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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"`
}
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit fed907b

Please sign in to comment.