Skip to content

Commit

Permalink
update 3.23.9
Browse files Browse the repository at this point in the history
  • Loading branch information
noaccident committed Sep 27, 2023
1 parent bc6f9dc commit 7c22360
Show file tree
Hide file tree
Showing 30 changed files with 827 additions and 175 deletions.
42 changes: 39 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
Version 3.21.12
Version 3.23.9

New Features:
1. Added the `obs.WithTrafficLimitHeader` method to limit the bandwidth of a single connection.
1. Added the obs.WithProgress method to support progress bar callback.
2. Added fragment expiration time in configuration life cycle management rules.

Documentation & Demo:
1. Added descriptions about single-connection bandwidth throttling.

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

Version 3.23.4

New Features:
1. Added the obs.WithCustomHeader method when upload.
2. Added bucket customDomain-related APIs, including SetBucketCustomDomain, GetBucketCustomDomain, and DeleteBucketCustomDomain.
3. Added bucket mirrorBackToSource-related APIs, including SetBucketMirrorBackToSource, GetBucketMirrorBackToSource, and DeleteBucketMirrorBackToSource.

Documentation & Demo:
1. Added descriptions about bucket customDomain APIs.
2. Added descriptions about bucket mirrorBackToSource APIs.

-----------------------------------------------------------------------------------
Version 3.23.3

New Features:
1. Added the obs.WithCallbackHeader method when upload.

Documentation & Demo:
1. Added descriptions about callback when upload.
2. Added descriptions about extended configurations of SDK APIs.

Resolved Issues:
1. Optimized some code.

-----------------------------------------------------------------------------------
Version 3.21.12

New Features:
1. Added obs.WithTrafficLimitHeader method to realize single-connection bandwidth throttling.

Documentation & Demo:
1. Added descriptions about single-connection bandwidth throttling.
2. Added descriptions about the SDK interface extension configuration.

Resolved Issues:
1. Optimized part of the code.

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

Version 3.21.8

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

新特性:
1. 新增obs.WithProgress方法支持进度条回调。
2. 新增配置生命周期管理规则中的碎片过期时间。

资料&demo:

-----------------------------------------------------------------------------------
Version 3.23.4

新特性:
1. 新增obs.WithCustomHeader方法。
2. 新增自定义域名相关API,包括SetBucketCustomDomain,GetBucketCustomDomain,DeleteBucketCustomDomain。
3. 新增镜像回源相关API,包括SetBucketMirrorBackToSource、GetBucketMirrorBackToSource、DeleteBucketMirrorBackToSource。

资料&demo:
1. 补充自定义域名相关API的描述。
2. 补充镜像回源相关API的描述。

-----------------------------------------------------------------------------------
Version 3.23.3

新特性:
1. 新增obs.WithCallbackHeader方法;

资料&demo:
1. 补充上传时回调的说明。
2. 补充SDK API扩展配置说明。

修复问题:
1. 优化部分代码实现

-----------------------------------------------------------------------------------
Version 3.21.12

