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