Skip to content

Commit c008ffa

Browse files
committed
add
1 parent e4433ac commit c008ffa

22 files changed

+899
-550
lines changed

tencentcloud/connectivity/client.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,21 @@ func (me *TencentCloudClient) NewClientIntlProfile(timeout int) *intlProfile.Cli
252252
}
253253

254254
// UseCosClient returns cos client for service
255-
func (me *TencentCloudClient) UseCosClient() *s3.S3 {
256-
if me.cosConn != nil {
257-
return me.cosConn
258-
}
255+
func (me *TencentCloudClient) UseCosClient(cdcId string) *s3.S3 {
256+
//if me.cosConn != nil {
257+
// return me.cosConn
258+
//}
259259

260260
resolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
261261
if service == endpoints.S3ServiceID {
262+
var endpointUrl string
263+
if cdcId == "" {
264+
endpointUrl = fmt.Sprintf("https://cos.%s.myqcloud.com", region)
265+
} else {
266+
endpointUrl = fmt.Sprintf("https://%s.cos-cdc.%s.myqcloud.com", cdcId, region)
267+
}
262268
return endpoints.ResolvedEndpoint{
263-
URL: fmt.Sprintf("https://cos.%s.myqcloud.com", region),
269+
URL: endpointUrl,
264270
SigningRegion: region,
265271
}, nil
266272
}

tencentcloud/provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,10 +1266,6 @@ func Provider() *schema.Provider {
12661266
"tencentcloud_mysql_ro_start_replication": cdb.ResourceTencentCloudMysqlRoStartReplication(),
12671267
"tencentcloud_mysql_ro_stop_replication": cdb.ResourceTencentCloudMysqlRoStopReplication(),
12681268
"tencentcloud_mysql_switch_proxy": cdb.ResourceTencentCloudMysqlSwitchProxy(),
1269-
"tencentcloud_cos_bucket": cos.ResourceTencentCloudCosBucket(),
1270-
"tencentcloud_cos_bucket_object": cos.ResourceTencentCloudCosBucketObject(),
1271-
"tencentcloud_cos_bucket_referer": cos.ResourceTencentCloudCosBucketReferer(),
1272-
"tencentcloud_cos_bucket_version": cos.ResourceTencentCloudCosBucketVersion(),
12731269
"tencentcloud_cfs_file_system": cfs.ResourceTencentCloudCfsFileSystem(),
12741270
"tencentcloud_cfs_access_group": cfs.ResourceTencentCloudCfsAccessGroup(),
12751271
"tencentcloud_cfs_access_rule": cfs.ResourceTencentCloudCfsAccessRule(),
@@ -1591,6 +1587,10 @@ func Provider() *schema.Provider {
15911587
"tencentcloud_tdmq_send_rocketmq_message": trocket.ResourceTencentCloudTdmqSendRocketmqMessage(),
15921588
"tencentcloud_tdmq_professional_cluster": tpulsar.ResourceTencentCloudTdmqProfessionalCluster(),
15931589
"tencentcloud_tdmq_subscription": tpulsar.ResourceTencentCloudTdmqSubscription(),
1590+
"tencentcloud_cos_bucket": cos.ResourceTencentCloudCosBucket(),
1591+
"tencentcloud_cos_bucket_object": cos.ResourceTencentCloudCosBucketObject(),
1592+
"tencentcloud_cos_bucket_referer": cos.ResourceTencentCloudCosBucketReferer(),
1593+
"tencentcloud_cos_bucket_version": cos.ResourceTencentCloudCosBucketVersion(),
15941594
"tencentcloud_cos_bucket_policy": cos.ResourceTencentCloudCosBucketPolicy(),
15951595
"tencentcloud_cos_bucket_domain_certificate_attachment": cos.ResourceTencentCloudCosBucketDomainCertificateAttachment(),
15961596
"tencentcloud_cos_bucket_inventory": cos.ResourceTencentCloudCosBucketInventory(),

tencentcloud/services/cos/data_source_tc_cos_batchs.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func DataSourceTencentCloudCosBatchs() *schema.Resource {
3333
Optional: true,
3434
Description: "The task status information you need to query. If you do not specify a task status, COS returns the status of all tasks that have been executed, including those that are in progress. If you specify a task status, COS returns the task in the specified state. Optional task states include: Active, Cancelled, Cancelling, Complete, Completing, Failed, Failing, New, Paused, Pausing, Preparing, Ready, Suspended.",
3535
},
36+
// computed
3637
"jobs": {
3738
Type: schema.TypeList,
3839
Computed: true,
@@ -113,19 +114,20 @@ func DataSourceTencentCloudCosBatchs() *schema.Resource {
113114
func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{}) error {
114115
defer tccommon.LogElapsed("data_source.tencentcloud_cos_batchs.read")()
115116

116-
logId := tccommon.GetLogId(tccommon.ContextNil)
117-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
117+
var (
118+
logId = tccommon.GetLogId(tccommon.ContextNil)
119+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
120+
)
121+
118122
uin := d.Get("uin").(string)
119123
appid := d.Get("appid").(int)
120124
jobs := make([]map[string]interface{}, 0)
121-
122125
opt := &cos.BatchListJobsOptions{}
123126
if v, ok := d.GetOk("job_statuses"); ok {
124127
opt.JobStatuses = v.(string)
125128
}
126-
headers := &cos.BatchRequestHeaders{
127-
XCosAppid: appid,
128-
}
129+
130+
headers := &cos.BatchRequestHeaders{XCosAppid: appid}
129131
ids := make([]string, 0)
130132
for {
131133
req, _ := json.Marshal(opt)
@@ -135,6 +137,7 @@ func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{
135137
if err != nil {
136138
return err
137139
}
140+
138141
for _, item := range result.Jobs.Members {
139142
jobItem := make(map[string]interface{})
140143
jobItem["creation_time"] = item.CreationTime
@@ -149,10 +152,12 @@ func dataSourceTencentCloudCosBatchsRead(d *schema.ResourceData, meta interface{
149152
"number_of_tasks_succeeded": item.ProgressSummary.NumberOfTasksSucceeded,
150153
"total_number_of_tasks": item.ProgressSummary.TotalNumberOfTasks,
151154
}
155+
152156
jobItem["progress_summary"] = []interface{}{progressSummary}
153157
ids = append(ids, item.JobId)
154158
jobs = append(jobs, jobItem)
155159
}
160+
156161
if result.NextToken != "" {
157162
opt.NextToken = result.NextToken
158163
} else {

tencentcloud/services/cos/data_source_tc_cos_bucket_inventorys.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func DataSourceTencentCloudCosBucketInventorys() *schema.Resource {
2323
Required: true,
2424
Description: "Bucket.",
2525
},
26+
"cdc_id": {
27+
Type: schema.TypeString,
28+
Optional: true,
29+
Description: "CDC cluster ID.",
30+
},
31+
// computed
2632
"inventorys": {
2733
Type: schema.TypeList,
2834
Computed: true,
@@ -78,8 +84,8 @@ func DataSourceTencentCloudCosBucketInventorys() *schema.Resource {
7884
},
7985
},
8086
"optional_fields": {
81-
Type: schema.TypeList,
82-
Optional: true,
87+
Type: schema.TypeList,
88+
Optional: true,
8389
Description: "Analysis items to include in the inventory result .",
8490
Elem: &schema.Resource{
8591
Schema: map[string]*schema.Schema{
@@ -166,14 +172,18 @@ func DataSourceTencentCloudCosBucketInventorys() *schema.Resource {
166172
func dataSourceTencentCloudCosBucketInventorysRead(d *schema.ResourceData, meta interface{}) error {
167173
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_inventorys.read")()
168174

169-
logId := tccommon.GetLogId(tccommon.ContextNil)
170-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
175+
var (
176+
logId = tccommon.GetLogId(tccommon.ContextNil)
177+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
178+
)
179+
171180
bucket := d.Get("bucket").(string)
181+
cdcId := d.Get("cdc_id").(string)
172182
inventoryConfigurations := make([]map[string]interface{}, 0)
173183
token := ""
174184
ids := make([]string, 0)
175185
for {
176-
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Bucket.ListInventoryConfigurations(ctx, token)
186+
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket, cdcId).Bucket.ListInventoryConfigurations(ctx, token)
177187
responseBody, _ := json.Marshal(response.Body)
178188
log.Printf("[DEBUG]%s api[ListInventoryConfigurations] success, response body [%s]\n", logId, responseBody)
179189
if err != nil {
@@ -194,20 +204,25 @@ func dataSourceTencentCloudCosBucketInventorysRead(d *schema.ResourceData, meta
194204
if item.Filter.Period.StartTime != 0 {
195205
periodMap["start_time"] = strconv.FormatInt(item.Filter.Period.StartTime, 10)
196206
}
207+
197208
if item.Filter.Period.EndTime != 0 {
198209
periodMap["end_time"] = strconv.FormatInt(item.Filter.Period.EndTime, 10)
199210
}
211+
200212
filterMap["period"] = []interface{}{periodMap}
201213
}
214+
202215
itemMap["filter"] = []interface{}{filterMap}
203216
}
217+
204218
if item.OptionalFields != nil {
205219
optionalFieldsMap := make(map[string]interface{})
206220
fields := make([]string, 0)
207221
if item.OptionalFields.BucketInventoryFields != nil {
208222
fields = append(fields, item.OptionalFields.BucketInventoryFields...)
209223
optionalFieldsMap["fields"] = fields
210224
}
225+
211226
itemMap["optional_fields"] = []interface{}{optionalFieldsMap}
212227
}
213228

@@ -225,16 +240,17 @@ func dataSourceTencentCloudCosBucketInventorysRead(d *schema.ResourceData, meta
225240
destinationMap["format"] = item.Destination.Format
226241
if item.Destination.Encryption != nil && item.Destination.Encryption.SSECOS != "" {
227242
encryptionMap := make(map[string]interface{})
228-
229243
encryptionMap["sse_cos"] = item.Destination.Encryption.SSECOS
230244
destinationMap["encryption"] = []interface{}{encryptionMap}
231-
232245
}
246+
233247
itemMap["destination"] = []interface{}{destinationMap}
234248
}
249+
235250
ids = append(ids, item.ID)
236251
inventoryConfigurations = append(inventoryConfigurations, itemMap)
237252
}
253+
238254
if result.NextContinuationToken != "" {
239255
token = result.NextContinuationToken
240256
} else {

tencentcloud/services/cos/data_source_tc_cos_bucket_multipart_uploads.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ func DataSourceTencentCloudCosBucketMultipartUploads() *schema.Resource {
3838
Optional: true,
3939
Description: "The returned Object key must be prefixed with Prefix. Note that when using the prefix query, the returned key still contains Prefix.",
4040
},
41+
"cdc_id": {
42+
Type: schema.TypeString,
43+
Optional: true,
44+
Description: "CDC cluster ID.",
45+
},
46+
// computed
4147
"uploads": {
4248
Type: schema.TypeList,
4349
Computed: true,
@@ -117,27 +123,35 @@ func DataSourceTencentCloudCosBucketMultipartUploads() *schema.Resource {
117123
func dataSourceTencentCloudCosBucketMultipartUploadsRead(d *schema.ResourceData, meta interface{}) error {
118124
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_multipart_uploads.read")()
119125

120-
logId := tccommon.GetLogId(tccommon.ContextNil)
121-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
126+
var (
127+
logId = tccommon.GetLogId(tccommon.ContextNil)
128+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
129+
)
130+
122131
bucket := d.Get("bucket").(string)
132+
cdcId := d.Get("cdc_id").(string)
123133
multipartUploads := make([]map[string]interface{}, 0)
124134
opt := &cos.ListMultipartUploadsOptions{}
125135
if v, ok := d.GetOk("delimiter"); ok {
126136
opt.Delimiter = v.(string)
127137
}
138+
128139
if v, ok := d.GetOk("encoding_type"); ok {
129140
opt.EncodingType = v.(string)
130141
}
142+
131143
if v, ok := d.GetOk("prefix"); ok {
132144
opt.Prefix = v.(string)
133145
}
146+
134147
ids := make([]string, 0)
135148
for {
136-
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket).Bucket.ListMultipartUploads(ctx, opt)
149+
result, response, err := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTencentCosClient(bucket, cdcId).Bucket.ListMultipartUploads(ctx, opt)
137150
responseBody, _ := json.Marshal(response.Body)
138151
if err != nil {
139152
return err
140153
}
154+
141155
log.Printf("[DEBUG]%s api[ListMultipartUploads] success, response body [%s]\n", logId, responseBody)
142156
for _, item := range result.Uploads {
143157
itemMap := make(map[string]interface{})
@@ -150,18 +164,23 @@ func dataSourceTencentCloudCosBucketMultipartUploadsRead(d *schema.ResourceData,
150164
"display_name": item.Owner.DisplayName,
151165
"id": item.Owner.ID,
152166
}
167+
153168
itemMap["owner"] = []map[string]interface{}{owner}
154169
}
170+
155171
if item.Initiator != nil {
156172
initiator := map[string]interface{}{
157173
"display_name": item.Initiator.DisplayName,
158174
"id": item.Initiator.ID,
159175
}
176+
160177
itemMap["initiator"] = []map[string]interface{}{initiator}
161178
}
179+
162180
ids = append(ids, item.UploadID)
163181
multipartUploads = append(multipartUploads, itemMap)
164182
}
183+
165184
if result.IsTruncated {
166185
opt.KeyMarker = result.KeyMarker
167186
opt.UploadIDMarker = result.UploadIDMarker

tencentcloud/services/cos/data_source_tc_cos_bucket_object.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ func DataSourceTencentCloudCosBucketObject() *schema.Resource {
2828
Required: true,
2929
Description: "The full path to the object inside the bucket.",
3030
},
31+
"cdc_id": {
32+
Type: schema.TypeString,
33+
Optional: true,
34+
Description: "CDC cluster ID.",
35+
},
3136
"result_output_file": {
3237
Type: schema.TypeString,
3338
Optional: true,
3439
Description: "Used to save results.",
3540
},
41+
// computed
3642
"cache_control": {
3743
Type: schema.TypeString,
3844
Computed: true,
@@ -75,38 +81,47 @@ func DataSourceTencentCloudCosBucketObject() *schema.Resource {
7581
func dataSourceTencentCloudCosBucketObjectsRead(d *schema.ResourceData, meta interface{}) error {
7682
defer tccommon.LogElapsed("data_source.tencentcloud_cos_bucket_object.read")()
7783

78-
logId := tccommon.GetLogId(tccommon.ContextNil)
79-
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
84+
var (
85+
logId = tccommon.GetLogId(tccommon.ContextNil)
86+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
87+
cosService = CosService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
88+
)
8089

8190
bucket := d.Get("bucket").(string)
8291
key := d.Get("key").(string)
92+
cdcId := d.Get("cdc_id").(string)
8393
outputMap := make(map[string]string)
8494
outputMap["bucket"] = bucket
8595
outputMap["key"] = key
86-
cosService := CosService{
87-
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
88-
}
89-
info, err := cosService.HeadObject(ctx, bucket, key)
96+
97+
info, err := cosService.HeadObject(ctx, bucket, key, cdcId)
9098
if err != nil {
9199
return err
92100
}
93101

94102
ids := []string{bucket, key}
95103
d.SetId(helper.DataResourceIdsHash(ids))
96104
_ = d.Set("cache_control", info.CacheControl)
105+
97106
outputMap["cache_control"] = getStringValue(info.CacheControl)
98107
_ = d.Set("content_disposition", info.ContentDisposition)
108+
99109
outputMap["content_disposition"] = getStringValue(info.ContentDisposition)
100110
_ = d.Set("content_encoding", info.ContentEncoding)
111+
101112
outputMap["content_encoding"] = getStringValue(info.ContentEncoding)
102113
_ = d.Set("content_type", info.ContentType)
114+
103115
outputMap["content_type"] = getStringValue(info.ContentType)
104116
etag := getStringValue(info.ETag)
105117
_ = d.Set("etag", strings.Trim(etag, `"`))
118+
106119
outputMap["etag"] = strings.Trim(etag, `"`)
107120
_ = d.Set("last_modified", info.LastModified.Format(time.RFC1123))
121+
108122
outputMap["last_modified"] = info.LastModified.Format(time.RFC1123)
109123
_ = d.Set("storage_class", s3.StorageClassStandard)
124+
110125
outputMap["storage_class"] = s3.StorageClassStandard
111126
if info.StorageClass != nil {
112127
_ = d.Set("storage_class", info.StorageClass)
@@ -127,5 +142,6 @@ func getStringValue(p *string) string {
127142
if p == nil {
128143
return ""
129144
}
145+
130146
return *p
131147
}

0 commit comments

Comments
 (0)