@@ -250,6 +250,14 @@ func (me *TencentCloudClient) NewClientIntlProfile(timeout int) *intlProfile.Cli
250250 return cpf
251251}
252252
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+
253261// UseCosClient returns cos client for service
254262func (me * TencentCloudClient ) UseCosClient () * s3.S3 {
255263 if me .cosConn != nil {
@@ -276,6 +284,37 @@ func (me *TencentCloudClient) UseCosClient() *s3.S3 {
276284 return s3 .New (sess )
277285}
278286
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+
279318// UseTencentCosClient tencent cloud own client for service instead of aws
280319func (me * TencentCloudClient ) UseTencentCosClient (bucket string ) * cos.Client {
281320 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 {
300339 return me .tencentCosConn
301340}
302341
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+
303367// UseMysqlClient returns mysql(cdb) client for service
304368func (me * TencentCloudClient ) UseMysqlClient (iacExtInfo ... IacExtInfo ) * cdb.Client {
305369 var logRoundTripper LogRoundTripper
0 commit comments