Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aliyun/aliyun-oss-go-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.9
Choose a base ref
...
head repository: aliyun/aliyun-oss-go-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.2
Choose a head ref
  • 11 commits
  • 30 files changed
  • 4 contributors

Commits on Oct 30, 2023

  1. Copy the full SHA
    cf6ec90 View commit details
  2. fix some bugs (#414)

    yangzong18 authored and huiguangjun committed Oct 30, 2023
    Copy the full SHA
    85d6790 View commit details
  3. refine callback.

    huiguangjun committed Oct 30, 2023
    Copy the full SHA
    50c3b3f View commit details
  4. add repsonse header api (#415)

    yangzong18 authored and huiguangjun committed Oct 30, 2023
    Copy the full SHA
    368023e View commit details
  5. modify bucket cros api (#416)

    yangzong18 authored and huiguangjun committed Oct 30, 2023
    Copy the full SHA
    9b58296 View commit details
  6. update testcase.

    huiguangjun committed Oct 30, 2023
    Copy the full SHA
    535b659 View commit details
  7. fix unit test (#417)

    yangzong18 authored and huiguangjun committed Oct 30, 2023
    Copy the full SHA
    0b1143e View commit details
  8. Copy the full SHA
    8a3825c View commit details
  9. release v2.2.10 (#420)

    huiguangjun authored Oct 30, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2bc5874 View commit details

Commits on Dec 28, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4550a97 View commit details
  2. release v3.0.2

    huiguangjun committed Dec 28, 2023
    Copy the full SHA
    3804c13 View commit details
Showing with 2,504 additions and 150 deletions.
  1. +13 −0 CHANGELOG.md
  2. +1 −1 README-CN.md
  3. +1 −1 README.md
  4. +36 −42 oss/auth.go
  5. +15 −9 oss/bucket.go
  6. +708 −16 oss/bucket_test.go
  7. +102 −0 oss/client.go
  8. +77 −1 oss/client_test.go
  9. +10 −2 oss/conf.go
  10. +83 −28 oss/conn.go
  11. +495 −1 oss/conn_test.go
  12. +7 −4 oss/const.go
  13. +1 −0 oss/crc_test.go
  14. +38 −0 oss/error.go
  15. +9 −3 oss/livechannel_test.go
  16. +31 −16 oss/multipart.go
  17. +70 −0 oss/multipart_test.go
  18. +37 −0 oss/option.go
  19. +1 −0 oss/progress_test.go
  20. +34 −4 oss/type.go
  21. +171 −1 oss/type_test.go
  22. +28 −2 oss/upload.go
  23. +61 −0 oss/upload_test.go
  24. +78 −13 oss/utils.go
  25. +192 −0 oss/utils_test.go
  26. +1 −0 sample.go
  27. +22 −4 sample/bucket_cors.go
  28. +88 −0 sample/bucket_responseheader.go
  29. +2 −2 sample/describe_regions.go
  30. +92 −0 sample/put_object.go
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# ChangeLog - Aliyun OSS SDK for Go

## 版本号:v3.0.2 日期:2023-12-28
### 变更内容
- 增加:presign 支持 oss v4签名规则
- 增加:credentials provider supports GetCredentialsE interface
- 修改:fix GetReaderLen

## 版本号:v2.2.10 日期:2023-10-30
### 变更内容
- 增加:support return callback body.
- 增加:support response header api
- 增加:add region field in listBuckets
- 增加:add ResponseVary field in CORSXML

## 版本号:v2.2.9 日期:2023-08-25
### 变更内容
- 增加:support force path style option.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
> - 使用此SDK,用户可以方便地在任何应用、任何时间、任何地点上传,下载和管理数据。
## 版本
> - Current version: v2.2.9
> - Current version: v3.0.2
## 运行环境
> - Go 1.5及以上。
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
> - With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.
## Version
> - Current version: v2.2.9
> - Current version: v3.0.2
## Running Environment
> - Go 1.5 or above.
78 changes: 36 additions & 42 deletions oss/auth.go
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ func (conn Conn) getAdditionalHeaderKeysV4(req *http.Request) ([]string, map[str
}

// signHeader signs the header and sets it as the authorization header.
func (conn Conn) signHeader(req *http.Request, canonicalizedResource string) {
akIf := conn.config.GetCredentials()
func (conn Conn) signHeader(req *http.Request, canonicalizedResource string, credentials Credentials) {
akIf := credentials
authorizationStr := ""
if conn.config.AuthVersion == AuthV4 {
strDay := ""
@@ -83,21 +83,20 @@ func (conn Conn) signHeader(req *http.Request, canonicalizedResource string) {
t, _ := time.Parse(http.TimeFormat, strDate)
strDay = t.Format("20060102")
} else {
t, _ := time.Parse(iso8601DateFormatSecond, strDate)
t, _ := time.Parse(timeFormatV4, strDate)
strDay = t.Format("20060102")
}

signHeaderProduct := conn.config.GetSignProduct()
signHeaderRegion := conn.config.GetSignRegion()

additionalList, _ := conn.getAdditionalHeaderKeysV4(req)
if len(additionalList) > 0 {
authorizationFmt := "OSS4-HMAC-SHA256 Credential=%v/%v/%v/" + signHeaderProduct + "/aliyun_v4_request,AdditionalHeaders=%v,Signature=%v"
additionnalHeadersStr := strings.Join(additionalList, ";")
authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, additionnalHeadersStr, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret()))
authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, additionnalHeadersStr, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret(), nil))
} else {
authorizationFmt := "OSS4-HMAC-SHA256 Credential=%v/%v/%v/" + signHeaderProduct + "/aliyun_v4_request,Signature=%v"
authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret()))
authorizationStr = fmt.Sprintf(authorizationFmt, akIf.GetAccessKeyID(), strDay, signHeaderRegion, conn.getSignedStrV4(req, canonicalizedResource, akIf.GetAccessKeySecret(), nil))
}
} else if conn.config.AuthVersion == AuthV2 {
additionalList, _ := conn.getAdditionalHeaderKeys(req)
@@ -168,49 +167,44 @@ func (conn Conn) getSignedStr(req *http.Request, canonicalizedResource string, k
return signedStr
}

func (conn Conn) getSignedStrV4(req *http.Request, canonicalizedResource string, keySecret string) string {
func (conn Conn) getSignedStrV4(req *http.Request, canonicalizedResource string, keySecret string, signingTime *time.Time) string {
// Find out the "x-oss-"'s address in header of the request
ossHeadersMap := make(map[string]string)
additionalList, additionalMap := conn.getAdditionalHeaderKeysV4(req)
for k, v := range req.Header {
if strings.HasPrefix(strings.ToLower(k), "x-oss-") {
ossHeadersMap[strings.ToLower(k)] = strings.Trim(v[0], " ")
lowKey := strings.ToLower(k)
if strings.EqualFold(lowKey, HTTPHeaderContentMD5) ||
strings.EqualFold(lowKey, HTTPHeaderContentType) ||
strings.HasPrefix(lowKey, "x-oss-") {
ossHeadersMap[lowKey] = strings.Trim(v[0], " ")
} else {
if _, ok := additionalMap[strings.ToLower(k)]; ok {
ossHeadersMap[strings.ToLower(k)] = strings.Trim(v[0], " ")
if _, ok := additionalMap[lowKey]; ok {
ossHeadersMap[lowKey] = strings.Trim(v[0], " ")
}
}
}

// Required parameters
// get day,eg 20210914
//signingTime
signDate := ""
dateFormat := ""
date := req.Header.Get(HTTPHeaderDate)
if date != "" {
signDate = date
dateFormat = http.TimeFormat
}

ossDate := req.Header.Get(HttpHeaderOssDate)
_, ok := ossHeadersMap[strings.ToLower(HttpHeaderOssDate)]
if ossDate != "" {
signDate = ossDate
dateFormat = iso8601DateFormatSecond
if !ok {
ossHeadersMap[strings.ToLower(HttpHeaderOssDate)] = strings.Trim(ossDate, " ")
strDay := ""
if signingTime != nil {
signDate = signingTime.Format(timeFormatV4)
strDay = signingTime.Format(shortTimeFormatV4)
} else {
var t time.Time
// Required parameters
if date := req.Header.Get(HTTPHeaderDate); date != "" {
signDate = date
t, _ = time.Parse(http.TimeFormat, date)
}
}

contentType := req.Header.Get(HTTPHeaderContentType)
_, ok = ossHeadersMap[strings.ToLower(HTTPHeaderContentType)]
if contentType != "" && !ok {
ossHeadersMap[strings.ToLower(HTTPHeaderContentType)] = strings.Trim(contentType, " ")
}
if ossDate := req.Header.Get(HttpHeaderOssDate); ossDate != "" {
signDate = ossDate
t, _ = time.Parse(timeFormatV4, ossDate)
}

contentMd5 := req.Header.Get(HTTPHeaderContentMD5)
_, ok = ossHeadersMap[strings.ToLower(HTTPHeaderContentMD5)]
if contentMd5 != "" && !ok {
ossHeadersMap[strings.ToLower(HTTPHeaderContentMD5)] = strings.Trim(contentMd5, " ")
strDay = t.Format("20060102")
}

hs := newHeaderSorter(ossHeadersMap)
@@ -227,7 +221,10 @@ func (conn Conn) getSignedStrV4(req *http.Request, canonicalizedResource string,
signStr := ""

// v4 signature
hashedPayload := req.Header.Get(HttpHeaderOssContentSha256)
hashedPayload := DefaultContentSha256
if val := req.Header.Get(HttpHeaderOssContentSha256); val != "" {
hashedPayload = val
}

// subResource
resource := canonicalizedResource
@@ -245,13 +242,10 @@ func (conn Conn) getSignedStrV4(req *http.Request, canonicalizedResource string,
hashedRequest := hex.EncodeToString(rh.Sum(nil))

if conn.config.LogLevel >= Debug {
conn.config.WriteLog(Debug, "[Req:%p]signStr:%s\n", req, EscapeLFString(canonicalReuqest))
conn.config.WriteLog(Debug, "[Req:%p]CanonicalRequest:%s\n", req, EscapeLFString(canonicalReuqest))
}

// get day,eg 20210914
t, _ := time.Parse(dateFormat, signDate)
strDay := t.Format("20060102")

// Product & Region
signedStrV4Product := conn.config.GetSignProduct()
signedStrV4Region := conn.config.GetSignRegion()

24 changes: 15 additions & 9 deletions oss/bucket.go
Original file line number Diff line number Diff line change
@@ -100,16 +100,26 @@ func (bucket Bucket) DoPutObject(request *PutObjectRequest, options []Option) (*
if err != nil {
return nil, err
}

if bucket.GetConfig().IsEnableCRC {
err = CheckCRC(resp, "DoPutObject")
if err != nil {
return resp, err
}
}

err = CheckRespCode(resp.StatusCode, []int{http.StatusOK})

body, _ := ioutil.ReadAll(resp.Body)
if len(body) > 0 {
if err != nil {
err = tryConvertServiceError(body, resp, err)
} else {
rb, _ := FindOption(options, responseBody, nil)
if rb != nil {
if rbody, ok := rb.(*[]byte); ok {
*rbody = body
}
}
}
}
return resp, err
}

@@ -882,7 +892,7 @@ func (bucket Bucket) RestoreObjectXML(objectKey, configXML string, options ...Op
// string returns the signed URL, when error is nil.
// error it's nil if no error, otherwise it's an error object.
func (bucket Bucket) SignURL(objectKey string, method HTTPMethod, expiredInSec int64, options ...Option) (string, error) {
err := CheckObjectName(objectKey)
err := CheckObjectNameEx(objectKey, isVerifyObjectStrict(bucket.GetConfig()))
if err != nil {
return "", err
}
@@ -903,7 +913,7 @@ func (bucket Bucket) SignURL(objectKey string, method HTTPMethod, expiredInSec i
return "", err
}

return bucket.Client.Conn.signURL(method, bucket.BucketName, objectKey, expiration, params, headers), nil
return bucket.Client.Conn.signURL(method, bucket.BucketName, objectKey, expiration, params, headers)
}

// PutObjectWithURL uploads an object with the URL. If the object exists, it will be overwritten.
@@ -1109,18 +1119,15 @@ func (bucket Bucket) ProcessObject(objectKey string, process string, options ...
return out, err
}

//
// AsyncProcessObject apply async process on the specified image file.
//
// The supported process includes resize, rotate, crop, watermark, format,
// udf, customized style, etc.
//
//
// objectKey object key to process.
// asyncProcess process string, such as "image/resize,w_100|sys/saveas,o_dGVzdC5qcGc,b_dGVzdA"
//
// error it's nil if no error, otherwise it's an error object.
//
func (bucket Bucket) AsyncProcessObject(objectKey string, asyncProcess string, options ...Option) (AsyncProcessObjectResult, error) {
var out AsyncProcessObjectResult
params, _ := GetRawParams(options)
@@ -1138,7 +1145,6 @@ func (bucket Bucket) AsyncProcessObject(objectKey string, asyncProcess string, o
return out, err
}

//
// PutObjectTagging add tagging to object
//
// objectKey object key to add tagging
Loading