新特性:
Expand Down
136 changes: 129 additions & 7 deletions main/obs_go_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func setBucketCors() {
var corsRules [2]obs.CorsRule
corsRule0 := obs.CorsRule{}
corsRule0.ID = "rule1"
corsRule0.AllowedOrigin = []string{"http://www.a.com", "http://www.b.com"}
corsRule0.AllowedOrigin = []string{"***"}
corsRule0.AllowedMethod = []string{"GET", "PUT", "POST", "HEAD"}
corsRule0.AllowedHeader = []string{"header1", "header2"}
corsRule0.MaxAgeSeconds = 100
Expand All @@ -368,7 +368,7 @@ func setBucketCors() {
corsRule1 := obs.CorsRule{}

corsRule1.ID = "rule2"
corsRule1.AllowedOrigin = []string{"http://www.c.com", "http://www.d.com"}
corsRule1.AllowedOrigin = []string{"***"}
corsRule1.AllowedMethod = []string{"GET", "PUT", "POST", "HEAD"}
corsRule1.AllowedHeader = []string{"header3", "header4"}
corsRule1.MaxAgeSeconds = 50
Expand Down Expand Up @@ -580,23 +580,23 @@ func getBucketLoggingConfiguration() {
func setBucketWebsiteConfiguration() {
input := &obs.SetBucketWebsiteConfigurationInput{}
input.Bucket = bucketName
// input.RedirectAllRequestsTo.HostName = "www.a.com"
// input.RedirectAllRequestsTo.HostName = "***"
// input.RedirectAllRequestsTo.Protocol = obs.ProtocolHttp
input.IndexDocument.Suffix = "suffix"
input.ErrorDocument.Key = "key"

var routingRules [2]obs.RoutingRule
routingRule0 := obs.RoutingRule{}

routingRule0.Redirect.HostName = "www.a.com"
routingRule0.Redirect.HostName = "***"
routingRule0.Redirect.Protocol = obs.ProtocolHttp
routingRule0.Redirect.ReplaceKeyPrefixWith = "prefix"
routingRule0.Redirect.HttpRedirectCode = "304"
routingRules[0] = routingRule0

routingRule1 := obs.RoutingRule{}

routingRule1.Redirect.HostName = "www.b.com"
routingRule1.Redirect.HostName = "***"
routingRule1.Redirect.Protocol = obs.ProtocolHttps
routingRule1.Redirect.ReplaceKeyWith = "replaceKey"
routingRule1.Redirect.HttpRedirectCode = "304"
Expand Down Expand Up @@ -822,7 +822,7 @@ func deleteBucketMirrorBackToSource() {
func setBucketCustomDomain() {
input := &obs.SetBucketCustomDomainInput{}
input.Bucket = bucketName
input.CustomDomain = "www.example.com"
input.CustomDomain = "***"

output, err := getObsClient().SetBucketCustomDomain(input)
if err == nil {
Expand Down Expand Up @@ -860,7 +860,7 @@ func getBucketCustomDomain() {
func deleteBucketCustomdomain() {
input := &obs.DeleteBucketCustomDomainInput{}
input.Bucket = bucketName
input.CustomDomain = "www.test-go4444.com"
input.CustomDomain = "***"

output, err := getObsClient().DeleteBucketCustomDomain(input)
if err == nil {
Expand Down Expand Up @@ -1602,6 +1602,126 @@ func renameFolder() {

}

// 定义进度条监听器。
type ObsProgressListener struct {
}

// 定义进度变更事件处理函数。
func (listener *ObsProgressListener) ProgressChanged(event *obs.ProgressEvent) {
switch event.EventType {
case obs.TransferStartedEvent:
fmt.Printf("Transfer Started, ConsumedBytes: %d, TotalBytes %d.\n",
event.ConsumedBytes, event.TotalBytes)
case obs.TransferDataEvent:
fmt.Printf("\rTransfer Data, ConsumedBytes: %d, TotalBytes %d, %d%%.\n",
event.ConsumedBytes, event.TotalBytes, event.ConsumedBytes*100/event.TotalBytes)
case obs.TransferCompletedEvent:
fmt.Printf("\nTransfer Completed, ConsumedBytes: %d, TotalBytes %d.\n",
event.ConsumedBytes, event.TotalBytes)
case obs.TransferFailedEvent:
fmt.Printf("\nTransfer Failed, ConsumedBytes: %d, TotalBytes %d.\n",
event.ConsumedBytes, event.TotalBytes)
default:
}
}

func getObjectWithProgress() {
input := &obs.GetObjectInput{}
input.Bucket = bucketName
input.Key = objectKey
output, err := getObsClient().GetObject(input, obs.WithProgress(&ObsProgressListener{}))
if err == nil {
defer output.Body.Close()
fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId)
fmt.Printf("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s\n",
output.StorageClass, output.ETag, output.ContentType, output.ContentLength, output.LastModified)
p := make([]byte, 1024)
var readErr error
var readCount int
for {
readCount, readErr = output.Body.Read(p)
if readCount > 0 {
fmt.Printf("%s", p[:readCount])
}
if readErr != nil {
break
}
}
} 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 putObjectWithProgress() {
input := &obs.PutObjectInput{}
input.Bucket = bucketName
input.Key = objectKey
input.Metadata = map[string]string{"meta": "value"}
input.Body = strings.NewReader("Hello OBS")
output, err := getObsClient().PutObject(input, obs.WithProgress(&ObsProgressListener{}))
if err == nil {
fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId)
fmt.Printf("ETag:%s, StorageClass:%s\n", output.ETag, output.StorageClass)
} 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 putFileWithProgress() {
input := &obs.PutFileInput{}
input.Bucket = bucketName
input.Key = objectKey
input.SourceFile = "localfile"
output, err := getObsClient().PutFile(input, obs.WithProgress(&ObsProgressListener{}))
if err == nil {
fmt.Printf("StatusCode:%d, RequestId:%s\n", output.StatusCode, output.RequestId)
fmt.Printf("ETag:%s, StorageClass:%s\n", output.ETag, output.StorageClass)
} 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 appendObjectWithProgress() {
input := &obs.AppendObjectInput{}
input.Bucket = bucketName
input.Key = objectKey
input.Position = 9
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)
return
}
fmt.Printf("Append objects under the bucket(%s) fail!\n", input.Bucket)
if obsError, ok := err.(obs.ObsError); ok {
fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.")
fmt.Println(obsError.Error())
} else {
fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.")
fmt.Println(err)
}

}

func runExamples() {
examples.RunBucketOperationsSample()
// examples.RunObjectOperationsSample()
Expand Down Expand Up @@ -1696,9 +1816,11 @@ func main() {
// completeMultipartUpload()
// abortMultipartUpload()
// putObject()
// putObjectWithProgress()
// putFile()
// getObjectMetadata()
// getObject()
// getObjectWithProgress()
// putObjectWithCallback()
// deleteBucket()
}
33 changes: 30 additions & 3 deletions obs/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ import (
"time"
)

func (obsClient ObsClient) doAuthTemporary(method, bucketName, objectKey string, params map[string]string,
func setURLWithPolicy(bucketName, canonicalizedUrl string) string {
if strings.HasPrefix(canonicalizedUrl, "/"+bucketName+"/") {
canonicalizedUrl = canonicalizedUrl[len("/"+bucketName+"/"):]
} else if strings.HasPrefix(canonicalizedUrl, "/"+bucketName) {
canonicalizedUrl = canonicalizedUrl[len("/"+bucketName):]
}
return canonicalizedUrl
}

func (obsClient ObsClient) doAuthTemporary(method, bucketName, objectKey string, policy string, params map[string]string,
headers map[string][]string, expires int64) (requestURL string, err error) {
sh := obsClient.getSecurity()
isAkSkEmpty := sh.ak == "" || sh.sk == ""
Expand All @@ -31,6 +40,11 @@ func (obsClient ObsClient) doAuthTemporary(method, bucketName, objectKey string,
params[HEADER_STS_TOKEN_AMZ] = sh.securityToken
}
}

if policy != "" {
objectKey = ""
}

requestURL, canonicalizedURL := obsClient.conf.formatUrls(bucketName, objectKey, params, true)
parsedRequestURL, err := url.Parse(requestURL)
if err != nil {
Expand Down Expand Up @@ -93,7 +107,13 @@ func (obsClient ObsClient) doAuthTemporary(method, bucketName, objectKey string,
return "", parseDateErr
}
expires += date.Unix()
headers[HEADER_DATE_CAMEL] = []string{Int64ToString(expires)}
if policy == "" {
headers[HEADER_DATE_CAMEL] = []string{Int64ToString(expires)}
} else {
policy = Base64Encode([]byte(policy))
headers[HEADER_DATE_CAMEL] = []string{policy}
canonicalizedURL = setURLWithPolicy(bucketName, canonicalizedURL)
}

stringToSign := getV2StringToSign(method, canonicalizedURL, headers, obsClient.conf.signature == SignatureObs)
signature := UrlEncode(Base64Encode(HmacSha1([]byte(sh.sk), []byte(stringToSign))), false)
Expand All @@ -107,7 +127,14 @@ func (obsClient ObsClient) doAuthTemporary(method, bucketName, objectKey string,
if obsClient.conf.signature != SignatureObs {
requestURL += "AWS"
}
requestURL += fmt.Sprintf("AccessKeyId=%s&Expires=%d&Signature=%s", UrlEncode(sh.ak, false), expires, signature)
if policy == "" {
requestURL += fmt.Sprintf("AccessKeyId=%s&Expires=%d&Signature=%s", UrlEncode(sh.ak, false),
expires, signature)
return

}
requestURL += fmt.Sprintf("AccessKeyId=%s&Policy=%s&Signature=%s", UrlEncode(sh.ak, false),
UrlEncode(policy, false), signature)
}
}

Expand Down
1 change: 0 additions & 1 deletion obs/authV4.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func getV4StringToSign(method, canonicalizedURL, queryURL, scope, longDate, payl

_stringToSign := strings.Join(stringToSign, "")

doLog(LEVEL_DEBUG, "The v4 auth stringToSign:\n%s", _stringToSign)
return _stringToSign
}

Expand Down
1 change: 0 additions & 1 deletion obs/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

//nolint:structcheck, unused
package obs

import (
Expand Down
Loading

0 comments on commit 7c22360

Please sign in to comment.