Skip to content

Commit

Permalink
Merge pull request #78 from aliyun/fix-sign-url
Browse files Browse the repository at this point in the history
Fix sign url
  • Loading branch information
baiyubin2020 authored Dec 13, 2017
2 parents 4710427 + 4f93522 commit 52de723
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog - Aliyun OSS SDK for Go

## 版本号:1.8.0 日期:2017-12-12
### 变更内容
- 变更:空闲链接关闭时间调整为50秒
- 修复:修复临时账号使用SignURL的问题

## 版本号:1.7.0 日期:2017-09-25
### 变更内容
- 增加:DownloadFile支持CRC校验
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
> - 使用此SDK,用户可以方便地在任何应用、任何时间、任何地点上传,下载和管理数据。
## 版本
> - 当前版本:1.7.0
> - 当前版本:1.8.0
## 运行环境
> - Go 1.5及以上。
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
> - With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.
## Version
> - Current version: 1.7.0.
> - Current version: 1.8.0.
## Running Environment
> - Go 1.5 or above.
Expand Down
19 changes: 18 additions & 1 deletion oss/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ func (s *OssBucketSuite) TestSTSToken(c *C) {
c.Assert(err, IsNil)

// Get
body, err := s.bucket.GetObject(objectName)
body, err := bucket.GetObject(objectName)
c.Assert(err, IsNil)
str, err := readBody(body)
c.Assert(err, IsNil)
Expand All @@ -1805,6 +1805,23 @@ func (s *OssBucketSuite) TestSTSToken(c *C) {
c.Assert(err, IsNil)
testLogger.Println("Objects:", lor.Objects)

// Put with url
signedURL, err := bucket.SignURL(objectName, HTTPPut, 3600)
c.Assert(err, IsNil)

err = bucket.PutObjectWithURL(signedURL, strings.NewReader(objectValue))
c.Assert(err, IsNil)

// Get with url
signedURL, err = bucket.SignURL(objectName, HTTPGet, 3600)
c.Assert(err, IsNil)

body, err = bucket.GetObjectWithURL(signedURL)
c.Assert(err, IsNil)
str, err = readBody(body)
c.Assert(err, IsNil)
c.Assert(str, Equals, objectValue)

// Delete
err = bucket.DeleteObject(objectName)
c.Assert(err, IsNil)
Expand Down
8 changes: 4 additions & 4 deletions oss/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ var (

const (
// prefix of bucket name for bucket ops test
bucketNamePrefix = "go-sdk-test-bucket-xyzuv-"
bucketNamePrefix = "go-sdk-test-bucket-xyz-"
// bucket name for object ops test
bucketName = "go-sdk-test-bucket-xyzuv-for-object"
archiveBucketName = "go-sdk-test-bucket-xyzuv-for-archive"
bucketName = "go-sdk-test-bucket-xyz-for-object"
archiveBucketName = "go-sdk-test-bucket-xyz-for-archive"
// object name for object ops test
objectNamePrefix = "go-sdk-test-object-xyzuv-"
objectNamePrefix = "go-sdk-test-object-xyz-"
// sts region is one and only hangzhou
stsRegion = "cn-hangzhou"
)
Expand Down
6 changes: 3 additions & 3 deletions oss/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ func (conn Conn) doRequest(method string, uri *url.URL, canonicalizedResource st
}

func (conn Conn) signURL(method HTTPMethod, bucketName, objectName string, expiration int64, params map[string]interface{}, headers map[string]string) string {
if conn.config.SecurityToken != "" {
params[HTTPParamSecurityToken] = conn.config.SecurityToken
}
subResource := conn.getSubResource(params)
canonicalizedResource := conn.url.getResource(bucketName, objectName, subResource)

Expand Down Expand Up @@ -273,9 +276,6 @@ func (conn Conn) signURL(method HTTPMethod, bucketName, objectName string, expir
params[HTTPParamExpires] = strconv.FormatInt(expiration, 10)
params[HTTPParamAccessKeyID] = conn.config.AccessKeyID
params[HTTPParamSignature] = signedStr
if conn.config.SecurityToken != "" {
params[HTTPParamSecurityToken] = conn.config.SecurityToken
}

urlParams := conn.getURLParams(params)
return conn.url.getSignURL(bucketName, objectName, urlParams)
Expand Down

0 comments on commit 52de723

Please sign in to comment.