Skip to content

Commit a4b34c3

Browse files
committed
fix: support cos cdc
1 parent 3f38027 commit a4b34c3

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

tencentcloud/connectivity/client.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type TencentCloudClient struct {
118118
Region string
119119
Protocol string
120120
Domain string
121+
CosDomain string
121122

122123
cosConn *s3.S3
123124
tencentCosConn *cos.Client
@@ -266,8 +267,12 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
266267

267268
resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
268269
if service == endpoints.S3ServiceID {
270+
cosUrl := fmt.Sprintf("https://cos.%s.myqcloud.com", region)
271+
if me.CosDomain != "" {
272+
cosUrl = me.CosDomain
273+
}
269274
return endpoints.ResolvedEndpoint{
270-
URL: fmt.Sprintf("https://cos.%s.myqcloud.com", region),
275+
URL: cosUrl,
271276
SigningRegion: region,
272277
}, nil
273278
}
@@ -317,7 +322,14 @@ func (me *TencentCloudClient) UseTencentCosClientNew(bucket string, cdcId ...str
317322

318323
// UseTencentCosClient tencent cloud own client for service instead of aws
319324
func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
320-
u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region))
325+
cosUrl := fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, me.Region)
326+
if me.CosDomain != "" {
327+
parsedURL, _ := url.Parse(me.CosDomain)
328+
parsedURL.Host = bucket + "." + parsedURL.Host
329+
cosUrl = parsedURL.String()
330+
}
331+
332+
u, _ := url.Parse(cosUrl)
321333

322334
if me.tencentCosConn != nil && me.tencentCosConn.BaseURL.BucketURL == u {
323335
return me.tencentCosConn
@@ -1319,7 +1331,12 @@ func (me *TencentCloudClient) UseDtsClient() *dts.Client {
13191331

13201332
// UseCosBatchClient returns ci client for service
13211333
func (me *TencentCloudClient) UseCosBatchClient(uin string) *cos.Client {
1322-
u, _ := url.Parse(fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region))
1334+
cosUrl := fmt.Sprintf("https://%s.cos-control.%s.myqcloud.com", uin, me.Region)
1335+
if me.CosDomain != "" {
1336+
cosUrl = me.CosDomain
1337+
}
1338+
1339+
u, _ := url.Parse(cosUrl)
13231340

13241341
if me.cosBatchConn != nil && me.cosBatchConn.BaseURL.BatchURL == u {
13251342
return me.cosBatchConn

tencentcloud/provider.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const (
125125
PROVIDER_REGION = "TENCENTCLOUD_REGION"
126126
PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL"
127127
PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN"
128+
PROVIDER_COS_DOMAIN = "TENCENTCLOUD_COS_DOMAIN"
128129
//internal version: replace envYunti begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
129130
//internal version: replace envYunti end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
130131
PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN"
@@ -204,6 +205,12 @@ func Provider() *schema.Provider {
204205
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil),
205206
Description: "The root domain of the API request, Default is `tencentcloudapi.com`.",
206207
},
208+
"cos_domain": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_COS_DOMAIN, nil),
212+
Description: "The cos domain of the API request, Default is `https://cos.{region}.myqcloud.com`, Other Examples: `https://cluster-123456.cos-cdc.ap-guangzhou.myqcloud.com`.",
213+
},
207214
//internal version: replace enableBpass begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
208215
//internal version: replace enableBpass end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
209216
"assume_role": {
@@ -2155,6 +2162,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
21552162
region string
21562163
protocol string
21572164
domain string
2165+
cosDomain string
21582166
camRoleName string
21592167
)
21602168

@@ -2194,6 +2202,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
21942202
domain = v.(string)
21952203
}
21962204

2205+
if v, ok := d.GetOk("cos_domain"); ok {
2206+
cosDomain = v.(string)
2207+
}
2208+
21972209
if v, ok := d.GetOk("cam_role_name"); ok {
21982210
camRoleName = v.(string)
21992211
}
@@ -2206,9 +2218,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
22062218
secretKey,
22072219
securityToken,
22082220
),
2209-
Region: region,
2210-
Protocol: protocol,
2211-
Domain: domain,
2221+
Region: region,
2222+
Protocol: protocol,
2223+
Domain: domain,
2224+
CosDomain: cosDomain,
22122225
}
22132226

22142227
// get auth from CAM role name

tencentcloud/services/cos/resource_tc_cos_batch.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Provides a resource to create a cos bucket batch.
22

3+
~> **NOTE:** The current resource does not support `cos_domain`.
4+
35
Example Usage
46

57
```hcl

tencentcloud/services/cos/resource_tc_cos_bucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func testSweepCosBuckets(region string) error {
7474
}
7575
log.Printf("[INFO] deleting cos bucket: %s", bucket)
7676

77-
if err = cosService.DeleteBucket(ctx, bucket, true, true); err != nil {
77+
if err = cosService.DeleteBucket(ctx, bucket, true, true, ""); err != nil {
7878
log.Printf("[ERROR] delete bucket %s error: %s", bucket, err.Error())
7979
}
8080
}

0 commit comments

Comments
 (0)