Skip to content

Commit dbcafb4

Browse files
committed
feat: cos - support verbose acl, origin-pull and domain rules
1 parent 1f25f4d commit dbcafb4

33 files changed

+1354
-149
lines changed

examples/tencentcloud-cos/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ data "tencentcloud_cos_buckets" "data_bucket" {
5858
resource "tencentcloud_cos_bucket_policy" "cos_policy" {
5959
bucket = "mycos-1258798060"
6060
policy = var.policy
61+
}
62+
63+
resource "tencentcloud_cos_buckets" "verbose_acl_bucket" {
64+
bucket_prefix = "mycos-1258798060"
65+
acl_body = var.acl_body
6166
}

examples/tencentcloud-cos/variables.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@ variable "policy" {
3737
]
3838
}
3939
EOF
40+
}
41+
42+
variable "acl_body" {
43+
default = <<EOF
44+
<AccessControlPolicy>
45+
<Owner>
46+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
47+
</Owner>
48+
<AccessControlList>
49+
<Grant>
50+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
51+
<URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
52+
</Grantee>
53+
<Permission>READ</Permission>
54+
</Grant>
55+
<Grant>
56+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
57+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
58+
</Grantee>
59+
<Permission>WRITE</Permission>
60+
</Grant>
61+
<Grant>
62+
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
63+
<ID>qcs::cam::uin/100000000001:uin/100000000001</ID>
64+
</Grantee>
65+
<Permission>READ_ACP</Permission>
66+
</Grant>
67+
</AccessControlList>
68+
</AccessControlPolicy>
69+
EOF
4070
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.199
5353
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
54-
github.com/tencentyun/cos-go-sdk-v5 v0.7.29
54+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b
5555
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
5656
github.com/zclconf/go-cty v1.4.2 // indirect
5757
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJ
523523
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199/go.mod h1:nnY91/H3j/Gu7V/oCA6Zeg8T5D3q36EUdBh4EjmHwqY=
524524
github.com/tencentyun/cos-go-sdk-v5 v0.7.29 h1:uwRBzc70Wgtc5iQQCowqecfRT0OpCXUOZzodZHOOEDs=
525525
github.com/tencentyun/cos-go-sdk-v5 v0.7.29/go.mod h1:4E4+bQ2gBVJcgEC9Cufwylio4mXOct2iu05WjgEBx1o=
526+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b h1:rLl5sAeLt382023Kd3X4TaOEaT2hdgXWwTGyKiy16Zo=
527+
github.com/tencentyun/cos-go-sdk-v5 v0.7.31-0.20210902132439-360bc9b1be6b/go.mod h1:4E4+bQ2gBVJcgEC9Cufwylio4mXOct2iu05WjgEBx1o=
526528
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
527529
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
528530
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/connectivity/client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"github.com/tencentyun/cos-go-sdk-v5"
66
"net/http"
7+
"net/url"
8+
"time"
79

810
"github.com/aws/aws-sdk-go/aws"
911
"github.com/aws/aws-sdk-go/aws/credentials"
@@ -136,12 +138,18 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
136138
}
137139

