Browse Source

查询对象接口支持预签名

pengcheng
Sydonian 8 months ago
parent
commit
07fa8a6fcd
2 changed files with 35 additions and 0 deletions
  1. +10
    -0
      sdks/storage/cdsapi/presigned.go
  2. +25
    -0
      sdks/storage/cdsapi/presigned_test.go

+ 10
- 0
sdks/storage/cdsapi/presigned.go View File

@@ -23,6 +23,16 @@ func (c *Client) Presigned() *PresignedService {
} }
} }


const PresignedObjectListByPathPath = "/v1/presigned/object/listByPath"

type PresignedObjectListByPath struct {
ObjectListByPath
}

func (c *PresignedService) ObjectListByPath(req PresignedObjectListByPath, expireIn int) (string, error) {
return c.presign(req, PresignedObjectListByPathPath, http.MethodGet, expireIn)
}

const PresignedObjectDownloadByPathPath = "/v1/presigned/object/downloadByPath" const PresignedObjectDownloadByPathPath = "/v1/presigned/object/downloadByPath"


type PresignedObjectDownloadByPath struct { type PresignedObjectDownloadByPath struct {


+ 25
- 0
sdks/storage/cdsapi/presigned_test.go View File

@@ -39,6 +39,31 @@ func Test_Presigned(t *testing.T) {
}) })
} }


func Test_PresignedObjectListByPath(t *testing.T) {
cli := NewClient(&Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
})

Convey("下载文件", t, func() {
pre := cli.Presigned()
url, err := pre.ObjectListByPath(PresignedObjectListByPath{
ObjectListByPath: ObjectListByPath{
UserID: 1,
PackageID: 12,
Path: "a/",
IsPrefix: true,
NoRecursive: true,
MaxKeys: 10,
ContinuationToken: "123456",
},
}, 100)
So(err, ShouldEqual, nil)
t.Logf("url: %s", url)
})
}

func Test_PresignedObjectDownloadByPath(t *testing.T) { func Test_PresignedObjectDownloadByPath(t *testing.T) {
cli := NewClient(&Config{ cli := NewClient(&Config{
URL: "http://localhost:7890", URL: "http://localhost:7890",


Loading…
Cancel
Save