@@ -253,6 +253,14 @@ func (me *TencentCloudClient) NewClientIntlProfile(timeout int) *intlProfile.Cli
253
253
return cpf
254
254
}
255
255
256
+ func (me * TencentCloudClient ) UseCosClientNew (cdcId ... string ) * s3.S3 {
257
+ if cdcId [0 ] == "" {
258
+ return me .UseCosClient ()
259
+ } else {
260
+ return me .UseCosCdcClient (cdcId [0 ])
261
+ }
262
+ }
263
+
256
264
// UseCosClient returns cos client for service
257
265
func (me * TencentCloudClient ) UseCosClient () * s3.S3 {
258
266
if me .cosConn != nil {
@@ -279,6 +287,37 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
279
287
return s3 .New (sess )
280
288
}
281
289
290
+ // UseCosClient returns cos client for service with CDC
291
+ func (me * TencentCloudClient ) UseCosCdcClient (cdcId string ) * s3.S3 {
292
+ resolver := func (service , region string , optFns ... func (* endpoints.Options )) (endpoints.ResolvedEndpoint , error ) {
293
+ if service == endpoints .S3ServiceID {
294
+ endpointUrl := fmt .Sprintf ("https://%s.cos-cdc.%s.myqcloud.com" , cdcId , region )
295
+ return endpoints.ResolvedEndpoint {
296
+ URL : endpointUrl ,
297
+ SigningRegion : region ,
298
+ }, nil
299
+ }
300
+ return endpoints .DefaultResolver ().EndpointFor (service , region , optFns ... )
301
+ }
302
+
303
+ creds := credentials .NewStaticCredentials (me .Credential .SecretId , me .Credential .SecretKey , me .Credential .Token )
304
+ sess := session .Must (session .NewSession (& aws.Config {
305
+ Credentials : creds ,
306
+ Region : aws .String (me .Region ),
307
+ EndpointResolver : endpoints .ResolverFunc (resolver ),
308
+ }))
309
+
310
+ return s3 .New (sess )
311
+ }
312
+
313
+ func (me * TencentCloudClient ) UseTencentCosClientNew (bucket string , cdcId ... string ) * cos.Client {
314
+ if cdcId [0 ] == "" {
315
+ return me .UseTencentCosClient (bucket )
316
+ } else {
317
+ return me .UseTencentCosCdcClient (bucket , cdcId [0 ])
318
+ }
319
+ }
320
+
282
321
// UseTencentCosClient tencent cloud own client for service instead of aws
283
322
func (me * TencentCloudClient ) UseTencentCosClient (bucket string ) * cos.Client {
284
323
u , _ := url .Parse (fmt .Sprintf ("https://%s.cos.%s.myqcloud.com" , bucket , me .Region ))
@@ -303,6 +342,31 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client {
303
342
return me .tencentCosConn
304
343
}
305
344
345
+ // UseTencentCosClient tencent cloud own client for service instead of aws with CDC
346
+ func (me * TencentCloudClient ) UseTencentCosCdcClient (bucket string , cdcId string ) * cos.Client {
347
+ var u * url.URL
348
+ u , _ = url .Parse (fmt .Sprintf ("https://%s.%s.cos-cdc.%s.myqcloud.com" , bucket , cdcId , me .Region ))
349
+
350
+ if me .tencentCosConn != nil && me .tencentCosConn .BaseURL .BucketURL == u {
351
+ return me .tencentCosConn
352
+ }
353
+
354
+ baseUrl := & cos.BaseURL {
355
+ BucketURL : u ,
356
+ }
357
+
358
+ me .tencentCosConn = cos .NewClient (baseUrl , & http.Client {
359
+ Timeout : 100 * time .Second ,
360
+ Transport : & cos.AuthorizationTransport {
361
+ SecretID : me .Credential .SecretId ,
362
+ SecretKey : me .Credential .SecretKey ,
363
+ SessionToken : me .Credential .Token ,
364
+ },
365
+ })
366
+
367
+ return me .tencentCosConn
368
+ }
369
+
306
370
// UseMysqlClient returns mysql(cdb) client for service
307
371
func (me * TencentCloudClient ) UseMysqlClient (iacExtInfo ... IacExtInfo ) * cdb.Client {
308
372
var logRoundTripper LogRoundTripper
0 commit comments