138140
// UseTencentCosClient tencent cloud own client for service instead of aws
139-
func (me *TencentCloudClient) UseTencentCosClient() *cos.Client {
141+
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
140142
if me.tencentCosConn != nil {
141143
return me.tencentCosConn
142144
}
143-
me.tencentCosConn = cos.NewClient("", &http.Client{
144-
Timeout: 60,
145+
146+
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
147+
baseUrl := &cos.BaseURL{
148+
BucketURL: u,
149+
}
150+
151+
me.tencentCosConn = cos.NewClient(baseUrl, &http.Client{
152+
Timeout: 100 * time.Second,
145153
Transport: &cos.AuthorizationTransport{
146154
SecretID: me.Credential.SecretId,
147155
SecretKey: me.Credential.SecretKey,

tencentcloud/data_source_tc_cos_buckets.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,97 @@ func dataSourceTencentCloudCosBuckets() *schema.Resource {
168168
},
169169
},
170170
},
171+
"origin_pull_rules": {
172+
Type: schema.TypeList,
173+
Computed: true,
174+
Description: "Bucket Origin-Pull rules.",
175+
Elem: &schema.Resource{
176+
Schema: map[string]*schema.Schema{
177+
"priority": {
178+
Type: schema.TypeInt,
179+
Required: true,
180+
Description: "Priority of origin-pull rules, do not set the same value for multiple rules.",
181+
},
182+
"sync_back_to_source": {
183+
Type: schema.TypeBool,
184+
Optional: true,
185+
Default: false,
186+
Description: "If `true`, COS will not return 3XX status code when pulling data from an origin server. Currently available zone: ap-beijing, ap-shanghai, ap-singapore, ap-mumbai.",
187+
},
188+
"prefix": {
189+
Type: schema.TypeString,
190+
Optional: true,
191+
Default: "",
192+
Description: "Triggers the origin-pull rule when the requested file name matches this prefix.",
193+
},
194+
"protocol": {
195+
Type: schema.TypeString,
196+
Optional: true,
197+
Default: "",
198+
Description: "the protocol used for COS to access the specified origin server. The available value include `HTTP`, `HTTPS` and `FOLLOW`",
199+
},
200+
"host": {
201+
Type: schema.TypeString,
202+
Required: true,
203+
Description: "Allows only a domain name or IP address. You can optionally append a port number to the address.",
204+
},
205+
"follow_query_string": {
206+
Type: schema.TypeBool,
207+
Optional: true,
208+
Default: true,
209+
Description: "Specifies whether to pass through COS request query string when accessing the origin server.",
210+
},
211+
"follow_redirection": {
212+
Type: schema.TypeBool,
213+
Optional: true,
214+
Default: true,
215+
Description: "Specifies whether to follow 3XX redirect to another origin server to pull data from",
216+
},
217+
//"copy_origin_data": {
218+
// Type: schema.TypeBool,
219+
// Optional: true,
220+
// Default: true,
221+
// Description: "",
222+
//},
223+
"follow_http_headers": {
224+
Type: schema.TypeList,
225+
Optional: true,
226+
Description: "Specifies the pass through headers when accessing the origin server.",
227+
Elem: &schema.Schema{Type: schema.TypeString},
228+
},
229+
"custom_http_headers": {
230+
Type: schema.TypeMap,
231+
Optional: true,
232+
Description: "Specifies the custom headers that you can add for COS to access your origin server.",
233+
},
234+
"redirect_prefix": {
235+
Type: schema.TypeString,
236+
Optional: true,
237+
Description: "Prefix for the file to which a request is redirected when the origin-pull rule is triggered.",
238+
},
239+
"redirect_suffix": {
240+
Type: schema.TypeString,
241+
Optional: true,
242+
Description: "Suffix for the file to which a request is redirected when the origin-pull rule is triggered.",
243+
},
244+
},
245+
},
246+
},
247+
"origin_domain_rules": {
248+
Type: schema.TypeList,
249+
Computed: true,
250+
Description: "Bucket origin domain rules.",
251+
Elem: &schema.Resource{
252+
Schema: map[string]*schema.Schema{
253+
254+
},
255+
},
256+
},
257+
"acl_body": {
258+
Type: schema.TypeString,
259+
Computed: true,
260+
Description: "Bucket acl configurations.",
261+
},
171262
"tags": {
172263
Type: schema.TypeMap,
173264
Computed: true,
@@ -211,22 +302,41 @@ LOOP:
211302
}
212303

213304
bucket["bucket"] = *v.Name
305+
214306
corsRules, err := cosService.GetBucketCors(ctx, *v.Name)
215307
if err != nil {
216308
return err
217309
}
218310
bucket["cors_rules"] = corsRules
311+
219312
lifecycleRules, err := cosService.GetDataSourceBucketLifecycle(ctx, *v.Name)
220313
if err != nil {
221314
return err
222315
}
223316
bucket["lifecycle_rules"] = lifecycleRules
317+
224318
website, err := cosService.GetBucketWebsite(ctx, *v.Name)
225319
if err != nil {
226320
return err
227321
}
228322
bucket["website"] = website
229323

324+
originRules, err := cosService.GetBucketPullOrigin(ctx, *v.Name)
325+
if err == nil {
326+
bucket["origin_pull_rules"] = originRules
327+
}
328+
329+
domainRules, err := cosService.GetBucketOriginDomain(ctx, *v.Name)
330+
if err == nil {
331+
bucket["origin_domain_rules"] = domainRules
332+
}
333+
334+
aclBody, err := cosService.GetBucketACLXML(ctx, *v.Name)
335+
if err != nil {
336+
return err
337+
}
338+
bucket["acl_body"] = aclBody
339+
230340
respTags, err := cosService.GetBucketTags(ctx, *v.Name)
231341
if err != nil {
232342
return err

0 commit comments

Comments
 (0)