Skip to content

Commit f4d20ac

Browse files
authored
Merge pull request #229 from tencentyun/feature_jojoliang_662e1318
update bucket cors, add x-cos-tagging in putbucket, update Presignurl
2 parents 191cedc + 35b83ed commit f4d20ac

File tree

4 files changed

+75
-27
lines changed

4 files changed

+75
-27
lines changed

bucket.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type BucketPutOptions struct {
5959
XCosGrantFullControl string `header:"x-cos-grant-full-control,omitempty" url:"-" xml:"-"`
6060
XCosGrantReadACP string `header:"x-cos-grant-read-acp,omitempty" url:"-" xml:"-"`
6161
XCosGrantWriteACP string `header:"x-cos-grant-write-acp,omitempty" url:"-" xml:"-"`
62+
XCosTagging string `header:"x-cos-tagging,omitempty" url:"-" xml:"-"`
63+
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
6264
CreateBucketConfiguration *CreateBucketConfiguration `header:"-" url:"-" xml:"-"`
6365
}
6466
type CreateBucketConfiguration struct {

bucket_cors.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type BucketCORSRule struct {
1818

1919
// BucketGetCORSResult is the result of GetBucketCORS
2020
type BucketGetCORSResult struct {
21-
XMLName xml.Name `xml:"CORSConfiguration"`
22-
Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
21+
XMLName xml.Name `xml:"CORSConfiguration"`
22+
Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
23+
ResponseVary string `xml:"ResponseVary,omitempty"`
2324
}
2425

2526
// GetCORS 实现 Bucket 跨域访问配置读取。
@@ -39,8 +40,9 @@ func (s *BucketService) GetCORS(ctx context.Context) (*BucketGetCORSResult, *Res
3940

4041
// BucketPutCORSOptions is the option of PutBucketCORS
4142
type BucketPutCORSOptions struct {
42-
XMLName xml.Name `xml:"CORSConfiguration"`
43-
Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
43+
XMLName xml.Name `xml:"CORSConfiguration"`
44+
Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
45+
ResponseVary string `xml:"ResponseVary,omitempty"`
4446
}
4547

4648
// PutCORS 实现 Bucket 跨域访问设置,您可以通过传入XML格式的配置文件实现配置,文件大小限制为64 KB。

object.go

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type PresignedURLOptions struct {
118118
Query *url.Values `xml:"-" url:"-" header:"-"`
119119
Header *http.Header `header:"-,omitempty" url:"-" xml:"-"`
120120
SignMerged bool `xml:"-" url:"-" header:"-"`
121+
AuthTime *AuthTime `xml:"-" url:"-" header:"-"`
121122
}
122123

123124
// GetPresignedURL get the object presigned to down or upload file by url
@@ -137,11 +138,20 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
137138
optQuery: opt,
138139
optHeader: opt,
139140
}
140-
if popt, ok := opt.(*PresignedURLOptions); ok {
141-
if popt != nil && popt.Query != nil {
142-
qs := popt.Query.Encode()
143-
if qs != "" {
144-
sendOpt.uri = fmt.Sprintf("%s?%s", sendOpt.uri, qs)
141+
var authTime *AuthTime
142+
if opt != nil {
143+
if opt, ok := opt.(*presignedURLTestingOptions); ok {
144+
authTime = opt.authTime
145+
}
146+
if popt, ok := opt.(*PresignedURLOptions); ok {
147+
if popt.Query != nil {
148+
qs := popt.Query.Encode()
149+
if qs != "" {
150+
sendOpt.uri = fmt.Sprintf("%s?%s", sendOpt.uri, qs)
151+
}
152+
}
153+
if popt.AuthTime != nil {
154+
authTime = popt.AuthTime
145155
}
146156
}
147157
}
@@ -150,12 +160,6 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
150160
return nil, err
151161
}
152162

153-
var authTime *AuthTime
154-
if opt != nil {
155-
if opt, ok := opt.(*presignedURLTestingOptions); ok {
156-
authTime = opt.authTime
157-
}
158-
}
159163
if authTime == nil {
160164
authTime = NewAuthTime(expired)
161165
}
@@ -206,13 +210,22 @@ func (s *ObjectService) GetPresignedURL2(ctx context.Context, httpMethod, name s
206210
optQuery: opt,
207211
optHeader: opt,
208212
}
213+
var authTime *AuthTime
209214
mark := "?"
210-
if popt, ok := opt.(*PresignedURLOptions); ok {
211-
if popt != nil && popt.Query != nil {
212-
qs := popt.Query.Encode()
213-
if qs != "" {
214-
sendOpt.uri = fmt.Sprintf("%s?%s", sendOpt.uri, qs)
215-
mark = "&"
215+
if opt != nil {
216+
if opt, ok := opt.(*presignedURLTestingOptions); ok {
217+
authTime = opt.authTime
218+
}
219+
if popt, ok := opt.(*PresignedURLOptions); ok {
220+
if popt.Query != nil {
221+
qs := popt.Query.Encode()
222+
if qs != "" {
223+
sendOpt.uri = fmt.Sprintf("%s?%s", sendOpt.uri, qs)
224+
mark = "&"
225+
}
226+
}
227+
if popt.AuthTime != nil {
228+
authTime = popt.AuthTime
216229
}
217230
}
218231
}
@@ -225,12 +238,6 @@ func (s *ObjectService) GetPresignedURL2(ctx context.Context, httpMethod, name s
225238
return nil, err
226239
}
227240

228-
var authTime *AuthTime
229-
if opt != nil {
230-
if opt, ok := opt.(*presignedURLTestingOptions); ok {
231-
authTime = opt.authTime
232-
}
233-
}
234241
if authTime == nil {
235242
authTime = NewAuthTime(expired)
236243
}

object_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,43 @@ func TestObjectService_GetPresignedURL(t *testing.T) {
215215
}
216216
}
217217

218+
func TestObjectService_GetPresignedURL_AuthTime(t *testing.T) {
219+
setup()
220+
defer teardown()
221+
222+
exceptSign := "q-sign-algorithm=sha1&q-ak=QmFzZTY0IGlzIGEgZ*******&q-sign-time=1622702557;1622706157&q-key-time=1622702557;1622706157&q-header-list=&q-url-param-list=&q-signature=0f359fe9d29e7fa0c738ce6c8feaf4ed1e84f287"
223+
exceptURL := &url.URL{
224+
Scheme: "http",
225+
Host: client.Host,
226+
Path: "/test.jpg",
227+
RawQuery: exceptSign,
228+
}
229+
230+
c := context.Background()
231+
name := "test.jpg"
232+
ak := "QmFzZTY0IGlzIGEgZ*******"
233+
sk := "ZfbOA78asKUYBcXFrJD0a1I*******"
234+
startTime := time.Unix(int64(1622702557), 0)
235+
endTime := time.Unix(int64(1622706157), 0)
236+
opt := &PresignedURLOptions{
237+
AuthTime: &AuthTime{
238+
SignStartTime: startTime,
239+
SignEndTime: endTime,
240+
KeyStartTime: startTime,
241+
KeyEndTime: endTime,
242+
},
243+
}
244+
245+
presignedURL, err := client.Object.GetPresignedURL(c, http.MethodPut, name, ak, sk, time.Hour, opt)
246+
if err != nil {
247+
t.Fatal(err)
248+
}
249+
250+
if reflect.DeepEqual(exceptURL, presignedURL) {
251+
t.Fatalf("Wrong PreSignedURL!")
252+
}
253+
}
254+
218255
func TestObjectService_GetPresignedURL2(t *testing.T) {
219256
setup()
220257
defer teardown()

0 commit comments

Comments
 (0)