From bcb63b9ea11f6b9720051035777ad3b33bb3d0de Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Mon, 26 Feb 2024 14:20:13 +0800 Subject: [PATCH 1/9] add --- tencentcloud/connectivity/client.go | 10 ++++-- tencentcloud/connectivity/transport.go | 15 ++++++++- .../services/cvm/resource_tc_instance.go | 33 ++++++++++++++----- .../services/cvm/service_tencentcloud_cvm.go | 5 ++- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 1d63b4d15d..5c407428f5 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -395,7 +395,7 @@ func (me *TencentCloudClient) UseClbClient() *clb.Client { } // UseCvmClient returns cvm client for service -func (me *TencentCloudClient) UseCvmClient() *cvm.Client { +func (me *TencentCloudClient) UseCvmClient(specArgs ...IacExtInfo) *cvm.Client { if me.cvmConn != nil { return me.cvmConn } @@ -403,7 +403,13 @@ func (me *TencentCloudClient) UseCvmClient() *cvm.Client { var reqTimeout = getEnvDefault(PROVIDER_CVM_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cvmConn, _ = cvm.NewClient(me.Credential, me.Region, cpf) - me.cvmConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.cvmConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cvmConn.WithHttpTransport(&LogRoundTripper{}) + } return me.cvmConn } diff --git a/tencentcloud/connectivity/transport.go b/tencentcloud/connectivity/transport.go index 02c2a4c1f2..61b9fe0970 100644 --- a/tencentcloud/connectivity/transport.go +++ b/tencentcloud/connectivity/transport.go @@ -25,6 +25,11 @@ func SetReqClient(name string) { } type LogRoundTripper struct { + InstanceId string +} + +type IacExtInfo struct { + InstanceId string } func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Response, errRet error) { @@ -47,7 +52,15 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp if routeUserID := os.Getenv(ENV_TESTING_ROUTE_USER_ID); routeUserID != "" { request.Header.Set(ENV_TESTING_ROUTE_HEADER_KEY, routeUserID) } - request.Header.Set("X-TC-RequestClient", ReqClient) + + var iacExtInfoStr string + if me.InstanceId != "" { + iacExtInfoStr = fmt.Sprintf("%s,id=%s", ReqClient, me.InstanceId) + } else { + iacExtInfoStr = ReqClient + } + + request.Header.Set("X-TC-RequestClient", iacExtInfoStr) inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName])) requestBody, errRet := ioutil.ReadAll(bodyReader) if errRet != nil { diff --git a/tencentcloud/services/cvm/resource_tc_instance.go b/tencentcloud/services/cvm/resource_tc_instance.go index f994d7282f..edec79a4eb 100644 --- a/tencentcloud/services/cvm/resource_tc_instance.go +++ b/tencentcloud/services/cvm/resource_tc_instance.go @@ -24,6 +24,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) +var importFlag = false + func ResourceTencentCloudInstance() *schema.Resource { return &schema.Resource{ Create: resourceTencentCloudInstanceCreate, @@ -31,7 +33,16 @@ func ResourceTencentCloudInstance() *schema.Resource { Update: resourceTencentCloudInstanceUpdate, Delete: resourceTencentCloudInstanceDelete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: func(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { + importFlag = true + defaultValues := map[string]interface{}{} + + for k, v := range defaultValues { + _ = d.Set(k, v) + } + + return []*schema.ResourceData{d}, nil + }, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(15 * time.Minute), @@ -739,21 +750,21 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{}) defer tccommon.LogElapsed("resource.tencentcloud_instance.read")() defer tccommon.InconsistentCheck(d, meta)() - logId := tccommon.GetLogId(tccommon.ContextNil) - ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + client = meta.(tccommon.ProviderMeta).GetAPIV3Conn() + cvmService = CvmService{client: client} + cbsService = svccbs.NewCbsService(client) + instanceId = d.Id() + ) - instanceId := d.Id() forceDelete := false if v, ok := d.GetOkExists("force_delete"); ok { forceDelete = v.(bool) _ = d.Set("force_delete", forceDelete) } - client := meta.(tccommon.ProviderMeta).GetAPIV3Conn() - cvmService := CvmService{ - client: client, - } - cbsService := svccbs.NewCbsService(client) var instance *cvm.Instance var errRet error err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { @@ -761,14 +772,18 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{}) if errRet != nil { return tccommon.RetryError(errRet, tccommon.InternalError) } + if instance != nil && instance.LatestOperationState != nil && *instance.LatestOperationState == "OPERATING" { return resource.RetryableError(fmt.Errorf("waiting for instance %s operation", *instance.InstanceId)) } + return nil }) + if err != nil { return err } + if instance == nil || *instance.InstanceState == CVM_STATUS_LAUNCH_FAILED { d.SetId("") log.Printf("[CRITAL]instance %s not exist or launch failed", instanceId) diff --git a/tencentcloud/services/cvm/service_tencentcloud_cvm.go b/tencentcloud/services/cvm/service_tencentcloud_cvm.go index 607b57fed6..6984db614c 100644 --- a/tencentcloud/services/cvm/service_tencentcloud_cvm.go +++ b/tencentcloud/services/cvm/service_tencentcloud_cvm.go @@ -69,8 +69,11 @@ func (me *CvmService) DescribeInstanceById(ctx context.Context, instanceId strin request := cvm.NewDescribeInstancesRequest() request.InstanceIds = []*string{&instanceId} + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + ratelimit.Check(request.GetAction()) - response, err := me.client.UseCvmClient().DescribeInstances(request) + response, err := me.client.UseCvmClient(specArgs).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) From 7f181ccc3301026672146aa028ec33bc53e7df1f Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 28 Feb 2024 18:01:09 +0800 Subject: [PATCH 2/9] add --- tencentcloud/connectivity/client.go | 120 ++++++++++++++---- .../services/cbs/service_tencentcloud_cbs.go | 39 +++++- .../ckafka/service_tencentcloud_ckafka.go | 4 +- .../services/clb/service_tencentcloud_clb.go | 4 +- .../mongodb/service_tencentcloud_mongodb.go | 6 +- .../service_tencentcloud_postgresql.go | 4 +- .../services/scf/service_tencentcloud_scf.go | 6 +- .../service_tencentcloud_sqlserver.go | 10 +- .../services/tcr/service_tencentcloud_tcr.go | 5 +- .../tdmq/service_tencentcloud_tdmq.go | 17 ++- .../services/tke/service_tencentcloud_tke.go | 5 +- .../services/tse/service_tencentcloud_tse.go | 5 +- .../services/vpc/service_tencentcloud_vpc.go | 18 ++- 13 files changed, 195 insertions(+), 48 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 5c407428f5..aad84b847a 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -329,20 +329,26 @@ func (me *TencentCloudClient) UseAsClient() *as.Client { } // UseVpcClient returns vpc client for service -func (me *TencentCloudClient) UseVpcClient() *vpc.Client { +func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { if me.vpcConn != nil { return me.vpcConn } cpf := me.NewClientProfile(300) me.vpcConn, _ = vpc.NewClient(me.Credential, me.Region, cpf) - me.vpcConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.vpcConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.vpcConn.WithHttpTransport(&LogRoundTripper{}) + } return me.vpcConn } // UseCbsClient returns cbs client for service -func (me *TencentCloudClient) UseCbsClient() *cbs.Client { +func (me *TencentCloudClient) UseCbsClient(specArgs ...IacExtInfo) *cbs.Client { if me.cbsConn != nil { return me.cbsConn } @@ -350,7 +356,13 @@ func (me *TencentCloudClient) UseCbsClient() *cbs.Client { var reqTimeout = getEnvDefault(PROVIDER_CBS_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cbsConn, _ = cbs.NewClient(me.Credential, me.Region, cpf) - me.cbsConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.cbsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cbsConn.WithHttpTransport(&LogRoundTripper{}) + } return me.cbsConn } @@ -369,27 +381,39 @@ func (me *TencentCloudClient) UseDcClient() *dc.Client { } // UseMongodbClient returns mongodb client for service -func (me *TencentCloudClient) UseMongodbClient() *mongodb.Client { +func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb.Client { if me.mongodbConn != nil { return me.mongodbConn } cpf := me.NewClientProfile(300) me.mongodbConn, _ = mongodb.NewClient(me.Credential, me.Region, cpf) - me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.mongodbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) + } return me.mongodbConn } // UseClbClient returns clb client for service -func (me *TencentCloudClient) UseClbClient() *clb.Client { +func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { if me.clbConn != nil { return me.clbConn } cpf := me.NewClientProfile(300) me.clbConn, _ = clb.NewClient(me.Credential, me.Region, cpf) - me.clbConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.clbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.clbConn.WithHttpTransport(&LogRoundTripper{}) + } return me.clbConn } @@ -428,27 +452,39 @@ func (me *TencentCloudClient) UseTagClient() *tag.Client { } // UseTkeClient returns tke client for service -func (me *TencentCloudClient) UseTkeClient() *tke.Client { +func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { if me.tkeConn != nil { return me.tkeConn } cpf := me.NewClientProfile(300) me.tkeConn, _ = tke.NewClient(me.Credential, me.Region, cpf) - me.tkeConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.tkeConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tkeConn.WithHttpTransport(&LogRoundTripper{}) + } return me.tkeConn } // UseTdmqClient returns Tdmq client for service -func (me *TencentCloudClient) UseTdmqClient() *tdmq.Client { +func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client { if me.tdmqConn != nil { return me.tdmqConn } cpf := me.NewClientProfile(300) me.tdmqConn, _ = tdmq.NewClient(me.Credential, me.Region, cpf) - me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.tdmqConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) + } return me.tdmqConn } @@ -522,14 +558,20 @@ func (me *TencentCloudClient) UseCfsClient() *cfs.Client { } // UseScfClient returns scf client for service -func (me *TencentCloudClient) UseScfClient() *scf.Client { +func (me *TencentCloudClient) UseScfClient(specArgs ...IacExtInfo) *scf.Client { if me.scfConn != nil { return me.scfConn } cpf := me.NewClientProfile(300) me.scfConn, _ = scf.NewClient(me.Credential, me.Region, cpf) - me.scfConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.scfConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.scfConn.WithHttpTransport(&LogRoundTripper{}) + } return me.scfConn } @@ -601,40 +643,58 @@ func (me *TencentCloudClient) UseEsClient() *es.Client { } // UsePostgresqlClient returns postgresql client for service -func (me *TencentCloudClient) UsePostgresqlClient() *postgre.Client { +func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postgre.Client { if me.postgreConn != nil { return me.postgreConn } cpf := me.NewClientProfile(300) me.postgreConn, _ = postgre.NewClient(me.Credential, me.Region, cpf) - me.postgreConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.postgreConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.postgreConn.WithHttpTransport(&LogRoundTripper{}) + } return me.postgreConn } // UseSqlserverClient returns sqlserver client for service -func (me *TencentCloudClient) UseSqlserverClient() *sqlserver.Client { +func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlserver.Client { if me.sqlserverConn != nil { return me.sqlserverConn } cpf := me.NewClientProfile(300) me.sqlserverConn, _ = sqlserver.NewClient(me.Credential, me.Region, cpf) - me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) + } return me.sqlserverConn } // UseCkafkaClient returns ckafka client for service -func (me *TencentCloudClient) UseCkafkaClient() *ckafka.Client { +func (me *TencentCloudClient) UseCkafkaClient(specArgs ...IacExtInfo) *ckafka.Client { if me.ckafkaConn != nil { return me.ckafkaConn } cpf := me.NewClientProfile(300) me.ckafkaConn, _ = ckafka.NewClient(me.Credential, me.Region, cpf) - me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) + } return me.ckafkaConn } @@ -692,14 +752,20 @@ func (me *TencentCloudClient) UseAPIGatewayClient() *apigateway.Client { } // UseTCRClient returns apigateway client for service -func (me *TencentCloudClient) UseTCRClient() *tcr.Client { +func (me *TencentCloudClient) UseTCRClient(specArgs ...IacExtInfo) *tcr.Client { if me.tcrConn != nil { return me.tcrConn } cpf := me.NewClientProfile(300) me.tcrConn, _ = tcr.NewClient(me.Credential, me.Region, cpf) - me.tcrConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.tcrConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tcrConn.WithHttpTransport(&LogRoundTripper{}) + } return me.tcrConn } @@ -1219,7 +1285,7 @@ func (me *TencentCloudClient) UseCiamClient() *ciam.Client { } // UseTseClient returns tse client for service -func (me *TencentCloudClient) UseTseClient() *tse.Client { +func (me *TencentCloudClient) UseTseClient(specArgs ...IacExtInfo) *tse.Client { if me.tseConn != nil { return me.tseConn } @@ -1227,7 +1293,13 @@ func (me *TencentCloudClient) UseTseClient() *tse.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.tseConn, _ = tse.NewClient(me.Credential, me.Region, cpf) - me.tseConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.tseConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tseConn.WithHttpTransport(&LogRoundTripper{}) + } return me.tseConn } diff --git a/tencentcloud/services/cbs/service_tencentcloud_cbs.go b/tencentcloud/services/cbs/service_tencentcloud_cbs.go index 7584545e1e..d206ff9b36 100644 --- a/tencentcloud/services/cbs/service_tencentcloud_cbs.go +++ b/tencentcloud/services/cbs/service_tencentcloud_cbs.go @@ -3,6 +3,7 @@ package cbs import ( "context" "log" + "strings" "sync" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" @@ -10,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" @@ -44,14 +46,35 @@ func (me *CbsService) DescribeDiskSetByIds(ctx context.Context, diskSetIds strin } func (me *CbsService) DescribeDiskById(ctx context.Context, diskId string) (disk *cbs.Disk, errRet error) { - disks, err := me.DescribeDiskList(ctx, []*string{&diskId}) + logId := tccommon.GetLogId(ctx) + request := cbs.NewDescribeDisksRequest() + request.DiskIds = common.StringPtrs([]string{diskId}) + request.Limit = helper.IntUint64(100) + ratelimit.Check(request.GetAction()) + + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = diskId + + response, err := me.client.UseCbsClient(specArgs).DescribeDisks(request) if err != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, request.GetAction(), request.ToJsonString(), err.Error()) errRet = err return } - if len(disks) > 0 { - disk = disks[0] + + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if err != nil { + errRet = err + return + } + + if len(response.Response.DiskSet) > 0 { + disk = response.Response.DiskSet[0] } + return } @@ -61,7 +84,15 @@ func (me *CbsService) DescribeDiskList(ctx context.Context, diskIds []*string) ( request.DiskIds = diskIds request.Limit = helper.IntUint64(100) ratelimit.Check(request.GetAction()) - response, err := me.client.UseCbsClient().DescribeDisks(request) + + var specArgs connectivity.IacExtInfo + tmpList := make([]string, len(diskIds)) + for k, v := range diskIds { + tmpList[k] = *v + } + specArgs.InstanceId = strings.Join(tmpList, tccommon.FILED_SP) + + response, err := me.client.UseCbsClient(specArgs).DescribeDisks(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go b/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go index 5c47b8519d..bf70e1b628 100644 --- a/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go +++ b/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go @@ -90,7 +90,9 @@ func (me *CkafkaService) DescribeCkafkaInstanceById(ctx context.Context, }() request.InstanceId = &instanceId if err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { - result, err := me.client.UseCkafkaClient().DescribeInstancesDetail(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + result, err := me.client.UseCkafkaClient(specArgs).DescribeInstancesDetail(request) if err != nil { return tccommon.RetryError(err) } diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index c62f9c2ed3..c451762862 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -56,7 +56,9 @@ func (me *ClbService) DescribeLoadBalancerById(ctx context.Context, clbId string request := clb.NewDescribeLoadBalancersRequest() request.LoadBalancerIds = []*string{&clbId} ratelimit.Check(request.GetAction()) - response, err := me.client.UseClbClient().DescribeLoadBalancers(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = clbId + response, err := me.client.UseClbClient(specArgs).DescribeLoadBalancers(request) if err != nil { errRet = errors.WithStack(err) return diff --git a/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go b/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go index 6e05ac289a..1e41687030 100644 --- a/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go +++ b/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go @@ -29,10 +29,14 @@ func (me *MongodbService) DescribeInstanceById(ctx context.Context, instanceId s logId := tccommon.GetLogId(ctx) request := mongodb.NewDescribeDBInstancesRequest() request.InstanceIds = []*string{&instanceId} + + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + var response *mongodb.DescribeDBInstancesResponse err := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - result, e := me.client.UseMongodbClient().DescribeDBInstances(request) + result, e := me.client.UseMongodbClient(specArgs).DescribeDBInstances(request) if e != nil { return resource.NonRetryableError(e) } diff --git a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go index 81c2159eb2..29284757f1 100644 --- a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go +++ b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go @@ -440,7 +440,9 @@ func (me *PostgresqlService) DescribePostgresqlInstanceById(ctx context.Context, request.DBInstanceId = &instanceId ratelimit.Check(request.GetAction()) - response, err := me.client.UsePostgresqlClient().DescribeDBInstanceAttribute(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + response, err := me.client.UsePostgresqlClient(specArgs).DescribeDBInstanceAttribute(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/scf/service_tencentcloud_scf.go b/tencentcloud/services/scf/service_tencentcloud_scf.go index b71d890d1d..affad92de9 100644 --- a/tencentcloud/services/scf/service_tencentcloud_scf.go +++ b/tencentcloud/services/scf/service_tencentcloud_scf.go @@ -148,16 +148,16 @@ func (me *ScfService) CreateFunction(ctx context.Context, info scfFunctionInfo) } func (me *ScfService) DescribeFunction(ctx context.Context, name, namespace string) (resp *scf.GetFunctionResponse, err error) { - client := me.client.UseScfClient() - request := scf.NewGetFunctionRequest() request.FunctionName = &name request.Namespace = &namespace if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = strings.Join([]string{name, namespace}, tccommon.FILED_SP) - response, err := client.GetFunction(request) + response, err := me.client.UseScfClient(specArgs).GetFunction(request) if err != nil { if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok { for _, code := range SCF_FUNCTIONS_NOT_FOUND_SET { diff --git a/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go b/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go index 0980fa0e18..55de396248 100644 --- a/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go +++ b/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go @@ -331,11 +331,14 @@ func (me *SqlserverService) DescribeSqlserverInstances(ctx context.Context, inst } var offset, limit int64 = 0, 20 + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + for { request.Offset = &offset request.Limit = &limit ratelimit.Check(request.GetAction()) - response, err := me.client.UseSqlserverClient().DescribeDBInstances(request) + response, err := me.client.UseSqlserverClient(specArgs).DescribeDBInstances(request) if err != nil { errRet = err return @@ -2667,7 +2670,10 @@ func (me *SqlserverService) DescribeSqlserverGeneralCloudInstanceById(ctx contex ratelimit.Check(request.GetAction()) - response, err := me.client.UseSqlserverClient().DescribeDBInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + + response, err := me.client.UseSqlserverClient(specArgs).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/tcr/service_tencentcloud_tcr.go b/tencentcloud/services/tcr/service_tencentcloud_tcr.go index 86bb9cb36b..d60a59e0bf 100644 --- a/tencentcloud/services/tcr/service_tencentcloud_tcr.go +++ b/tencentcloud/services/tcr/service_tencentcloud_tcr.go @@ -177,7 +177,10 @@ func (me *TCRService) DescribeTCRInstanceById(ctx context.Context, instanceId st request.Registryids = []*string{&instanceId} ratelimit.Check(request.GetAction()) - response, err := me.client.UseTCRClient().DescribeInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + + response, err := me.client.UseTCRClient(specArgs).DescribeInstances(request) if err != nil { ee, ok := err.(*sdkErrors.TencentCloudSDKError) if !ok { diff --git a/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go b/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go index 29256b51be..56d08aa52e 100644 --- a/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go +++ b/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go @@ -44,9 +44,12 @@ func (me *TdmqService) DescribeTdmqInstanceById(ctx context.Context, var response *tdmq.DescribeClustersResponse + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = clusterId + if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - result, err := me.client.UseTdmqClient().DescribeClusters(request) + result, err := me.client.UseTdmqClient(specArgs).DescribeClusters(request) if err != nil { return tccommon.RetryError(err, tccommon.InternalError) } @@ -642,8 +645,10 @@ func (me *TdmqService) DescribeTdmqProfessionalClusterById(ctx context.Context, }() ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = clusterId - response, err := me.client.UseTdmqClient().DescribePulsarProInstanceDetail(request) + response, err := me.client.UseTdmqClient(specArgs).DescribePulsarProInstanceDetail(request) if err != nil { errRet = err return @@ -696,6 +701,8 @@ func (me *TdmqService) DescribePulsarProInstances(ctx context.Context, clusterId }() ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = clusterId var ( offset uint64 = 0 @@ -705,7 +712,7 @@ func (me *TdmqService) DescribePulsarProInstances(ctx context.Context, clusterId for { request.Offset = &offset request.Limit = &limit - response, err := me.client.UseTdmqClient().DescribePulsarProInstances(request) + response, err := me.client.UseTdmqClient(specArgs).DescribePulsarProInstances(request) if err != nil { errRet = err return @@ -1618,8 +1625,10 @@ func (me *TdmqService) DescribeTdmqRabbitmqVipInstanceById(ctx context.Context, }() ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId - response, err := me.client.UseTdmqClient().DescribeRabbitMQVipInstance(request) + response, err := me.client.UseTdmqClient(specArgs).DescribeRabbitMQVipInstance(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/tke/service_tencentcloud_tke.go b/tencentcloud/services/tke/service_tencentcloud_tke.go index 1bbed36694..f465ce69d4 100644 --- a/tencentcloud/services/tke/service_tencentcloud_tke.go +++ b/tencentcloud/services/tke/service_tencentcloud_tke.go @@ -414,8 +414,11 @@ func (me *TkeService) DescribeCluster(ctx context.Context, id string) ( request.ClusterIds = []*string{&id} + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = id + ratelimit.Check(request.GetAction()) - response, err := me.client.UseTkeClient().DescribeClusters(request) + response, err := me.client.UseTkeClient(specArgs).DescribeClusters(request) if err != nil { errRet = err diff --git a/tencentcloud/services/tse/service_tencentcloud_tse.go b/tencentcloud/services/tse/service_tencentcloud_tse.go index c95663eefc..391d22f299 100644 --- a/tencentcloud/services/tse/service_tencentcloud_tse.go +++ b/tencentcloud/services/tse/service_tencentcloud_tse.go @@ -42,8 +42,9 @@ func (me *TseService) DescribeTseInstanceById(ctx context.Context, instanceId st }() ratelimit.Check(request.GetAction()) - - response, err := me.client.UseTseClient().DescribeSREInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + response, err := me.client.UseTseClient(specArgs).DescribeSREInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/vpc/service_tencentcloud_vpc.go b/tencentcloud/services/vpc/service_tencentcloud_vpc.go index ef85602600..41737d578c 100644 --- a/tencentcloud/services/vpc/service_tencentcloud_vpc.go +++ b/tencentcloud/services/vpc/service_tencentcloud_vpc.go @@ -407,7 +407,16 @@ getMoreData: var response *vpc.DescribeVpcsResponse if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - result, err := me.client.UseVpcClient().DescribeVpcs(request) + var result *vpc.DescribeVpcsResponse + var err error + if vpcId != "" { + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = vpcId + result, err = me.client.UseVpcClient(specArgs).DescribeVpcs(request) + } else { + result, err = me.client.UseVpcClient().DescribeVpcs(request) + } + if err != nil { return tccommon.RetryError(err, tccommon.InternalError) } @@ -2357,9 +2366,12 @@ func (me *VpcService) DescribeEipById(ctx context.Context, eipId string) (eip *v logId := tccommon.GetLogId(ctx) request := vpc.NewDescribeAddressesRequest() request.AddressIds = []*string{&eipId} - ratelimit.Check(request.GetAction()) - response, err := me.client.UseVpcClient().DescribeAddresses(request) + + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = eipId + + response, err := me.client.UseVpcClient(specArgs).DescribeAddresses(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) From 788f8e67af059709be9a5549981415598a8fd4d2 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 6 Mar 2024 09:47:01 +0800 Subject: [PATCH 3/9] feat/iacExtInfo2 --- tencentcloud/connectivity/client.go | 122 ++++++++++++++---- tencentcloud/connectivity/transport.go | 9 ++ .../cdb/service_tencentcloud_mysql.go | 4 +- .../services/cdn/service_tencentcloud_cdn.go | 4 +- .../services/cfw/service_tencentcloud_cfw.go | 9 +- .../services/cls/service_tencentcloud_cls.go | 8 +- .../es/service_tencentcloud_elasticsearch.go | 4 +- .../gaap/service_tencentcloud_gaap.go | 10 +- .../service_tencentcloud_lighthouse.go | 4 +- .../mariadb/service_tencentcloud_mariadb.go | 8 +- .../resource_tc_private_dns_zone.go | 8 +- .../tdcpg/service_tencentcloud_tdcpg.go | 25 +++- .../services/teo/service_tencentcloud_teo.go | 7 +- .../services/vpc/resource_tc_nat_gateway.go | 10 +- .../services/vpc/service_tencentcloud_vpc.go | 15 ++- .../vpn/resource_tc_vpn_customer_gateway.go | 5 +- .../services/waf/service_tencentcloud_waf.go | 5 +- 17 files changed, 200 insertions(+), 57 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 0d43f4d891..3eb1459607 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -295,14 +295,20 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { } // UseMysqlClient returns mysql(cdb) client for service -func (me *TencentCloudClient) UseMysqlClient() *cdb.Client { +func (me *TencentCloudClient) UseMysqlClient(specArgs ...IacExtInfo) *cdb.Client { if me.mysqlConn != nil { return me.mysqlConn } cpf := me.NewClientProfile(300) me.mysqlConn, _ = cdb.NewClient(me.Credential, me.Region, cpf) - me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.mysqlConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) + } return me.mysqlConn } @@ -495,15 +501,20 @@ func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client } // UseGaapClient returns gaap client for service -func (me *TencentCloudClient) UseGaapClient() *gaap.Client { +func (me *TencentCloudClient) UseGaapClient(specArgs ...IacExtInfo) *gaap.Client { if me.gaapConn != nil { return me.gaapConn } cpf := me.NewClientProfile(300) me.gaapConn, _ = gaap.NewClient(me.Credential, me.Region, cpf) - me.gaapConn.WithHttpTransport(&LogRoundTripper{}) - + if len(specArgs) != 0 { + me.gaapConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.gaapConn.WithHttpTransport(&LogRoundTripper{}) + } return me.gaapConn } @@ -608,14 +619,20 @@ func (me *TencentCloudClient) UseDayuClient() *dayu.Client { } // UseCdnClient returns cdn client for service -func (me *TencentCloudClient) UseCdnClient() *cdn.Client { +func (me *TencentCloudClient) UseCdnClient(specArgs ...IacExtInfo) *cdn.Client { if me.cdnConn != nil { return me.cdnConn } cpf := me.NewClientProfile(300) me.cdnConn, _ = cdn.NewClient(me.Credential, me.Region, cpf) - me.cdnConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.cdnConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cdnConn.WithHttpTransport(&LogRoundTripper{}) + } return me.cdnConn } @@ -634,7 +651,7 @@ func (me *TencentCloudClient) UseMonitorClient() *monitor.Client { } // UseEsClient returns es client for service -func (me *TencentCloudClient) UseEsClient() *es.Client { +func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { if me.esConn != nil { return me.esConn } @@ -642,7 +659,13 @@ func (me *TencentCloudClient) UseEsClient() *es.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.esConn, _ = es.NewClient(me.Credential, me.Region, cpf) - me.esConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.esConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.esConn.WithHttpTransport(&LogRoundTripper{}) + } return me.esConn } @@ -839,25 +862,37 @@ func (me *TencentCloudClient) UseEmrClient() *emr.Client { } // UseClsClient return CLS client for service -func (me *TencentCloudClient) UseClsClient() *cls.Client { +func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { if me.clsConn != nil { return me.clsConn } cpf := me.NewClientProfile(300) me.clsConn, _ = cls.NewClient(me.Credential, me.Region, cpf) - me.clsConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.clsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.clsConn.WithHttpTransport(&LogRoundTripper{}) + } return me.clsConn } // UseLighthouseClient return Lighthouse client for service -func (me *TencentCloudClient) UseLighthouseClient() *lighthouse.Client { +func (me *TencentCloudClient) UseLighthouseClient(specArgs ...IacExtInfo) *lighthouse.Client { if me.lighthouseConn != nil { return me.lighthouseConn } cpf := me.NewClientProfile(300) me.lighthouseConn, _ = lighthouse.NewClient(me.Credential, me.Region, cpf) - me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) + } return me.lighthouseConn } @@ -875,13 +910,19 @@ func (me *TencentCloudClient) UseDnsPodClient() *dnspod.Client { } // UsePrivateDnsClient return PrivateDns client for service -func (me *TencentCloudClient) UsePrivateDnsClient() *privatedns.Client { +func (me *TencentCloudClient) UsePrivateDnsClient(specArgs ...IacExtInfo) *privatedns.Client { if me.privateDnsConn != nil { return me.privateDnsConn } cpf := me.NewClientProfile(300) me.privateDnsConn, _ = privatedns.NewClient(me.Credential, me.Region, cpf) - me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) + } return me.privateDnsConn } @@ -925,14 +966,20 @@ func (me *TencentCloudClient) UseTemClient() *tem.Client { } // UseTeoClient returns teo client for service -func (me *TencentCloudClient) UseTeoClient() *teo.Client { +func (me *TencentCloudClient) UseTeoClient(specArgs ...IacExtInfo) *teo.Client { if me.teoConn != nil { return me.teoConn } cpf := me.NewClientProfile(300) me.teoConn, _ = teo.NewClient(me.Credential, me.Region, cpf) - me.teoConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.teoConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.teoConn.WithHttpTransport(&LogRoundTripper{}) + } return me.teoConn } @@ -1016,14 +1063,20 @@ func (me *TencentCloudClient) UseCatClient() *cat.Client { } // UseMariadbClient returns mariadb client for service -func (me *TencentCloudClient) UseMariadbClient() *mariadb.Client { +func (me *TencentCloudClient) UseMariadbClient(specArgs ...IacExtInfo) *mariadb.Client { if me.mariadbConn != nil { return me.mariadbConn } cpf := me.NewClientProfile(300) me.mariadbConn, _ = mariadb.NewClient(me.Credential, me.Region, cpf) - me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.mariadbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) + } return me.mariadbConn } @@ -1068,15 +1121,20 @@ func (me *TencentCloudClient) UseOrganizationClient() *organization.Client { } // UseTdcpgClient returns tdcpg client for service -func (me *TencentCloudClient) UseTdcpgClient() *tdcpg.Client { +func (me *TencentCloudClient) UseTdcpgClient(specArgs ...IacExtInfo) *tdcpg.Client { if me.tdcpgConn != nil { return me.tdcpgConn } cpf := me.NewClientProfile(300) me.tdcpgConn, _ = tdcpg.NewClient(me.Credential, me.Region, cpf) - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) - + if len(specArgs) != 0 { + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) + } return me.tdcpgConn } @@ -1365,7 +1423,7 @@ func (me *TencentCloudClient) UseWedataClient() *wedata.Client { return me.wedataConn } -func (me *TencentCloudClient) UseWafClient() *waf.Client { +func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { if me.wafConn != nil { return me.wafConn } @@ -1373,12 +1431,18 @@ func (me *TencentCloudClient) UseWafClient() *waf.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.wafConn, _ = waf.NewClient(me.Credential, me.Region, cpf) - me.wafConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.wafConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.wafConn.WithHttpTransport(&LogRoundTripper{}) + } return me.wafConn } -func (me *TencentCloudClient) UseCfwClient() *cfw.Client { +func (me *TencentCloudClient) UseCfwClient(specArgs ...IacExtInfo) *cfw.Client { if me.cfwConn != nil { return me.cfwConn } @@ -1386,7 +1450,13 @@ func (me *TencentCloudClient) UseCfwClient() *cfw.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.cfwConn, _ = cfw.NewClient(me.Credential, me.Region, cpf) - me.cfwConn.WithHttpTransport(&LogRoundTripper{}) + if len(specArgs) != 0 { + me.cfwConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cfwConn.WithHttpTransport(&LogRoundTripper{}) + } return me.cfwConn } diff --git a/tencentcloud/connectivity/transport.go b/tencentcloud/connectivity/transport.go index 61b9fe0970..01e0bb1b47 100644 --- a/tencentcloud/connectivity/transport.go +++ b/tencentcloud/connectivity/transport.go @@ -61,6 +61,15 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp } request.Header.Set("X-TC-RequestClient", iacExtInfoStr) + + fmt.Println(1111111111) + fmt.Println(1111111111) + fmt.Println(1111111111) + fmt.Println(request.Header.Get("X-TC-RequestClient")) + fmt.Println(1111111111) + fmt.Println(1111111111) + fmt.Println(1111111111) + inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName])) requestBody, errRet := ioutil.ReadAll(bodyReader) if errRet != nil { diff --git a/tencentcloud/services/cdb/service_tencentcloud_mysql.go b/tencentcloud/services/cdb/service_tencentcloud_mysql.go index f4c9de53a1..46b13a029c 100644 --- a/tencentcloud/services/cdb/service_tencentcloud_mysql.go +++ b/tencentcloud/services/cdb/service_tencentcloud_mysql.go @@ -810,7 +810,9 @@ func (me *MysqlService) _innerDescribeDBInstanceById(ctx context.Context, mysqlI } }() ratelimit.Check(request.GetAction()) - response, err := me.client.UseMysqlClient().DescribeDBInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = mysqlId + response, err := me.client.UseMysqlClient(specArgs).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/cdn/service_tencentcloud_cdn.go b/tencentcloud/services/cdn/service_tencentcloud_cdn.go index 42d4ed34f2..3b2bac2a33 100644 --- a/tencentcloud/services/cdn/service_tencentcloud_cdn.go +++ b/tencentcloud/services/cdn/service_tencentcloud_cdn.go @@ -41,7 +41,9 @@ func (me *CdnService) DescribeDomainsConfigByDomain(ctx context.Context, domain request.Filters = append(request.Filters, filter) ratelimit.Check(request.GetAction()) - response, err := me.client.UseCdnClient().DescribeDomainsConfig(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = domain + response, err := me.client.UseCdnClient(specArgs).DescribeDomainsConfig(request) if err != nil { if sdkErr, ok := err.(*errors.TencentCloudSDKError); ok { if sdkErr.Code == CDN_HOST_NOT_FOUND { diff --git a/tencentcloud/services/cfw/service_tencentcloud_cfw.go b/tencentcloud/services/cfw/service_tencentcloud_cfw.go index fd81a52735..4b2c853940 100644 --- a/tencentcloud/services/cfw/service_tencentcloud_cfw.go +++ b/tencentcloud/services/cfw/service_tencentcloud_cfw.go @@ -245,8 +245,9 @@ func (me *CfwService) DescribeCfwNatInstanceById(ctx context.Context, natinsId s }() ratelimit.Check(request.GetAction()) - - response, err := me.client.UseCfwClient().DescribeNatFwInstancesInfo(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = natinsId + response, err := me.client.UseCfwClient(specArgs).DescribeNatFwInstancesInfo(request) if err != nil { errRet = err return @@ -442,8 +443,10 @@ func (me *CfwService) DescribeCfwVpcInstanceById(ctx context.Context, fwGroupId }() ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = fwGroupId - response, err := me.client.UseCfwClient().DescribeFwGroupInstanceInfo(request) + response, err := me.client.UseCfwClient(specArgs).DescribeFwGroupInstanceInfo(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/cls/service_tencentcloud_cls.go b/tencentcloud/services/cls/service_tencentcloud_cls.go index dcf454915d..92bf93a255 100644 --- a/tencentcloud/services/cls/service_tencentcloud_cls.go +++ b/tencentcloud/services/cls/service_tencentcloud_cls.go @@ -53,7 +53,9 @@ func (me *ClsService) DescribeClsLogset(ctx context.Context, logsetId string) (l request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseClsClient().DescribeLogsets(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = logsetId + response, err := me.client.UseClsClient(specArgs).DescribeLogsets(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -240,7 +242,9 @@ func (me *ClsService) DescribeClsTopicById(ctx context.Context, topicId string) request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseClsClient().DescribeTopics(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = topicId + response, err := me.client.UseClsClient(specArgs).DescribeTopics(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/es/service_tencentcloud_elasticsearch.go b/tencentcloud/services/es/service_tencentcloud_elasticsearch.go index 044c337a56..2d18a0a7c8 100644 --- a/tencentcloud/services/es/service_tencentcloud_elasticsearch.go +++ b/tencentcloud/services/es/service_tencentcloud_elasticsearch.go @@ -30,7 +30,9 @@ func (me *ElasticsearchService) DescribeInstanceById(ctx context.Context, instan request.InstanceIds = []*string{&instanceId} ratelimit.Check(request.GetAction()) - response, err := me.client.UseEsClient().DescribeInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + response, err := me.client.UseEsClient(specArgs).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/gaap/service_tencentcloud_gaap.go b/tencentcloud/services/gaap/service_tencentcloud_gaap.go index 6a5aba208e..5116be4c05 100644 --- a/tencentcloud/services/gaap/service_tencentcloud_gaap.go +++ b/tencentcloud/services/gaap/service_tencentcloud_gaap.go @@ -586,6 +586,7 @@ func (me *GaapService) DescribeProxies( logId := tccommon.GetLogId(ctx) request := gaap.NewDescribeProxiesRequest() + response := gaap.NewDescribeProxiesResponse() if len(ids) > 0 { request.ProxyIds = common.StringPtrs(ids) } @@ -624,8 +625,15 @@ func (me *GaapService) DescribeProxies( if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) + if len(ids) > 0 { + var specArgs connectivity.IacExtInfo + tmpIds := strings.Join(ids, tccommon.FILED_SP) + specArgs.InstanceId = tmpIds + response, err = me.client.UseGaapClient(specArgs).DescribeProxies(request) + } else { + response, err = me.client.UseGaapClient().DescribeProxies(request) + } - response, err := me.client.UseGaapClient().DescribeProxies(request) if err != nil { count = 0 diff --git a/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go b/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go index 340be3c5d5..7d87daac59 100644 --- a/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go +++ b/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go @@ -40,6 +40,8 @@ func (me *LightHouseService) DescribeLighthouseInstanceById(ctx context.Context, request.InstanceIds = append(request.InstanceIds, helper.String(instanceId)) ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId var offset int64 = 0 var pageSize int64 = 100 @@ -49,7 +51,7 @@ func (me *LightHouseService) DescribeLighthouseInstanceById(ctx context.Context, request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseLighthouseClient().DescribeInstances(request) + response, err := me.client.UseLighthouseClient(specArgs).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go b/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go index ecc346ae25..7c73c76e41 100644 --- a/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go +++ b/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go @@ -755,8 +755,10 @@ func (me *MariadbService) DescribeMariadbDbInstanceDetail(ctx context.Context, i }() request.InstanceId = &instanceId + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId - response, err := me.client.UseMariadbClient().DescribeDBInstanceDetail(request) + response, err := me.client.UseMariadbClient(specArgs).DescribeDBInstanceDetail(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -1125,8 +1127,10 @@ func (me *MariadbService) DescribeMariadbInstanceById(ctx context.Context, insta }() ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId - response, err := me.client.UseMariadbClient().DescribeDBInstances(request) + response, err := me.client.UseMariadbClient(specArgs).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go index 53f0b66baf..2e7bb08fbc 100644 --- a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go +++ b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go @@ -3,10 +3,10 @@ package privatedns import ( "context" "fmt" - "log" - tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" + "log" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" @@ -255,9 +255,11 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf ) request.ZoneId = &id + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = id err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UsePrivateDnsClient().DescribePrivateZone(request) + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UsePrivateDnsClient(specArgs).DescribePrivateZone(request) if e != nil { return tccommon.RetryError(e) } diff --git a/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go b/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go index a448143091..304b45a35e 100644 --- a/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go +++ b/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go @@ -330,9 +330,11 @@ func (me *TdcpgService) DescribeTdcpgClustersByFilter(ctx context.Context, param var ( logId = tccommon.GetLogId(ctx) request = tdcpg.NewDescribeClustersRequest() + response = tdcpg.NewDescribeClustersResponse() indx = 0 currNumber = 1 pageSize = 20 + err error ) defer func() { @@ -342,6 +344,7 @@ func (me *TdcpgService) DescribeTdcpgClustersByFilter(ctx context.Context, param } }() + var tmpId string request.Filters = make([]*tdcpg.Filter, len(param)) for k, v := range param { if k == "cluster_id" { @@ -350,6 +353,7 @@ func (me *TdcpgService) DescribeTdcpgClustersByFilter(ctx context.Context, param Values: []*string{v.(*string)}, } indx++ + tmpId = v.(string) continue } @@ -394,8 +398,14 @@ func (me *TdcpgService) DescribeTdcpgClustersByFilter(ctx context.Context, param for { request.PageNumber = helper.IntUint64(currNumber) request.PageSize = helper.IntUint64(pageSize) + if tmpId != "" { + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = tmpId + response, err = me.client.UseTdcpgClient(specArgs).DescribeClusters(request) + } else { + response, err = me.client.UseTdcpgClient().DescribeClusters(request) + } - response, err := me.client.UseTdcpgClient().DescribeClusters(request) if err != nil { log.Printf("[CRITICAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -422,9 +432,11 @@ func (me *TdcpgService) DescribeTdcpgInstancesByFilter(ctx context.Context, clus var ( logId = tccommon.GetLogId(ctx) request = tdcpg.NewDescribeClusterInstancesRequest() + response = tdcpg.NewDescribeClusterInstancesResponse() indx = 0 currNumber = 1 pageSize = 20 + err error ) defer func() { @@ -434,6 +446,7 @@ func (me *TdcpgService) DescribeTdcpgInstancesByFilter(ctx context.Context, clus } }() + var tmpId string request.Filters = make([]*tdcpg.Filter, len(param)) for k, v := range param { if k == "instance_id" { @@ -442,6 +455,7 @@ func (me *TdcpgService) DescribeTdcpgInstancesByFilter(ctx context.Context, clus Values: []*string{v.(*string)}, } indx++ + tmpId = v.(string) continue } @@ -478,8 +492,13 @@ func (me *TdcpgService) DescribeTdcpgInstancesByFilter(ctx context.Context, clus request.PageNumber = helper.IntUint64(currNumber) request.PageSize = helper.IntUint64(pageSize) request.ClusterId = clusterId - - response, err := me.client.UseTdcpgClient().DescribeClusterInstances(request) + if tmpId != "" { + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = tmpId + response, err = me.client.UseTdcpgClient(specArgs).DescribeClusterInstances(request) + } else { + response, err = me.client.UseTdcpgClient().DescribeClusterInstances(request) + } if err != nil { log.Printf("[CRITICAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/teo/service_tencentcloud_teo.go b/tencentcloud/services/teo/service_tencentcloud_teo.go index 3dd27ba317..10fab3efd2 100644 --- a/tencentcloud/services/teo/service_tencentcloud_teo.go +++ b/tencentcloud/services/teo/service_tencentcloud_teo.go @@ -3,9 +3,8 @@ package teo import ( "context" "fmt" - "log" - tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "log" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901" @@ -47,6 +46,8 @@ func (me *TeoService) DescribeTeoZone(ctx context.Context, zoneId string) (zone } ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = zoneId var offset int64 = 0 var pageSize int64 = 100 @@ -56,7 +57,7 @@ func (me *TeoService) DescribeTeoZone(ctx context.Context, zoneId string) (zone request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseTeoClient().DescribeZones(request) + response, err := me.client.UseTeoClient(specArgs).DescribeZones(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/vpc/resource_tc_nat_gateway.go b/tencentcloud/services/vpc/resource_tc_nat_gateway.go index f0f3a4ba5f..eb15753d3d 100644 --- a/tencentcloud/services/vpc/resource_tc_nat_gateway.go +++ b/tencentcloud/services/vpc/resource_tc_nat_gateway.go @@ -1,11 +1,11 @@ package vpc import ( - tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" - svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" - "context" "fmt" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" + svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" "log" "time" @@ -218,7 +218,9 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{} request.NatGatewayIds = []*string{&natGatewayId} var response *vpc.DescribeNatGatewaysResponse err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DescribeNatGateways(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = natGatewayId + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(specArgs).DescribeNatGateways(request) if e != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), e.Error()) diff --git a/tencentcloud/services/vpc/service_tencentcloud_vpc.go b/tencentcloud/services/vpc/service_tencentcloud_vpc.go index 41737d578c..860525aa5a 100644 --- a/tencentcloud/services/vpc/service_tencentcloud_vpc.go +++ b/tencentcloud/services/vpc/service_tencentcloud_vpc.go @@ -2911,6 +2911,7 @@ func (me *VpcService) describeEnis( logId := tccommon.GetLogId(ctx) request := vpc.NewDescribeNetworkInterfacesRequest() + response := vpc.NewDescribeNetworkInterfacesResponse() if len(ids) > 0 { request.NetworkInterfaceIds = common.StringPtrs(ids) @@ -2987,8 +2988,14 @@ func (me *VpcService) describeEnis( for count == ENI_DESCRIBE_LIMIT { if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - - response, err := me.client.UseVpcClient().DescribeNetworkInterfaces(request) + if len(ids) > 0 { + var specArgs connectivity.IacExtInfo + tmpIds := strings.Join(ids, tccommon.FILED_SP) + specArgs.InstanceId = tmpIds + response, err = me.client.UseVpcClient(specArgs).DescribeNetworkInterfaces(request) + } else { + response, err = me.client.UseVpcClient().DescribeNetworkInterfaces(request) + } if err != nil { count = 0 @@ -4179,7 +4186,9 @@ func (me *VpcService) DescribeVpngwById(ctx context.Context, vpngwId string) (ha ) request.VpnGatewayIds = []*string{&vpngwId} err = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - response, err = me.client.UseVpcClient().DescribeVpnGateways(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = vpngwId + response, err = me.client.UseVpcClient(specArgs).DescribeVpnGateways(request) if err != nil { ee, ok := err.(*sdkErrors.TencentCloudSDKError) if !ok { diff --git a/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go b/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go index 4c40e9e095..2e33927108 100644 --- a/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go +++ b/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go @@ -2,6 +2,7 @@ package vpn import ( tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" svcvpc "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/vpc" @@ -135,7 +136,9 @@ func resourceTencentCloudVpnCustomerGatewayRead(d *schema.ResourceData, meta int request.CustomerGatewayIds = []*string{&customerGatewayId} var response *vpc.DescribeCustomerGatewaysResponse err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient().DescribeCustomerGateways(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = customerGatewayId + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(specArgs).DescribeCustomerGateways(request) if e != nil { ee, ok := e.(*errors.TencentCloudSDKError) if !ok { diff --git a/tencentcloud/services/waf/service_tencentcloud_waf.go b/tencentcloud/services/waf/service_tencentcloud_waf.go index f4f8113ffb..8432fc0011 100644 --- a/tencentcloud/services/waf/service_tencentcloud_waf.go +++ b/tencentcloud/services/waf/service_tencentcloud_waf.go @@ -625,8 +625,9 @@ func (me *WafService) DescribeWafInstanceById(ctx context.Context, instanceId st }() ratelimit.Check(request.GetAction()) - - response, err := me.client.UseWafClient().DescribeInstances(request) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = instanceId + response, err := me.client.UseWafClient(specArgs).DescribeInstances(request) if err != nil { errRet = err return From 0adda67c118a0ce14c0a014407ba520084b85b76 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Mon, 11 Mar 2024 17:36:28 +0800 Subject: [PATCH 4/9] add --- .changelog/2544.txt | 3 + tencentcloud/connectivity/client.go | 205 ++++++++++++++++++ tencentcloud/connectivity/transport.go | 9 - .../services/cls/service_tencentcloud_cls.go | 4 +- .../resource_tc_private_dns_zone.go | 3 +- .../services/teo/service_tencentcloud_teo.go | 3 +- .../services/vpc/resource_tc_nat_gateway.go | 5 +- 7 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 .changelog/2544.txt diff --git a/.changelog/2544.txt b/.changelog/2544.txt new file mode 100644 index 0000000000..829e81bdfd --- /dev/null +++ b/.changelog/2544.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/client: Adjusting the client structure +``` \ No newline at end of file diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 3eb1459607..257d0d4b14 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -297,6 +297,14 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { // UseMysqlClient returns mysql(cdb) client for service func (me *TencentCloudClient) UseMysqlClient(specArgs ...IacExtInfo) *cdb.Client { if me.mysqlConn != nil { + if len(specArgs) != 0 { + me.mysqlConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.mysqlConn } @@ -342,6 +350,14 @@ func (me *TencentCloudClient) UseAsClient() *as.Client { // UseVpcClient returns vpc client for service func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { if me.vpcConn != nil { + if len(specArgs) != 0 { + me.vpcConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.vpcConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.vpcConn } @@ -361,6 +377,14 @@ func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { // UseCbsClient returns cbs client for service func (me *TencentCloudClient) UseCbsClient(specArgs ...IacExtInfo) *cbs.Client { if me.cbsConn != nil { + if len(specArgs) != 0 { + me.cbsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cbsConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.cbsConn } @@ -394,6 +418,14 @@ func (me *TencentCloudClient) UseDcClient() *dc.Client { // UseMongodbClient returns mongodb client for service func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb.Client { if me.mongodbConn != nil { + if len(specArgs) != 0 { + me.mongodbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.mongodbConn } @@ -413,6 +445,14 @@ func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb. // UseClbClient returns clb client for service func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { if me.clbConn != nil { + if len(specArgs) != 0 { + me.clbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.clbConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.clbConn } @@ -432,6 +472,14 @@ func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { // UseCvmClient returns cvm client for service func (me *TencentCloudClient) UseCvmClient(specArgs ...IacExtInfo) *cvm.Client { if me.cvmConn != nil { + if len(specArgs) != 0 { + me.cvmConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cvmConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.cvmConn } @@ -465,6 +513,14 @@ func (me *TencentCloudClient) UseTagClient() *tag.Client { // UseTkeClient returns tke client for service func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { if me.tkeConn != nil { + if len(specArgs) != 0 { + me.tkeConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tkeConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.tkeConn } @@ -484,6 +540,14 @@ func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { // UseTdmqClient returns Tdmq client for service func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client { if me.tdmqConn != nil { + if len(specArgs) != 0 { + me.tdmqConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.tdmqConn } @@ -503,6 +567,14 @@ func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client // UseGaapClient returns gaap client for service func (me *TencentCloudClient) UseGaapClient(specArgs ...IacExtInfo) *gaap.Client { if me.gaapConn != nil { + if len(specArgs) != 0 { + me.gaapConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.gaapConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.gaapConn } @@ -515,6 +587,7 @@ func (me *TencentCloudClient) UseGaapClient(specArgs ...IacExtInfo) *gaap.Client } else { me.gaapConn.WithHttpTransport(&LogRoundTripper{}) } + return me.gaapConn } @@ -576,6 +649,14 @@ func (me *TencentCloudClient) UseCfsClient() *cfs.Client { // UseScfClient returns scf client for service func (me *TencentCloudClient) UseScfClient(specArgs ...IacExtInfo) *scf.Client { if me.scfConn != nil { + if len(specArgs) != 0 { + me.scfConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.scfConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.scfConn } @@ -621,6 +702,14 @@ func (me *TencentCloudClient) UseDayuClient() *dayu.Client { // UseCdnClient returns cdn client for service func (me *TencentCloudClient) UseCdnClient(specArgs ...IacExtInfo) *cdn.Client { if me.cdnConn != nil { + if len(specArgs) != 0 { + me.cdnConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cdnConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.cdnConn } @@ -653,6 +742,14 @@ func (me *TencentCloudClient) UseMonitorClient() *monitor.Client { // UseEsClient returns es client for service func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { if me.esConn != nil { + if len(specArgs) != 0 { + me.esConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.esConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.esConn } @@ -673,6 +770,14 @@ func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { // UsePostgresqlClient returns postgresql client for service func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postgre.Client { if me.postgreConn != nil { + if len(specArgs) != 0 { + me.postgreConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.postgreConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.postgreConn } @@ -692,6 +797,14 @@ func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postg // UseSqlserverClient returns sqlserver client for service func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlserver.Client { if me.sqlserverConn != nil { + if len(specArgs) != 0 { + me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.sqlserverConn } @@ -711,6 +824,14 @@ func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlser // UseCkafkaClient returns ckafka client for service func (me *TencentCloudClient) UseCkafkaClient(specArgs ...IacExtInfo) *ckafka.Client { if me.ckafkaConn != nil { + if len(specArgs) != 0 { + me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.ckafkaConn } @@ -782,6 +903,14 @@ func (me *TencentCloudClient) UseAPIGatewayClient() *apigateway.Client { // UseTCRClient returns apigateway client for service func (me *TencentCloudClient) UseTCRClient(specArgs ...IacExtInfo) *tcr.Client { if me.tcrConn != nil { + if len(specArgs) != 0 { + me.tcrConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tcrConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.tcrConn } @@ -864,8 +993,17 @@ func (me *TencentCloudClient) UseEmrClient() *emr.Client { // UseClsClient return CLS client for service func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { if me.clsConn != nil { + if len(specArgs) != 0 { + me.clsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.clsConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.clsConn } + cpf := me.NewClientProfile(300) me.clsConn, _ = cls.NewClient(me.Credential, me.Region, cpf) if len(specArgs) != 0 { @@ -882,8 +1020,17 @@ func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { // UseLighthouseClient return Lighthouse client for service func (me *TencentCloudClient) UseLighthouseClient(specArgs ...IacExtInfo) *lighthouse.Client { if me.lighthouseConn != nil { + if len(specArgs) != 0 { + me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.lighthouseConn } + cpf := me.NewClientProfile(300) me.lighthouseConn, _ = lighthouse.NewClient(me.Credential, me.Region, cpf) if len(specArgs) != 0 { @@ -912,8 +1059,17 @@ func (me *TencentCloudClient) UseDnsPodClient() *dnspod.Client { // UsePrivateDnsClient return PrivateDns client for service func (me *TencentCloudClient) UsePrivateDnsClient(specArgs ...IacExtInfo) *privatedns.Client { if me.privateDnsConn != nil { + if len(specArgs) != 0 { + me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.privateDnsConn } + cpf := me.NewClientProfile(300) me.privateDnsConn, _ = privatedns.NewClient(me.Credential, me.Region, cpf) if len(specArgs) != 0 { @@ -968,6 +1124,14 @@ func (me *TencentCloudClient) UseTemClient() *tem.Client { // UseTeoClient returns teo client for service func (me *TencentCloudClient) UseTeoClient(specArgs ...IacExtInfo) *teo.Client { if me.teoConn != nil { + if len(specArgs) != 0 { + me.teoConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.teoConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.teoConn } @@ -1065,6 +1229,14 @@ func (me *TencentCloudClient) UseCatClient() *cat.Client { // UseMariadbClient returns mariadb client for service func (me *TencentCloudClient) UseMariadbClient(specArgs ...IacExtInfo) *mariadb.Client { if me.mariadbConn != nil { + if len(specArgs) != 0 { + me.mariadbConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.mariadbConn } @@ -1123,6 +1295,14 @@ func (me *TencentCloudClient) UseOrganizationClient() *organization.Client { // UseTdcpgClient returns tdcpg client for service func (me *TencentCloudClient) UseTdcpgClient(specArgs ...IacExtInfo) *tdcpg.Client { if me.tdcpgConn != nil { + if len(specArgs) != 0 { + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.tdcpgConn } @@ -1135,6 +1315,7 @@ func (me *TencentCloudClient) UseTdcpgClient(specArgs ...IacExtInfo) *tdcpg.Clie } else { me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) } + return me.tdcpgConn } @@ -1350,6 +1531,14 @@ func (me *TencentCloudClient) UseCiamClient() *ciam.Client { // UseTseClient returns tse client for service func (me *TencentCloudClient) UseTseClient(specArgs ...IacExtInfo) *tse.Client { if me.tseConn != nil { + if len(specArgs) != 0 { + me.tseConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.tseConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.tseConn } @@ -1425,6 +1614,14 @@ func (me *TencentCloudClient) UseWedataClient() *wedata.Client { func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { if me.wafConn != nil { + if len(specArgs) != 0 { + me.wafConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.wafConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.wafConn } @@ -1444,6 +1641,14 @@ func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { func (me *TencentCloudClient) UseCfwClient(specArgs ...IacExtInfo) *cfw.Client { if me.cfwConn != nil { + if len(specArgs) != 0 { + me.cfwConn.WithHttpTransport(&LogRoundTripper{ + InstanceId: specArgs[0].InstanceId, + }) + } else { + me.cfwConn.WithHttpTransport(&LogRoundTripper{}) + } + return me.cfwConn } diff --git a/tencentcloud/connectivity/transport.go b/tencentcloud/connectivity/transport.go index 01e0bb1b47..61b9fe0970 100644 --- a/tencentcloud/connectivity/transport.go +++ b/tencentcloud/connectivity/transport.go @@ -61,15 +61,6 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp } request.Header.Set("X-TC-RequestClient", iacExtInfoStr) - - fmt.Println(1111111111) - fmt.Println(1111111111) - fmt.Println(1111111111) - fmt.Println(request.Header.Get("X-TC-RequestClient")) - fmt.Println(1111111111) - fmt.Println(1111111111) - fmt.Println(1111111111) - inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName])) requestBody, errRet := ioutil.ReadAll(bodyReader) if errRet != nil { diff --git a/tencentcloud/services/cls/service_tencentcloud_cls.go b/tencentcloud/services/cls/service_tencentcloud_cls.go index 92bf93a255..d44d846a6b 100644 --- a/tencentcloud/services/cls/service_tencentcloud_cls.go +++ b/tencentcloud/services/cls/service_tencentcloud_cls.go @@ -232,6 +232,8 @@ func (me *ClsService) DescribeClsTopicById(ctx context.Context, topicId string) }, } ratelimit.Check(request.GetAction()) + var specArgs connectivity.IacExtInfo + specArgs.InstanceId = topicId var ( offset int64 = 0 pageSize int64 = 100 @@ -242,8 +244,6 @@ func (me *ClsService) DescribeClsTopicById(ctx context.Context, topicId string) request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = topicId response, err := me.client.UseClsClient(specArgs).DescribeTopics(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", diff --git a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go index 8da33e11c4..0af7340e1e 100644 --- a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go +++ b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go @@ -3,10 +3,11 @@ package privatedns import ( "context" "fmt" + "log" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" - "log" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" diff --git a/tencentcloud/services/teo/service_tencentcloud_teo.go b/tencentcloud/services/teo/service_tencentcloud_teo.go index 10fab3efd2..ee3fe19139 100644 --- a/tencentcloud/services/teo/service_tencentcloud_teo.go +++ b/tencentcloud/services/teo/service_tencentcloud_teo.go @@ -3,9 +3,10 @@ package teo import ( "context" "fmt" - tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" "log" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901" diff --git a/tencentcloud/services/vpc/resource_tc_nat_gateway.go b/tencentcloud/services/vpc/resource_tc_nat_gateway.go index eb15753d3d..74e43d7926 100644 --- a/tencentcloud/services/vpc/resource_tc_nat_gateway.go +++ b/tencentcloud/services/vpc/resource_tc_nat_gateway.go @@ -3,11 +3,12 @@ package vpc import ( "context" "fmt" + "log" + "time" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" svctag "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/tag" - "log" - "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" From 33f80d4cf2a59c336303106b06716c4f1b490811 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Mon, 11 Mar 2024 18:52:12 +0800 Subject: [PATCH 5/9] add --- tencentcloud/services/cvm/resource_tc_instance.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tencentcloud/services/cvm/resource_tc_instance.go b/tencentcloud/services/cvm/resource_tc_instance.go index edec79a4eb..dc99a56991 100644 --- a/tencentcloud/services/cvm/resource_tc_instance.go +++ b/tencentcloud/services/cvm/resource_tc_instance.go @@ -24,8 +24,6 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) -var importFlag = false - func ResourceTencentCloudInstance() *schema.Resource { return &schema.Resource{ Create: resourceTencentCloudInstanceCreate, @@ -33,16 +31,7 @@ func ResourceTencentCloudInstance() *schema.Resource { Update: resourceTencentCloudInstanceUpdate, Delete: resourceTencentCloudInstanceDelete, Importer: &schema.ResourceImporter{ - State: func(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { - importFlag = true - defaultValues := map[string]interface{}{} - - for k, v := range defaultValues { - _ = d.Set(k, v) - } - - return []*schema.ResourceData{d}, nil - }, + State: schema.ImportStatePassthrough, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(15 * time.Minute), From 47adb69ab903f94806cef41071a6b7852f98be6e Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 13 Mar 2024 15:18:34 +0800 Subject: [PATCH 6/9] add --- tencentcloud/connectivity/client.go | 250 +++++++++--------- .../services/cbs/service_tencentcloud_cbs.go | 14 +- .../cdb/service_tencentcloud_mysql.go | 6 +- .../services/cdn/service_tencentcloud_cdn.go | 6 +- .../services/cfw/service_tencentcloud_cfw.go | 13 +- .../ckafka/service_tencentcloud_ckafka.go | 6 +- .../services/clb/service_tencentcloud_clb.go | 6 +- .../services/cls/service_tencentcloud_cls.go | 12 +- .../services/cvm/service_tencentcloud_cvm.go | 7 +- .../es/service_tencentcloud_elasticsearch.go | 6 +- .../gaap/service_tencentcloud_gaap.go | 6 +- .../service_tencentcloud_lighthouse.go | 6 +- .../mariadb/service_tencentcloud_mariadb.go | 14 +- .../mongodb/service_tencentcloud_mongodb.go | 7 +- .../service_tencentcloud_postgresql.go | 6 +- .../resource_tc_private_dns_zone.go | 7 +- .../services/scf/service_tencentcloud_scf.go | 8 +- .../service_tencentcloud_sqlserver.go | 6 +- .../services/tcr/service_tencentcloud_tcr.go | 7 +- .../tdcpg/service_tencentcloud_tdcpg.go | 12 +- .../tdmq/service_tencentcloud_tdmq.go | 27 +- .../services/teo/service_tencentcloud_teo.go | 6 +- .../services/tke/service_tencentcloud_tke.go | 7 +- .../services/tse/service_tencentcloud_tse.go | 6 +- .../services/vpc/resource_tc_nat_gateway.go | 6 +- .../services/vpc/service_tencentcloud_vpc.go | 6 +- .../vpn/resource_tc_vpn_customer_gateway.go | 6 +- .../services/waf/service_tencentcloud_waf.go | 6 +- 28 files changed, 230 insertions(+), 245 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 257d0d4b14..990a0ee10a 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -295,11 +295,11 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { } // UseMysqlClient returns mysql(cdb) client for service -func (me *TencentCloudClient) UseMysqlClient(specArgs ...IacExtInfo) *cdb.Client { +func (me *TencentCloudClient) UseMysqlClient(iacExtInfo ...IacExtInfo) *cdb.Client { if me.mysqlConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mysqlConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) @@ -310,9 +310,9 @@ func (me *TencentCloudClient) UseMysqlClient(specArgs ...IacExtInfo) *cdb.Client cpf := me.NewClientProfile(300) me.mysqlConn, _ = cdb.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mysqlConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) @@ -348,11 +348,11 @@ func (me *TencentCloudClient) UseAsClient() *as.Client { } // UseVpcClient returns vpc client for service -func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { +func (me *TencentCloudClient) UseVpcClient(iacExtInfo ...IacExtInfo) *vpc.Client { if me.vpcConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.vpcConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.vpcConn.WithHttpTransport(&LogRoundTripper{}) @@ -363,9 +363,9 @@ func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { cpf := me.NewClientProfile(300) me.vpcConn, _ = vpc.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.vpcConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.vpcConn.WithHttpTransport(&LogRoundTripper{}) @@ -375,11 +375,11 @@ func (me *TencentCloudClient) UseVpcClient(specArgs ...IacExtInfo) *vpc.Client { } // UseCbsClient returns cbs client for service -func (me *TencentCloudClient) UseCbsClient(specArgs ...IacExtInfo) *cbs.Client { +func (me *TencentCloudClient) UseCbsClient(iacExtInfo ...IacExtInfo) *cbs.Client { if me.cbsConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cbsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cbsConn.WithHttpTransport(&LogRoundTripper{}) @@ -391,9 +391,9 @@ func (me *TencentCloudClient) UseCbsClient(specArgs ...IacExtInfo) *cbs.Client { var reqTimeout = getEnvDefault(PROVIDER_CBS_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cbsConn, _ = cbs.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cbsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cbsConn.WithHttpTransport(&LogRoundTripper{}) @@ -416,11 +416,11 @@ func (me *TencentCloudClient) UseDcClient() *dc.Client { } // UseMongodbClient returns mongodb client for service -func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb.Client { +func (me *TencentCloudClient) UseMongodbClient(iacExtInfo ...IacExtInfo) *mongodb.Client { if me.mongodbConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mongodbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) @@ -431,9 +431,9 @@ func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb. cpf := me.NewClientProfile(300) me.mongodbConn, _ = mongodb.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mongodbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) @@ -443,11 +443,11 @@ func (me *TencentCloudClient) UseMongodbClient(specArgs ...IacExtInfo) *mongodb. } // UseClbClient returns clb client for service -func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { +func (me *TencentCloudClient) UseClbClient(iacExtInfo ...IacExtInfo) *clb.Client { if me.clbConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.clbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.clbConn.WithHttpTransport(&LogRoundTripper{}) @@ -458,9 +458,9 @@ func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { cpf := me.NewClientProfile(300) me.clbConn, _ = clb.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.clbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.clbConn.WithHttpTransport(&LogRoundTripper{}) @@ -470,11 +470,11 @@ func (me *TencentCloudClient) UseClbClient(specArgs ...IacExtInfo) *clb.Client { } // UseCvmClient returns cvm client for service -func (me *TencentCloudClient) UseCvmClient(specArgs ...IacExtInfo) *cvm.Client { +func (me *TencentCloudClient) UseCvmClient(iacExtInfo ...IacExtInfo) *cvm.Client { if me.cvmConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cvmConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cvmConn.WithHttpTransport(&LogRoundTripper{}) @@ -486,9 +486,9 @@ func (me *TencentCloudClient) UseCvmClient(specArgs ...IacExtInfo) *cvm.Client { var reqTimeout = getEnvDefault(PROVIDER_CVM_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cvmConn, _ = cvm.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cvmConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cvmConn.WithHttpTransport(&LogRoundTripper{}) @@ -511,11 +511,11 @@ func (me *TencentCloudClient) UseTagClient() *tag.Client { } // UseTkeClient returns tke client for service -func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { +func (me *TencentCloudClient) UseTkeClient(iacExtInfo ...IacExtInfo) *tke.Client { if me.tkeConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tkeConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tkeConn.WithHttpTransport(&LogRoundTripper{}) @@ -526,9 +526,9 @@ func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { cpf := me.NewClientProfile(300) me.tkeConn, _ = tke.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tkeConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tkeConn.WithHttpTransport(&LogRoundTripper{}) @@ -538,11 +538,11 @@ func (me *TencentCloudClient) UseTkeClient(specArgs ...IacExtInfo) *tke.Client { } // UseTdmqClient returns Tdmq client for service -func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client { +func (me *TencentCloudClient) UseTdmqClient(iacExtInfo ...IacExtInfo) *tdmq.Client { if me.tdmqConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tdmqConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) @@ -553,9 +553,9 @@ func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client cpf := me.NewClientProfile(300) me.tdmqConn, _ = tdmq.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tdmqConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) @@ -565,11 +565,11 @@ func (me *TencentCloudClient) UseTdmqClient(specArgs ...IacExtInfo) *tdmq.Client } // UseGaapClient returns gaap client for service -func (me *TencentCloudClient) UseGaapClient(specArgs ...IacExtInfo) *gaap.Client { +func (me *TencentCloudClient) UseGaapClient(iacExtInfo ...IacExtInfo) *gaap.Client { if me.gaapConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.gaapConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.gaapConn.WithHttpTransport(&LogRoundTripper{}) @@ -580,9 +580,9 @@ func (me *TencentCloudClient) UseGaapClient(specArgs ...IacExtInfo) *gaap.Client cpf := me.NewClientProfile(300) me.gaapConn, _ = gaap.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.gaapConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.gaapConn.WithHttpTransport(&LogRoundTripper{}) @@ -647,11 +647,11 @@ func (me *TencentCloudClient) UseCfsClient() *cfs.Client { } // UseScfClient returns scf client for service -func (me *TencentCloudClient) UseScfClient(specArgs ...IacExtInfo) *scf.Client { +func (me *TencentCloudClient) UseScfClient(iacExtInfo ...IacExtInfo) *scf.Client { if me.scfConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.scfConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.scfConn.WithHttpTransport(&LogRoundTripper{}) @@ -662,9 +662,9 @@ func (me *TencentCloudClient) UseScfClient(specArgs ...IacExtInfo) *scf.Client { cpf := me.NewClientProfile(300) me.scfConn, _ = scf.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.scfConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.scfConn.WithHttpTransport(&LogRoundTripper{}) @@ -700,11 +700,11 @@ func (me *TencentCloudClient) UseDayuClient() *dayu.Client { } // UseCdnClient returns cdn client for service -func (me *TencentCloudClient) UseCdnClient(specArgs ...IacExtInfo) *cdn.Client { +func (me *TencentCloudClient) UseCdnClient(iacExtInfo ...IacExtInfo) *cdn.Client { if me.cdnConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cdnConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cdnConn.WithHttpTransport(&LogRoundTripper{}) @@ -715,9 +715,9 @@ func (me *TencentCloudClient) UseCdnClient(specArgs ...IacExtInfo) *cdn.Client { cpf := me.NewClientProfile(300) me.cdnConn, _ = cdn.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cdnConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cdnConn.WithHttpTransport(&LogRoundTripper{}) @@ -740,11 +740,11 @@ func (me *TencentCloudClient) UseMonitorClient() *monitor.Client { } // UseEsClient returns es client for service -func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { +func (me *TencentCloudClient) UseEsClient(iacExtInfo ...IacExtInfo) *es.Client { if me.esConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.esConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.esConn.WithHttpTransport(&LogRoundTripper{}) @@ -756,9 +756,9 @@ func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.esConn, _ = es.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.esConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.esConn.WithHttpTransport(&LogRoundTripper{}) @@ -768,11 +768,11 @@ func (me *TencentCloudClient) UseEsClient(specArgs ...IacExtInfo) *es.Client { } // UsePostgresqlClient returns postgresql client for service -func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postgre.Client { +func (me *TencentCloudClient) UsePostgresqlClient(iacExtInfo ...IacExtInfo) *postgre.Client { if me.postgreConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.postgreConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.postgreConn.WithHttpTransport(&LogRoundTripper{}) @@ -783,9 +783,9 @@ func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postg cpf := me.NewClientProfile(300) me.postgreConn, _ = postgre.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.postgreConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.postgreConn.WithHttpTransport(&LogRoundTripper{}) @@ -795,11 +795,11 @@ func (me *TencentCloudClient) UsePostgresqlClient(specArgs ...IacExtInfo) *postg } // UseSqlserverClient returns sqlserver client for service -func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlserver.Client { +func (me *TencentCloudClient) UseSqlserverClient(iacExtInfo ...IacExtInfo) *sqlserver.Client { if me.sqlserverConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) @@ -810,9 +810,9 @@ func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlser cpf := me.NewClientProfile(300) me.sqlserverConn, _ = sqlserver.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) @@ -822,11 +822,11 @@ func (me *TencentCloudClient) UseSqlserverClient(specArgs ...IacExtInfo) *sqlser } // UseCkafkaClient returns ckafka client for service -func (me *TencentCloudClient) UseCkafkaClient(specArgs ...IacExtInfo) *ckafka.Client { +func (me *TencentCloudClient) UseCkafkaClient(iacExtInfo ...IacExtInfo) *ckafka.Client { if me.ckafkaConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) @@ -837,9 +837,9 @@ func (me *TencentCloudClient) UseCkafkaClient(specArgs ...IacExtInfo) *ckafka.Cl cpf := me.NewClientProfile(300) me.ckafkaConn, _ = ckafka.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) @@ -901,11 +901,11 @@ func (me *TencentCloudClient) UseAPIGatewayClient() *apigateway.Client { } // UseTCRClient returns apigateway client for service -func (me *TencentCloudClient) UseTCRClient(specArgs ...IacExtInfo) *tcr.Client { +func (me *TencentCloudClient) UseTCRClient(iacExtInfo ...IacExtInfo) *tcr.Client { if me.tcrConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tcrConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tcrConn.WithHttpTransport(&LogRoundTripper{}) @@ -916,9 +916,9 @@ func (me *TencentCloudClient) UseTCRClient(specArgs ...IacExtInfo) *tcr.Client { cpf := me.NewClientProfile(300) me.tcrConn, _ = tcr.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tcrConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tcrConn.WithHttpTransport(&LogRoundTripper{}) @@ -991,11 +991,11 @@ func (me *TencentCloudClient) UseEmrClient() *emr.Client { } // UseClsClient return CLS client for service -func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { +func (me *TencentCloudClient) UseClsClient(iacExtInfo ...IacExtInfo) *cls.Client { if me.clsConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.clsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.clsConn.WithHttpTransport(&LogRoundTripper{}) @@ -1006,9 +1006,9 @@ func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { cpf := me.NewClientProfile(300) me.clsConn, _ = cls.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.clsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.clsConn.WithHttpTransport(&LogRoundTripper{}) @@ -1018,11 +1018,11 @@ func (me *TencentCloudClient) UseClsClient(specArgs ...IacExtInfo) *cls.Client { } // UseLighthouseClient return Lighthouse client for service -func (me *TencentCloudClient) UseLighthouseClient(specArgs ...IacExtInfo) *lighthouse.Client { +func (me *TencentCloudClient) UseLighthouseClient(iacExtInfo ...IacExtInfo) *lighthouse.Client { if me.lighthouseConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) @@ -1033,9 +1033,9 @@ func (me *TencentCloudClient) UseLighthouseClient(specArgs ...IacExtInfo) *light cpf := me.NewClientProfile(300) me.lighthouseConn, _ = lighthouse.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) @@ -1057,11 +1057,11 @@ func (me *TencentCloudClient) UseDnsPodClient() *dnspod.Client { } // UsePrivateDnsClient return PrivateDns client for service -func (me *TencentCloudClient) UsePrivateDnsClient(specArgs ...IacExtInfo) *privatedns.Client { +func (me *TencentCloudClient) UsePrivateDnsClient(iacExtInfo ...IacExtInfo) *privatedns.Client { if me.privateDnsConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) @@ -1072,9 +1072,9 @@ func (me *TencentCloudClient) UsePrivateDnsClient(specArgs ...IacExtInfo) *priva cpf := me.NewClientProfile(300) me.privateDnsConn, _ = privatedns.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) @@ -1122,11 +1122,11 @@ func (me *TencentCloudClient) UseTemClient() *tem.Client { } // UseTeoClient returns teo client for service -func (me *TencentCloudClient) UseTeoClient(specArgs ...IacExtInfo) *teo.Client { +func (me *TencentCloudClient) UseTeoClient(iacExtInfo ...IacExtInfo) *teo.Client { if me.teoConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.teoConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.teoConn.WithHttpTransport(&LogRoundTripper{}) @@ -1137,9 +1137,9 @@ func (me *TencentCloudClient) UseTeoClient(specArgs ...IacExtInfo) *teo.Client { cpf := me.NewClientProfile(300) me.teoConn, _ = teo.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.teoConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.teoConn.WithHttpTransport(&LogRoundTripper{}) @@ -1227,11 +1227,11 @@ func (me *TencentCloudClient) UseCatClient() *cat.Client { } // UseMariadbClient returns mariadb client for service -func (me *TencentCloudClient) UseMariadbClient(specArgs ...IacExtInfo) *mariadb.Client { +func (me *TencentCloudClient) UseMariadbClient(iacExtInfo ...IacExtInfo) *mariadb.Client { if me.mariadbConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mariadbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) @@ -1242,9 +1242,9 @@ func (me *TencentCloudClient) UseMariadbClient(specArgs ...IacExtInfo) *mariadb. cpf := me.NewClientProfile(300) me.mariadbConn, _ = mariadb.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.mariadbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) @@ -1293,11 +1293,11 @@ func (me *TencentCloudClient) UseOrganizationClient() *organization.Client { } // UseTdcpgClient returns tdcpg client for service -func (me *TencentCloudClient) UseTdcpgClient(specArgs ...IacExtInfo) *tdcpg.Client { +func (me *TencentCloudClient) UseTdcpgClient(iacExtInfo ...IacExtInfo) *tdcpg.Client { if me.tdcpgConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) @@ -1308,9 +1308,9 @@ func (me *TencentCloudClient) UseTdcpgClient(specArgs ...IacExtInfo) *tdcpg.Clie cpf := me.NewClientProfile(300) me.tdcpgConn, _ = tdcpg.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) @@ -1529,11 +1529,11 @@ func (me *TencentCloudClient) UseCiamClient() *ciam.Client { } // UseTseClient returns tse client for service -func (me *TencentCloudClient) UseTseClient(specArgs ...IacExtInfo) *tse.Client { +func (me *TencentCloudClient) UseTseClient(iacExtInfo ...IacExtInfo) *tse.Client { if me.tseConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tseConn.WithHttpTransport(&LogRoundTripper{}) @@ -1545,9 +1545,9 @@ func (me *TencentCloudClient) UseTseClient(specArgs ...IacExtInfo) *tse.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.tseConn, _ = tse.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.tseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.tseConn.WithHttpTransport(&LogRoundTripper{}) @@ -1612,11 +1612,11 @@ func (me *TencentCloudClient) UseWedataClient() *wedata.Client { return me.wedataConn } -func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { +func (me *TencentCloudClient) UseWafClient(iacExtInfo ...IacExtInfo) *waf.Client { if me.wafConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.wafConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.wafConn.WithHttpTransport(&LogRoundTripper{}) @@ -1628,9 +1628,9 @@ func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.wafConn, _ = waf.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.wafConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.wafConn.WithHttpTransport(&LogRoundTripper{}) @@ -1639,11 +1639,11 @@ func (me *TencentCloudClient) UseWafClient(specArgs ...IacExtInfo) *waf.Client { return me.wafConn } -func (me *TencentCloudClient) UseCfwClient(specArgs ...IacExtInfo) *cfw.Client { +func (me *TencentCloudClient) UseCfwClient(iacExtInfo ...IacExtInfo) *cfw.Client { if me.cfwConn != nil { - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cfwConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cfwConn.WithHttpTransport(&LogRoundTripper{}) @@ -1655,9 +1655,9 @@ func (me *TencentCloudClient) UseCfwClient(specArgs ...IacExtInfo) *cfw.Client { cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.cfwConn, _ = cfw.NewClient(me.Credential, me.Region, cpf) - if len(specArgs) != 0 { + if len(iacExtInfo) != 0 { me.cfwConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: specArgs[0].InstanceId, + InstanceId: iacExtInfo[0].InstanceId, }) } else { me.cfwConn.WithHttpTransport(&LogRoundTripper{}) diff --git a/tencentcloud/services/cbs/service_tencentcloud_cbs.go b/tencentcloud/services/cbs/service_tencentcloud_cbs.go index d206ff9b36..72dcf7e017 100644 --- a/tencentcloud/services/cbs/service_tencentcloud_cbs.go +++ b/tencentcloud/services/cbs/service_tencentcloud_cbs.go @@ -52,10 +52,9 @@ func (me *CbsService) DescribeDiskById(ctx context.Context, diskId string) (disk request.Limit = helper.IntUint64(100) ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = diskId - - response, err := me.client.UseCbsClient(specArgs).DescribeDisks(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = diskId + response, err := me.client.UseCbsClient(iacExtInfo).DescribeDisks(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -85,14 +84,13 @@ func (me *CbsService) DescribeDiskList(ctx context.Context, diskIds []*string) ( request.Limit = helper.IntUint64(100) ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo + var iacExtInfo connectivity.IacExtInfo tmpList := make([]string, len(diskIds)) for k, v := range diskIds { tmpList[k] = *v } - specArgs.InstanceId = strings.Join(tmpList, tccommon.FILED_SP) - - response, err := me.client.UseCbsClient(specArgs).DescribeDisks(request) + iacExtInfo.InstanceId = strings.Join(tmpList, tccommon.FILED_SP) + response, err := me.client.UseCbsClient(iacExtInfo).DescribeDisks(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/cdb/service_tencentcloud_mysql.go b/tencentcloud/services/cdb/service_tencentcloud_mysql.go index 46b13a029c..ce39ea5756 100644 --- a/tencentcloud/services/cdb/service_tencentcloud_mysql.go +++ b/tencentcloud/services/cdb/service_tencentcloud_mysql.go @@ -810,9 +810,9 @@ func (me *MysqlService) _innerDescribeDBInstanceById(ctx context.Context, mysqlI } }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = mysqlId - response, err := me.client.UseMysqlClient(specArgs).DescribeDBInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = mysqlId + response, err := me.client.UseMysqlClient(iacExtInfo).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/cdn/service_tencentcloud_cdn.go b/tencentcloud/services/cdn/service_tencentcloud_cdn.go index 3b2bac2a33..5559f6cf52 100644 --- a/tencentcloud/services/cdn/service_tencentcloud_cdn.go +++ b/tencentcloud/services/cdn/service_tencentcloud_cdn.go @@ -41,9 +41,9 @@ func (me *CdnService) DescribeDomainsConfigByDomain(ctx context.Context, domain request.Filters = append(request.Filters, filter) ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = domain - response, err := me.client.UseCdnClient(specArgs).DescribeDomainsConfig(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = domain + response, err := me.client.UseCdnClient(iacExtInfo).DescribeDomainsConfig(request) if err != nil { if sdkErr, ok := err.(*errors.TencentCloudSDKError); ok { if sdkErr.Code == CDN_HOST_NOT_FOUND { diff --git a/tencentcloud/services/cfw/service_tencentcloud_cfw.go b/tencentcloud/services/cfw/service_tencentcloud_cfw.go index 4b2c853940..95be68859a 100644 --- a/tencentcloud/services/cfw/service_tencentcloud_cfw.go +++ b/tencentcloud/services/cfw/service_tencentcloud_cfw.go @@ -245,9 +245,9 @@ func (me *CfwService) DescribeCfwNatInstanceById(ctx context.Context, natinsId s }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = natinsId - response, err := me.client.UseCfwClient(specArgs).DescribeNatFwInstancesInfo(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = natinsId + response, err := me.client.UseCfwClient(iacExtInfo).DescribeNatFwInstancesInfo(request) if err != nil { errRet = err return @@ -443,10 +443,9 @@ func (me *CfwService) DescribeCfwVpcInstanceById(ctx context.Context, fwGroupId }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = fwGroupId - - response, err := me.client.UseCfwClient(specArgs).DescribeFwGroupInstanceInfo(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = fwGroupId + response, err := me.client.UseCfwClient(iacExtInfo).DescribeFwGroupInstanceInfo(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go b/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go index bf70e1b628..530ba54ece 100644 --- a/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go +++ b/tencentcloud/services/ckafka/service_tencentcloud_ckafka.go @@ -89,10 +89,10 @@ func (me *CkafkaService) DescribeCkafkaInstanceById(ctx context.Context, } }() request.InstanceId = &instanceId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId if err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - result, err := me.client.UseCkafkaClient(specArgs).DescribeInstancesDetail(request) + result, err := me.client.UseCkafkaClient(iacExtInfo).DescribeInstancesDetail(request) if err != nil { return tccommon.RetryError(err) } diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index c451762862..6ef4bdd145 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -56,9 +56,9 @@ func (me *ClbService) DescribeLoadBalancerById(ctx context.Context, clbId string request := clb.NewDescribeLoadBalancersRequest() request.LoadBalancerIds = []*string{&clbId} ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = clbId - response, err := me.client.UseClbClient(specArgs).DescribeLoadBalancers(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = clbId + response, err := me.client.UseClbClient(iacExtInfo).DescribeLoadBalancers(request) if err != nil { errRet = errors.WithStack(err) return diff --git a/tencentcloud/services/cls/service_tencentcloud_cls.go b/tencentcloud/services/cls/service_tencentcloud_cls.go index d44d846a6b..2027b9ba1d 100644 --- a/tencentcloud/services/cls/service_tencentcloud_cls.go +++ b/tencentcloud/services/cls/service_tencentcloud_cls.go @@ -48,14 +48,14 @@ func (me *ClsService) DescribeClsLogset(ctx context.Context, logsetId string) (l var offset int64 = 0 var pageSize int64 = 100 instances := make([]*cls.LogsetInfo, 0) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = logsetId for { request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = logsetId - response, err := me.client.UseClsClient(specArgs).DescribeLogsets(request) + response, err := me.client.UseClsClient(iacExtInfo).DescribeLogsets(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -232,8 +232,8 @@ func (me *ClsService) DescribeClsTopicById(ctx context.Context, topicId string) }, } ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = topicId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = topicId var ( offset int64 = 0 pageSize int64 = 100 @@ -244,7 +244,7 @@ func (me *ClsService) DescribeClsTopicById(ctx context.Context, topicId string) request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseClsClient(specArgs).DescribeTopics(request) + response, err := me.client.UseClsClient(iacExtInfo).DescribeTopics(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/cvm/service_tencentcloud_cvm.go b/tencentcloud/services/cvm/service_tencentcloud_cvm.go index 6984db614c..071d5d8f1f 100644 --- a/tencentcloud/services/cvm/service_tencentcloud_cvm.go +++ b/tencentcloud/services/cvm/service_tencentcloud_cvm.go @@ -69,11 +69,10 @@ func (me *CvmService) DescribeInstanceById(ctx context.Context, instanceId strin request := cvm.NewDescribeInstancesRequest() request.InstanceIds = []*string{&instanceId} - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId ratelimit.Check(request.GetAction()) - response, err := me.client.UseCvmClient(specArgs).DescribeInstances(request) + response, err := me.client.UseCvmClient(iacExtInfo).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/es/service_tencentcloud_elasticsearch.go b/tencentcloud/services/es/service_tencentcloud_elasticsearch.go index 2d18a0a7c8..cd06efca8a 100644 --- a/tencentcloud/services/es/service_tencentcloud_elasticsearch.go +++ b/tencentcloud/services/es/service_tencentcloud_elasticsearch.go @@ -30,9 +30,9 @@ func (me *ElasticsearchService) DescribeInstanceById(ctx context.Context, instan request.InstanceIds = []*string{&instanceId} ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - response, err := me.client.UseEsClient(specArgs).DescribeInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseEsClient(iacExtInfo).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/gaap/service_tencentcloud_gaap.go b/tencentcloud/services/gaap/service_tencentcloud_gaap.go index 5116be4c05..b4e4814da3 100644 --- a/tencentcloud/services/gaap/service_tencentcloud_gaap.go +++ b/tencentcloud/services/gaap/service_tencentcloud_gaap.go @@ -626,10 +626,10 @@ func (me *GaapService) DescribeProxies( if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) if len(ids) > 0 { - var specArgs connectivity.IacExtInfo + var iacExtInfo connectivity.IacExtInfo tmpIds := strings.Join(ids, tccommon.FILED_SP) - specArgs.InstanceId = tmpIds - response, err = me.client.UseGaapClient(specArgs).DescribeProxies(request) + iacExtInfo.InstanceId = tmpIds + response, err = me.client.UseGaapClient(iacExtInfo).DescribeProxies(request) } else { response, err = me.client.UseGaapClient().DescribeProxies(request) } diff --git a/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go b/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go index 7d87daac59..6a90694e00 100644 --- a/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go +++ b/tencentcloud/services/lighthouse/service_tencentcloud_lighthouse.go @@ -40,8 +40,8 @@ func (me *LightHouseService) DescribeLighthouseInstanceById(ctx context.Context, request.InstanceIds = append(request.InstanceIds, helper.String(instanceId)) ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId var offset int64 = 0 var pageSize int64 = 100 @@ -51,7 +51,7 @@ func (me *LightHouseService) DescribeLighthouseInstanceById(ctx context.Context, request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseLighthouseClient(specArgs).DescribeInstances(request) + response, err := me.client.UseLighthouseClient(iacExtInfo).DescribeInstances(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go b/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go index 7c73c76e41..c3644d26ba 100644 --- a/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go +++ b/tencentcloud/services/mariadb/service_tencentcloud_mariadb.go @@ -755,10 +755,9 @@ func (me *MariadbService) DescribeMariadbDbInstanceDetail(ctx context.Context, i }() request.InstanceId = &instanceId - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - - response, err := me.client.UseMariadbClient(specArgs).DescribeDBInstanceDetail(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseMariadbClient(iacExtInfo).DescribeDBInstanceDetail(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) @@ -1127,10 +1126,9 @@ func (me *MariadbService) DescribeMariadbInstanceById(ctx context.Context, insta }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - - response, err := me.client.UseMariadbClient(specArgs).DescribeDBInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseMariadbClient(iacExtInfo).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go b/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go index 1e41687030..b3df2e2aad 100644 --- a/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go +++ b/tencentcloud/services/mongodb/service_tencentcloud_mongodb.go @@ -30,13 +30,12 @@ func (me *MongodbService) DescribeInstanceById(ctx context.Context, instanceId s request := mongodb.NewDescribeDBInstancesRequest() request.InstanceIds = []*string{&instanceId} - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId var response *mongodb.DescribeDBInstancesResponse err := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - result, e := me.client.UseMongodbClient(specArgs).DescribeDBInstances(request) + result, e := me.client.UseMongodbClient(iacExtInfo).DescribeDBInstances(request) if e != nil { return resource.NonRetryableError(e) } diff --git a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go index 29284757f1..b6a01aef25 100644 --- a/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go +++ b/tencentcloud/services/postgresql/service_tencentcloud_postgresql.go @@ -440,9 +440,9 @@ func (me *PostgresqlService) DescribePostgresqlInstanceById(ctx context.Context, request.DBInstanceId = &instanceId ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - response, err := me.client.UsePostgresqlClient(specArgs).DescribeDBInstanceAttribute(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UsePostgresqlClient(iacExtInfo).DescribeDBInstanceAttribute(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go index 0af7340e1e..897d68132b 100644 --- a/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go +++ b/tencentcloud/services/privatedns/resource_tc_private_dns_zone.go @@ -257,11 +257,10 @@ func resourceTencentCloudDPrivateDnsZoneRead(d *schema.ResourceData, meta interf ) request.ZoneId = &id - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = id - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = id err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UsePrivateDnsClient(specArgs).DescribePrivateZone(request) + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UsePrivateDnsClient(iacExtInfo).DescribePrivateZone(request) if e != nil { return tccommon.RetryError(e) } diff --git a/tencentcloud/services/scf/service_tencentcloud_scf.go b/tencentcloud/services/scf/service_tencentcloud_scf.go index affad92de9..ea9c2626b8 100644 --- a/tencentcloud/services/scf/service_tencentcloud_scf.go +++ b/tencentcloud/services/scf/service_tencentcloud_scf.go @@ -151,13 +151,11 @@ func (me *ScfService) DescribeFunction(ctx context.Context, name, namespace stri request := scf.NewGetFunctionRequest() request.FunctionName = &name request.Namespace = &namespace - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = strings.Join([]string{name, namespace}, tccommon.FILED_SP) if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = strings.Join([]string{name, namespace}, tccommon.FILED_SP) - - response, err := me.client.UseScfClient(specArgs).GetFunction(request) + response, err := me.client.UseScfClient(iacExtInfo).GetFunction(request) if err != nil { if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok { for _, code := range SCF_FUNCTIONS_NOT_FOUND_SET { diff --git a/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go b/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go index 55de396248..9e777e406a 100644 --- a/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go +++ b/tencentcloud/services/sqlserver/service_tencentcloud_sqlserver.go @@ -331,14 +331,14 @@ func (me *SqlserverService) DescribeSqlserverInstances(ctx context.Context, inst } var offset, limit int64 = 0, 20 - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId for { request.Offset = &offset request.Limit = &limit ratelimit.Check(request.GetAction()) - response, err := me.client.UseSqlserverClient(specArgs).DescribeDBInstances(request) + response, err := me.client.UseSqlserverClient(iacExtInfo).DescribeDBInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/tcr/service_tencentcloud_tcr.go b/tencentcloud/services/tcr/service_tencentcloud_tcr.go index d60a59e0bf..5c68478be1 100644 --- a/tencentcloud/services/tcr/service_tencentcloud_tcr.go +++ b/tencentcloud/services/tcr/service_tencentcloud_tcr.go @@ -177,10 +177,9 @@ func (me *TCRService) DescribeTCRInstanceById(ctx context.Context, instanceId st request.Registryids = []*string{&instanceId} ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - - response, err := me.client.UseTCRClient(specArgs).DescribeInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseTCRClient(iacExtInfo).DescribeInstances(request) if err != nil { ee, ok := err.(*sdkErrors.TencentCloudSDKError) if !ok { diff --git a/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go b/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go index 304b45a35e..6f235535bc 100644 --- a/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go +++ b/tencentcloud/services/tdcpg/service_tencentcloud_tdcpg.go @@ -394,14 +394,14 @@ func (me *TdcpgService) DescribeTdcpgClustersByFilter(ctx context.Context, param } } ratelimit.Check(request.GetAction()) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = tmpId for { request.PageNumber = helper.IntUint64(currNumber) request.PageSize = helper.IntUint64(pageSize) if tmpId != "" { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = tmpId - response, err = me.client.UseTdcpgClient(specArgs).DescribeClusters(request) + response, err = me.client.UseTdcpgClient(iacExtInfo).DescribeClusters(request) } else { response, err = me.client.UseTdcpgClient().DescribeClusters(request) } @@ -487,15 +487,15 @@ func (me *TdcpgService) DescribeTdcpgInstancesByFilter(ctx context.Context, clus } } ratelimit.Check(request.GetAction()) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = tmpId for { request.PageNumber = helper.IntUint64(currNumber) request.PageSize = helper.IntUint64(pageSize) request.ClusterId = clusterId if tmpId != "" { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = tmpId - response, err = me.client.UseTdcpgClient(specArgs).DescribeClusterInstances(request) + response, err = me.client.UseTdcpgClient(iacExtInfo).DescribeClusterInstances(request) } else { response, err = me.client.UseTdcpgClient().DescribeClusterInstances(request) } diff --git a/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go b/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go index 56d08aa52e..cfbb63575f 100644 --- a/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go +++ b/tencentcloud/services/tdmq/service_tencentcloud_tdmq.go @@ -44,12 +44,11 @@ func (me *TdmqService) DescribeTdmqInstanceById(ctx context.Context, var response *tdmq.DescribeClustersResponse - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = clusterId - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = clusterId if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) - result, err := me.client.UseTdmqClient(specArgs).DescribeClusters(request) + result, err := me.client.UseTdmqClient(iacExtInfo).DescribeClusters(request) if err != nil { return tccommon.RetryError(err, tccommon.InternalError) } @@ -645,10 +644,9 @@ func (me *TdmqService) DescribeTdmqProfessionalClusterById(ctx context.Context, }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = clusterId - - response, err := me.client.UseTdmqClient(specArgs).DescribePulsarProInstanceDetail(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = clusterId + response, err := me.client.UseTdmqClient(iacExtInfo).DescribePulsarProInstanceDetail(request) if err != nil { errRet = err return @@ -701,8 +699,8 @@ func (me *TdmqService) DescribePulsarProInstances(ctx context.Context, clusterId }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = clusterId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = clusterId var ( offset uint64 = 0 @@ -712,7 +710,7 @@ func (me *TdmqService) DescribePulsarProInstances(ctx context.Context, clusterId for { request.Offset = &offset request.Limit = &limit - response, err := me.client.UseTdmqClient(specArgs).DescribePulsarProInstances(request) + response, err := me.client.UseTdmqClient(iacExtInfo).DescribePulsarProInstances(request) if err != nil { errRet = err return @@ -1625,10 +1623,9 @@ func (me *TdmqService) DescribeTdmqRabbitmqVipInstanceById(ctx context.Context, }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - - response, err := me.client.UseTdmqClient(specArgs).DescribeRabbitMQVipInstance(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseTdmqClient(iacExtInfo).DescribeRabbitMQVipInstance(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/teo/service_tencentcloud_teo.go b/tencentcloud/services/teo/service_tencentcloud_teo.go index ee3fe19139..cdfd8dfe0b 100644 --- a/tencentcloud/services/teo/service_tencentcloud_teo.go +++ b/tencentcloud/services/teo/service_tencentcloud_teo.go @@ -47,8 +47,8 @@ func (me *TeoService) DescribeTeoZone(ctx context.Context, zoneId string) (zone } ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = zoneId + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = zoneId var offset int64 = 0 var pageSize int64 = 100 @@ -58,7 +58,7 @@ func (me *TeoService) DescribeTeoZone(ctx context.Context, zoneId string) (zone request.Offset = &offset request.Limit = &pageSize ratelimit.Check(request.GetAction()) - response, err := me.client.UseTeoClient(specArgs).DescribeZones(request) + response, err := me.client.UseTeoClient(iacExtInfo).DescribeZones(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) diff --git a/tencentcloud/services/tke/service_tencentcloud_tke.go b/tencentcloud/services/tke/service_tencentcloud_tke.go index ecaa1cfb9b..911e38480b 100644 --- a/tencentcloud/services/tke/service_tencentcloud_tke.go +++ b/tencentcloud/services/tke/service_tencentcloud_tke.go @@ -414,11 +414,10 @@ func (me *TkeService) DescribeCluster(ctx context.Context, id string) ( request.ClusterIds = []*string{&id} - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = id - + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = id ratelimit.Check(request.GetAction()) - response, err := me.client.UseTkeClient(specArgs).DescribeClusters(request) + response, err := me.client.UseTkeClient(iacExtInfo).DescribeClusters(request) if err != nil { errRet = err diff --git a/tencentcloud/services/tse/service_tencentcloud_tse.go b/tencentcloud/services/tse/service_tencentcloud_tse.go index 391d22f299..6fda2425ba 100644 --- a/tencentcloud/services/tse/service_tencentcloud_tse.go +++ b/tencentcloud/services/tse/service_tencentcloud_tse.go @@ -42,9 +42,9 @@ func (me *TseService) DescribeTseInstanceById(ctx context.Context, instanceId st }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - response, err := me.client.UseTseClient(specArgs).DescribeSREInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseTseClient(iacExtInfo).DescribeSREInstances(request) if err != nil { errRet = err return diff --git a/tencentcloud/services/vpc/resource_tc_nat_gateway.go b/tencentcloud/services/vpc/resource_tc_nat_gateway.go index 74e43d7926..bcf3cdbc47 100644 --- a/tencentcloud/services/vpc/resource_tc_nat_gateway.go +++ b/tencentcloud/services/vpc/resource_tc_nat_gateway.go @@ -218,10 +218,10 @@ func resourceTencentCloudNatGatewayRead(d *schema.ResourceData, meta interface{} request := vpc.NewDescribeNatGatewaysRequest() request.NatGatewayIds = []*string{&natGatewayId} var response *vpc.DescribeNatGatewaysResponse + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = natGatewayId err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = natGatewayId - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(specArgs).DescribeNatGateways(request) + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(iacExtInfo).DescribeNatGateways(request) if e != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), e.Error()) diff --git a/tencentcloud/services/vpc/service_tencentcloud_vpc.go b/tencentcloud/services/vpc/service_tencentcloud_vpc.go index 860525aa5a..43311163b9 100644 --- a/tencentcloud/services/vpc/service_tencentcloud_vpc.go +++ b/tencentcloud/services/vpc/service_tencentcloud_vpc.go @@ -405,14 +405,14 @@ getMoreData: var strOffset = fmt.Sprintf("%d", offset) request.Offset = &strOffset var response *vpc.DescribeVpcsResponse + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = vpcId if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) var result *vpc.DescribeVpcsResponse var err error if vpcId != "" { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = vpcId - result, err = me.client.UseVpcClient(specArgs).DescribeVpcs(request) + result, err = me.client.UseVpcClient(iacExtInfo).DescribeVpcs(request) } else { result, err = me.client.UseVpcClient().DescribeVpcs(request) } diff --git a/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go b/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go index 2e33927108..58090d2b2c 100644 --- a/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go +++ b/tencentcloud/services/vpn/resource_tc_vpn_customer_gateway.go @@ -135,10 +135,10 @@ func resourceTencentCloudVpnCustomerGatewayRead(d *schema.ResourceData, meta int request := vpc.NewDescribeCustomerGatewaysRequest() request.CustomerGatewayIds = []*string{&customerGatewayId} var response *vpc.DescribeCustomerGatewaysResponse + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = customerGatewayId err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = customerGatewayId - result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(specArgs).DescribeCustomerGateways(request) + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseVpcClient(iacExtInfo).DescribeCustomerGateways(request) if e != nil { ee, ok := e.(*errors.TencentCloudSDKError) if !ok { diff --git a/tencentcloud/services/waf/service_tencentcloud_waf.go b/tencentcloud/services/waf/service_tencentcloud_waf.go index 8432fc0011..7f3aa8ad9e 100644 --- a/tencentcloud/services/waf/service_tencentcloud_waf.go +++ b/tencentcloud/services/waf/service_tencentcloud_waf.go @@ -625,9 +625,9 @@ func (me *WafService) DescribeWafInstanceById(ctx context.Context, instanceId st }() ratelimit.Check(request.GetAction()) - var specArgs connectivity.IacExtInfo - specArgs.InstanceId = instanceId - response, err := me.client.UseWafClient(specArgs).DescribeInstances(request) + var iacExtInfo connectivity.IacExtInfo + iacExtInfo.InstanceId = instanceId + response, err := me.client.UseWafClient(iacExtInfo).DescribeInstances(request) if err != nil { errRet = err return From 312539933ac3e32ec1ccb85eabb237cf8f661661 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 15 Mar 2024 16:14:05 +0800 Subject: [PATCH 7/9] add --- .changelog/2544.txt | 3 - tencentcloud/connectivity/client.go | 550 ++++++++----------------- tencentcloud/connectivity/transport.go | 16 +- 3 files changed, 184 insertions(+), 385 deletions(-) delete mode 100644 .changelog/2544.txt diff --git a/.changelog/2544.txt b/.changelog/2544.txt deleted file mode 100644 index 829e81bdfd..0000000000 --- a/.changelog/2544.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:enhancement -resource/client: Adjusting the client structure -``` \ No newline at end of file diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 990a0ee10a..750fff6cc7 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -296,27 +296,19 @@ func (me *TencentCloudClient) UseTencentCosClient(bucket string) *cos.Client { // UseMysqlClient returns mysql(cdb) client for service func (me *TencentCloudClient) UseMysqlClient(iacExtInfo ...IacExtInfo) *cdb.Client { - if me.mysqlConn != nil { - if len(iacExtInfo) != 0 { - me.mysqlConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.mysqlConn != nil { + me.mysqlConn.WithHttpTransport(&logRoundTripper) return me.mysqlConn } cpf := me.NewClientProfile(300) me.mysqlConn, _ = cdb.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.mysqlConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mysqlConn.WithHttpTransport(&LogRoundTripper{}) - } + me.mysqlConn.WithHttpTransport(&logRoundTripper) return me.mysqlConn } @@ -349,55 +341,39 @@ func (me *TencentCloudClient) UseAsClient() *as.Client { // UseVpcClient returns vpc client for service func (me *TencentCloudClient) UseVpcClient(iacExtInfo ...IacExtInfo) *vpc.Client { - if me.vpcConn != nil { - if len(iacExtInfo) != 0 { - me.vpcConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.vpcConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.vpcConn != nil { + me.vpcConn.WithHttpTransport(&logRoundTripper) return me.vpcConn } cpf := me.NewClientProfile(300) me.vpcConn, _ = vpc.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.vpcConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.vpcConn.WithHttpTransport(&LogRoundTripper{}) - } + me.vpcConn.WithHttpTransport(&logRoundTripper) return me.vpcConn } // UseCbsClient returns cbs client for service func (me *TencentCloudClient) UseCbsClient(iacExtInfo ...IacExtInfo) *cbs.Client { - if me.cbsConn != nil { - if len(iacExtInfo) != 0 { - me.cbsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cbsConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.cbsConn != nil { + me.cbsConn.WithHttpTransport(&logRoundTripper) return me.cbsConn } var reqTimeout = getEnvDefault(PROVIDER_CBS_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cbsConn, _ = cbs.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.cbsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cbsConn.WithHttpTransport(&LogRoundTripper{}) - } + me.cbsConn.WithHttpTransport(&logRoundTripper) return me.cbsConn } @@ -417,82 +393,58 @@ func (me *TencentCloudClient) UseDcClient() *dc.Client { // UseMongodbClient returns mongodb client for service func (me *TencentCloudClient) UseMongodbClient(iacExtInfo ...IacExtInfo) *mongodb.Client { - if me.mongodbConn != nil { - if len(iacExtInfo) != 0 { - me.mongodbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.mongodbConn != nil { + me.mongodbConn.WithHttpTransport(&logRoundTripper) return me.mongodbConn } cpf := me.NewClientProfile(300) me.mongodbConn, _ = mongodb.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.mongodbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mongodbConn.WithHttpTransport(&LogRoundTripper{}) - } + me.mongodbConn.WithHttpTransport(&logRoundTripper) return me.mongodbConn } // UseClbClient returns clb client for service func (me *TencentCloudClient) UseClbClient(iacExtInfo ...IacExtInfo) *clb.Client { - if me.clbConn != nil { - if len(iacExtInfo) != 0 { - me.clbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.clbConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.clbConn != nil { + me.clbConn.WithHttpTransport(&logRoundTripper) return me.clbConn } cpf := me.NewClientProfile(300) me.clbConn, _ = clb.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.clbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.clbConn.WithHttpTransport(&LogRoundTripper{}) - } + me.clbConn.WithHttpTransport(&logRoundTripper) return me.clbConn } // UseCvmClient returns cvm client for service func (me *TencentCloudClient) UseCvmClient(iacExtInfo ...IacExtInfo) *cvm.Client { - if me.cvmConn != nil { - if len(iacExtInfo) != 0 { - me.cvmConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cvmConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.cvmConn != nil { + me.cvmConn.WithHttpTransport(&logRoundTripper) return me.cvmConn } var reqTimeout = getEnvDefault(PROVIDER_CVM_REQUEST_TIMEOUT, 300) cpf := me.NewClientProfile(reqTimeout) me.cvmConn, _ = cvm.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.cvmConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cvmConn.WithHttpTransport(&LogRoundTripper{}) - } + me.cvmConn.WithHttpTransport(&logRoundTripper) return me.cvmConn } @@ -512,81 +464,57 @@ func (me *TencentCloudClient) UseTagClient() *tag.Client { // UseTkeClient returns tke client for service func (me *TencentCloudClient) UseTkeClient(iacExtInfo ...IacExtInfo) *tke.Client { - if me.tkeConn != nil { - if len(iacExtInfo) != 0 { - me.tkeConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tkeConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.tkeConn != nil { + me.tkeConn.WithHttpTransport(&logRoundTripper) return me.tkeConn } cpf := me.NewClientProfile(300) me.tkeConn, _ = tke.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.tkeConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tkeConn.WithHttpTransport(&LogRoundTripper{}) - } + me.tkeConn.WithHttpTransport(&logRoundTripper) return me.tkeConn } // UseTdmqClient returns Tdmq client for service func (me *TencentCloudClient) UseTdmqClient(iacExtInfo ...IacExtInfo) *tdmq.Client { - if me.tdmqConn != nil { - if len(iacExtInfo) != 0 { - me.tdmqConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.tdmqConn != nil { + me.tdmqConn.WithHttpTransport(&logRoundTripper) return me.tdmqConn } cpf := me.NewClientProfile(300) me.tdmqConn, _ = tdmq.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.tdmqConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tdmqConn.WithHttpTransport(&LogRoundTripper{}) - } + me.tdmqConn.WithHttpTransport(&logRoundTripper) return me.tdmqConn } // UseGaapClient returns gaap client for service func (me *TencentCloudClient) UseGaapClient(iacExtInfo ...IacExtInfo) *gaap.Client { - if me.gaapConn != nil { - if len(iacExtInfo) != 0 { - me.gaapConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.gaapConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.gaapConn != nil { + me.gaapConn.WithHttpTransport(&logRoundTripper) return me.gaapConn } cpf := me.NewClientProfile(300) me.gaapConn, _ = gaap.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.gaapConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.gaapConn.WithHttpTransport(&LogRoundTripper{}) - } + me.gaapConn.WithHttpTransport(&logRoundTripper) return me.gaapConn } @@ -648,27 +576,19 @@ func (me *TencentCloudClient) UseCfsClient() *cfs.Client { // UseScfClient returns scf client for service func (me *TencentCloudClient) UseScfClient(iacExtInfo ...IacExtInfo) *scf.Client { - if me.scfConn != nil { - if len(iacExtInfo) != 0 { - me.scfConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.scfConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.scfConn != nil { + me.scfConn.WithHttpTransport(&logRoundTripper) return me.scfConn } cpf := me.NewClientProfile(300) me.scfConn, _ = scf.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.scfConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.scfConn.WithHttpTransport(&LogRoundTripper{}) - } + me.scfConn.WithHttpTransport(&logRoundTripper) return me.scfConn } @@ -701,27 +621,19 @@ func (me *TencentCloudClient) UseDayuClient() *dayu.Client { // UseCdnClient returns cdn client for service func (me *TencentCloudClient) UseCdnClient(iacExtInfo ...IacExtInfo) *cdn.Client { - if me.cdnConn != nil { - if len(iacExtInfo) != 0 { - me.cdnConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cdnConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.cdnConn != nil { + me.cdnConn.WithHttpTransport(&logRoundTripper) return me.cdnConn } cpf := me.NewClientProfile(300) me.cdnConn, _ = cdn.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.cdnConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cdnConn.WithHttpTransport(&LogRoundTripper{}) - } + me.cdnConn.WithHttpTransport(&logRoundTripper) return me.cdnConn } @@ -741,109 +653,77 @@ func (me *TencentCloudClient) UseMonitorClient() *monitor.Client { // UseEsClient returns es client for service func (me *TencentCloudClient) UseEsClient(iacExtInfo ...IacExtInfo) *es.Client { - if me.esConn != nil { - if len(iacExtInfo) != 0 { - me.esConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.esConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.esConn != nil { + me.esConn.WithHttpTransport(&logRoundTripper) return me.esConn } cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.esConn, _ = es.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.esConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.esConn.WithHttpTransport(&LogRoundTripper{}) - } + me.esConn.WithHttpTransport(&logRoundTripper) return me.esConn } // UsePostgresqlClient returns postgresql client for service func (me *TencentCloudClient) UsePostgresqlClient(iacExtInfo ...IacExtInfo) *postgre.Client { - if me.postgreConn != nil { - if len(iacExtInfo) != 0 { - me.postgreConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.postgreConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.postgreConn != nil { + me.postgreConn.WithHttpTransport(&logRoundTripper) return me.postgreConn } cpf := me.NewClientProfile(300) me.postgreConn, _ = postgre.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.postgreConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.postgreConn.WithHttpTransport(&LogRoundTripper{}) - } + me.postgreConn.WithHttpTransport(&logRoundTripper) return me.postgreConn } // UseSqlserverClient returns sqlserver client for service func (me *TencentCloudClient) UseSqlserverClient(iacExtInfo ...IacExtInfo) *sqlserver.Client { - if me.sqlserverConn != nil { - if len(iacExtInfo) != 0 { - me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.sqlserverConn != nil { + me.sqlserverConn.WithHttpTransport(&logRoundTripper) return me.sqlserverConn } cpf := me.NewClientProfile(300) me.sqlserverConn, _ = sqlserver.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.sqlserverConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.sqlserverConn.WithHttpTransport(&LogRoundTripper{}) - } + me.sqlserverConn.WithHttpTransport(&logRoundTripper) return me.sqlserverConn } // UseCkafkaClient returns ckafka client for service func (me *TencentCloudClient) UseCkafkaClient(iacExtInfo ...IacExtInfo) *ckafka.Client { - if me.ckafkaConn != nil { - if len(iacExtInfo) != 0 { - me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.ckafkaConn != nil { + me.ckafkaConn.WithHttpTransport(&logRoundTripper) return me.ckafkaConn } cpf := me.NewClientProfile(300) me.ckafkaConn, _ = ckafka.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.ckafkaConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.ckafkaConn.WithHttpTransport(&LogRoundTripper{}) - } + me.ckafkaConn.WithHttpTransport(&logRoundTripper) return me.ckafkaConn } @@ -902,27 +782,19 @@ func (me *TencentCloudClient) UseAPIGatewayClient() *apigateway.Client { // UseTCRClient returns apigateway client for service func (me *TencentCloudClient) UseTCRClient(iacExtInfo ...IacExtInfo) *tcr.Client { - if me.tcrConn != nil { - if len(iacExtInfo) != 0 { - me.tcrConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tcrConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.tcrConn != nil { + me.tcrConn.WithHttpTransport(&logRoundTripper) return me.tcrConn } cpf := me.NewClientProfile(300) me.tcrConn, _ = tcr.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.tcrConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tcrConn.WithHttpTransport(&LogRoundTripper{}) - } + me.tcrConn.WithHttpTransport(&logRoundTripper) return me.tcrConn } @@ -992,54 +864,38 @@ func (me *TencentCloudClient) UseEmrClient() *emr.Client { // UseClsClient return CLS client for service func (me *TencentCloudClient) UseClsClient(iacExtInfo ...IacExtInfo) *cls.Client { - if me.clsConn != nil { - if len(iacExtInfo) != 0 { - me.clsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.clsConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.clsConn != nil { + me.clsConn.WithHttpTransport(&logRoundTripper) return me.clsConn } cpf := me.NewClientProfile(300) me.clsConn, _ = cls.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.clsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.clsConn.WithHttpTransport(&LogRoundTripper{}) - } + me.clsConn.WithHttpTransport(&logRoundTripper) return me.clsConn } // UseLighthouseClient return Lighthouse client for service func (me *TencentCloudClient) UseLighthouseClient(iacExtInfo ...IacExtInfo) *lighthouse.Client { - if me.lighthouseConn != nil { - if len(iacExtInfo) != 0 { - me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.lighthouseConn != nil { + me.lighthouseConn.WithHttpTransport(&logRoundTripper) return me.lighthouseConn } cpf := me.NewClientProfile(300) me.lighthouseConn, _ = lighthouse.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.lighthouseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.lighthouseConn.WithHttpTransport(&LogRoundTripper{}) - } + me.lighthouseConn.WithHttpTransport(&logRoundTripper) return me.lighthouseConn } @@ -1058,27 +914,19 @@ func (me *TencentCloudClient) UseDnsPodClient() *dnspod.Client { // UsePrivateDnsClient return PrivateDns client for service func (me *TencentCloudClient) UsePrivateDnsClient(iacExtInfo ...IacExtInfo) *privatedns.Client { - if me.privateDnsConn != nil { - if len(iacExtInfo) != 0 { - me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.privateDnsConn != nil { + me.privateDnsConn.WithHttpTransport(&logRoundTripper) return me.privateDnsConn } cpf := me.NewClientProfile(300) me.privateDnsConn, _ = privatedns.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.privateDnsConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.privateDnsConn.WithHttpTransport(&LogRoundTripper{}) - } + me.privateDnsConn.WithHttpTransport(&logRoundTripper) return me.privateDnsConn } @@ -1123,27 +971,19 @@ func (me *TencentCloudClient) UseTemClient() *tem.Client { // UseTeoClient returns teo client for service func (me *TencentCloudClient) UseTeoClient(iacExtInfo ...IacExtInfo) *teo.Client { - if me.teoConn != nil { - if len(iacExtInfo) != 0 { - me.teoConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.teoConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.teoConn != nil { + me.teoConn.WithHttpTransport(&logRoundTripper) return me.teoConn } cpf := me.NewClientProfile(300) me.teoConn, _ = teo.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.teoConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.teoConn.WithHttpTransport(&LogRoundTripper{}) - } + me.teoConn.WithHttpTransport(&logRoundTripper) return me.teoConn } @@ -1228,27 +1068,19 @@ func (me *TencentCloudClient) UseCatClient() *cat.Client { // UseMariadbClient returns mariadb client for service func (me *TencentCloudClient) UseMariadbClient(iacExtInfo ...IacExtInfo) *mariadb.Client { - if me.mariadbConn != nil { - if len(iacExtInfo) != 0 { - me.mariadbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.mariadbConn != nil { + me.mariadbConn.WithHttpTransport(&logRoundTripper) return me.mariadbConn } cpf := me.NewClientProfile(300) me.mariadbConn, _ = mariadb.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.mariadbConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.mariadbConn.WithHttpTransport(&LogRoundTripper{}) - } + me.mariadbConn.WithHttpTransport(&logRoundTripper) return me.mariadbConn } @@ -1294,27 +1126,19 @@ func (me *TencentCloudClient) UseOrganizationClient() *organization.Client { // UseTdcpgClient returns tdcpg client for service func (me *TencentCloudClient) UseTdcpgClient(iacExtInfo ...IacExtInfo) *tdcpg.Client { - if me.tdcpgConn != nil { - if len(iacExtInfo) != 0 { - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.tdcpgConn != nil { + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) return me.tdcpgConn } cpf := me.NewClientProfile(300) me.tdcpgConn, _ = tdcpg.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) - } + me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) return me.tdcpgConn } @@ -1530,28 +1354,20 @@ func (me *TencentCloudClient) UseCiamClient() *ciam.Client { // UseTseClient returns tse client for service func (me *TencentCloudClient) UseTseClient(iacExtInfo ...IacExtInfo) *tse.Client { - if me.tseConn != nil { - if len(iacExtInfo) != 0 { - me.tseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tseConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.tseConn != nil { + me.tseConn.WithHttpTransport(&logRoundTripper) return me.tseConn } cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.tseConn, _ = tse.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.tseConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.tseConn.WithHttpTransport(&LogRoundTripper{}) - } + me.tseConn.WithHttpTransport(&logRoundTripper) return me.tseConn } @@ -1613,55 +1429,39 @@ func (me *TencentCloudClient) UseWedataClient() *wedata.Client { } func (me *TencentCloudClient) UseWafClient(iacExtInfo ...IacExtInfo) *waf.Client { - if me.wafConn != nil { - if len(iacExtInfo) != 0 { - me.wafConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.wafConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.wafConn != nil { + me.wafConn.WithHttpTransport(&logRoundTripper) return me.wafConn } cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.wafConn, _ = waf.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.wafConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.wafConn.WithHttpTransport(&LogRoundTripper{}) - } + me.wafConn.WithHttpTransport(&logRoundTripper) return me.wafConn } func (me *TencentCloudClient) UseCfwClient(iacExtInfo ...IacExtInfo) *cfw.Client { - if me.cfwConn != nil { - if len(iacExtInfo) != 0 { - me.cfwConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cfwConn.WithHttpTransport(&LogRoundTripper{}) - } + var logRoundTripper LogRoundTripper + if len(iacExtInfo) != 0 { + logRoundTripper.InstanceId = iacExtInfo[0].InstanceId + } + if me.cfwConn != nil { + me.cfwConn.WithHttpTransport(&logRoundTripper) return me.cfwConn } cpf := me.NewClientProfile(300) cpf.Language = "zh-CN" me.cfwConn, _ = cfw.NewClient(me.Credential, me.Region, cpf) - if len(iacExtInfo) != 0 { - me.cfwConn.WithHttpTransport(&LogRoundTripper{ - InstanceId: iacExtInfo[0].InstanceId, - }) - } else { - me.cfwConn.WithHttpTransport(&LogRoundTripper{}) - } + me.cfwConn.WithHttpTransport(&logRoundTripper) return me.cfwConn } diff --git a/tencentcloud/connectivity/transport.go b/tencentcloud/connectivity/transport.go index 61b9fe0970..dbb1b4eb26 100644 --- a/tencentcloud/connectivity/transport.go +++ b/tencentcloud/connectivity/transport.go @@ -44,30 +44,29 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp if errRet != nil { return } + var headName = "X-TC-Action" if envReqClient := os.Getenv(REQUEST_CLIENT); envReqClient != "" { ReqClient = envReqClient } + if routeUserID := os.Getenv(ENV_TESTING_ROUTE_USER_ID); routeUserID != "" { request.Header.Set(ENV_TESTING_ROUTE_HEADER_KEY, routeUserID) } - var iacExtInfoStr string if me.InstanceId != "" { - iacExtInfoStr = fmt.Sprintf("%s,id=%s", ReqClient, me.InstanceId) - } else { - iacExtInfoStr = ReqClient + ReqClient = fmt.Sprintf("%s,id=%s", ReqClient, me.InstanceId) } - request.Header.Set("X-TC-RequestClient", iacExtInfoStr) + request.Header.Set("X-TC-RequestClient", ReqClient) inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName])) requestBody, errRet := ioutil.ReadAll(bodyReader) if errRet != nil { return } - inBytes = append(inBytes, requestBody...) + inBytes = append(inBytes, requestBody...) headName = "X-TC-Region" appendMessage := []byte(fmt.Sprintf( ", (host %+v, region:%+v)", @@ -76,15 +75,16 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp )) inBytes = append(inBytes, appendMessage...) - response, errRet = http.DefaultTransport.RoundTrip(request) if errRet != nil { return } + outBytes, errRet = ioutil.ReadAll(response.Body) if errRet != nil { return } + response.Body = ioutil.NopCloser(bytes.NewBuffer(outBytes)) return } @@ -96,11 +96,13 @@ func (me *LogRoundTripper) log(in []byte, out []byte, err error, start time.Time if err != nil { tag = "[CRITICAL]" } + buf.WriteString(tag) if len(in) > 0 { buf.WriteString("tencentcloud-sdk-go: ") buf.Write(in) } + if len(out) > 0 { buf.WriteString("; response:") err := json.Compact(&buf, out) From 4ee88a2f544f9def0fa6078cbfb790c405b966f2 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 15 Mar 2024 16:18:43 +0800 Subject: [PATCH 8/9] add --- tencentcloud/connectivity/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 750fff6cc7..7bf400fc5a 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -1132,13 +1132,13 @@ func (me *TencentCloudClient) UseTdcpgClient(iacExtInfo ...IacExtInfo) *tdcpg.Cl } if me.tdcpgConn != nil { - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) + me.tdcpgConn.WithHttpTransport(&logRoundTripper) return me.tdcpgConn } cpf := me.NewClientProfile(300) me.tdcpgConn, _ = tdcpg.NewClient(me.Credential, me.Region, cpf) - me.tdcpgConn.WithHttpTransport(&LogRoundTripper{}) + me.tdcpgConn.WithHttpTransport(&logRoundTripper) return me.tdcpgConn } From 25da4ef5171825d075da20a7bbbb37b7e69c2216 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 28 Mar 2024 10:00:06 +0800 Subject: [PATCH 9/9] add --- go.mod | 2 +- go.sum | 7 ++ tencentcloud/provider.go | 5 ++ .../tencentcloud/common/http/request.go | 2 +- .../tencentcloud/common/json/encode.go | 20 ++++-- .../common/oidc_role_arn_provider.go | 72 ++++++++++++------- .../common/role_arn_credential.go | 1 + vendor/modules.txt | 2 +- 8 files changed, 79 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 296d5b9537..45bcc5279a 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.887 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692 diff --git a/go.sum b/go.sum index 4b1340a343..c88d96570b 100644 --- a/go.sum +++ b/go.sum @@ -744,6 +744,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sesky4/tencentcloud-sdk-go/tencentcloud/common v1.0.336-0.20240326032455-d61711597f1c h1:yPsYLRZAfaTYX33hyaXD8zgQeXS53hdwknNIo0csY9Y= +github.com/sesky4/tencentcloud-sdk-go/tencentcloud/common v1.0.336-0.20240326032455-d61711597f1c/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs= github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= @@ -920,9 +922,14 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.844/go.mod github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.845/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.853/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.856/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.857/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 h1:d5/YwGX6b5YgFU/0thsbs5aBp4aJJXBi7JyU1JHAaw0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.884 h1:CEUPF6aCscLcFCHiEskW/SqShD7YldJ/rqaEsz764yc= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.884/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.887 h1:Py9MuRl/d97NxBb9opcNWMsxgrn83Aramk7X5sEUI4o= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.887/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860/go.mod h1:NZo1WplQcC314kMlCRUoy8NQju2BnolIJj7NAWgsuhY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8= diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 3fe7c1c23f..46aa87867f 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mitchellh/go-homedir" sdkcommon "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + commonJson "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/json" sdksts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts/v20180813" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" @@ -139,6 +140,10 @@ type TencentCloudClient struct { var _ tccommon.ProviderMeta = &TencentCloudClient{} +func init() { + commonJson.UseOmitNil = false +} + // GetAPIV3Conn 返回访问云 API 的客户端连接对象 func (meta *TencentCloudClient) GetAPIV3Conn() *connectivity.TencentCloudClient { return meta.apiV3Conn diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go index 80caf9eb3a..2950bb7171 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go @@ -265,7 +265,7 @@ func CompleteCommonParams(request Request, region string, requestClient string) params["Action"] = request.GetAction() params["Timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) params["Nonce"] = strconv.Itoa(rand.Int()) - params["RequestClient"] = "SDK_GO_1.0.860" + params["RequestClient"] = "SDK_GO_1.0.887" if requestClient != "" { params["RequestClient"] += ": " + requestClient } diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/json/encode.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/json/encode.go index c9850b63c0..eecf128774 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/json/encode.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/json/encode.go @@ -635,15 +635,27 @@ type structEncoder struct { fieldEncs []encoderFunc } +const ( + OmitNil = 0 + iota + OmitEmpty +) + +var OmitBehaviour = OmitNil + +func shouldOmit(f field, fv reflect.Value) bool { + if OmitBehaviour == OmitNil { + return !fv.IsValid() || (f.omitNil || f.omitEmpty) && isNilValue(fv) + } else { + return !fv.IsValid() || (f.omitNil || f.omitEmpty) && isEmptyValue(fv) + } +} + func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { e.WriteByte('{') first := true for i, f := range se.fields { fv := fieldByIndex(v, f.index) - if !fv.IsValid() || f.omitEmpty && isEmptyValue(fv) { - continue - } - if !fv.IsValid() || f.omitNil && isNilValue(fv) { + if shouldOmit(f, fv) { continue } if first { diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go index bde372bc70..0522bc08fa 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/oidc_role_arn_provider.go @@ -21,6 +21,7 @@ type OIDCRoleArnProvider struct { roleSessionName string durationSeconds int64 Endpoint string + beforeRefresh func(provider *OIDCRoleArnProvider) error } type oidcStsRsp struct { @@ -54,33 +55,46 @@ func NewOIDCRoleArnProvider(region, providerId, webIdentityToken, roleArn, roleS // 4. roleSessionName will be "tencentcloud-go-sdk-" + timestamp // 5. durationSeconds will be 7200s func DefaultTkeOIDCRoleArnProvider() (*OIDCRoleArnProvider, error) { - reg := os.Getenv("TKE_REGION") - if reg == "" { - return nil, errors.New("env TKE_REGION not exist") + beforeRefresh := func(provider *OIDCRoleArnProvider) error { + reg := os.Getenv("TKE_REGION") + if reg == "" { + return errors.New("env TKE_REGION not exist") + } + + providerId := os.Getenv("TKE_PROVIDER_ID") + if providerId == "" { + return errors.New("env TKE_PROVIDER_ID not exist") + } + + tokenFile := os.Getenv("TKE_WEB_IDENTITY_TOKEN_FILE") + if tokenFile == "" { + return errors.New("env TKE_WEB_IDENTITY_TOKEN_FILE not exist") + } + tokenBytes, err := ioutil.ReadFile(tokenFile) + if err != nil { + return err + } + + roleArn := os.Getenv("TKE_ROLE_ARN") + if roleArn == "" { + return errors.New("env TKE_ROLE_ARN not exist") + } + + sessionName := defaultSessionName + strconv.FormatInt(time.Now().UnixNano()/1000, 10) + + provider.region = region + provider.providerId = providerId + provider.webIdentityToken = string(tokenBytes) + provider.roleArn = roleArn + provider.roleSessionName = sessionName + return nil } - providerId := os.Getenv("TKE_PROVIDER_ID") - if providerId == "" { - return nil, errors.New("env TKE_PROVIDER_ID not exist") + provider := &OIDCRoleArnProvider{ + beforeRefresh: beforeRefresh, + durationSeconds: defaultDurationSeconds, } - - tokenFile := os.Getenv("TKE_WEB_IDENTITY_TOKEN_FILE") - if tokenFile == "" { - return nil, errors.New("env TKE_WEB_IDENTITY_TOKEN_FILE not exist") - } - tokenBytes, err := ioutil.ReadFile(tokenFile) - if err != nil { - return nil, err - } - - roleArn := os.Getenv("TKE_ROLE_ARN") - if roleArn == "" { - return nil, errors.New("env TKE_ROLE_ARN not exist") - } - - sessionName := defaultSessionName + strconv.FormatInt(time.Now().UnixNano()/1000, 10) - - return NewOIDCRoleArnProvider(reg, providerId, string(tokenBytes), roleArn, sessionName, defaultDurationSeconds), nil + return provider, provider.beforeRefresh(provider) } func (r *OIDCRoleArnProvider) GetCredential() (CredentialIface, error) { @@ -89,6 +103,14 @@ func (r *OIDCRoleArnProvider) GetCredential() (CredentialIface, error) { version = "2018-08-13" action = "AssumeRoleWithWebIdentity" ) + + if r.beforeRefresh != nil { + err := r.beforeRefresh(r) + if err != nil { + return nil, err + } + } + if r.durationSeconds > 43200 || r.durationSeconds <= 0 { return nil, tcerr.NewTencentCloudSDKError(creErr, "AssumeRoleWithWebIdentity durationSeconds should be in the range of 0~43200s", "") } @@ -131,7 +153,7 @@ func (r *OIDCRoleArnProvider) GetCredential() (CredentialIface, error) { roleArn: r.roleArn, roleSessionName: r.roleSessionName, durationSeconds: r.durationSeconds, - expiredTime: int64(rspSt.Response.ExpiredTime), + expiredTime: int64(rspSt.Response.ExpiredTime) - r.durationSeconds/10, token: rspSt.Response.Credentials.Token, tmpSecretId: rspSt.Response.Credentials.TmpSecretId, tmpSecretKey: rspSt.Response.Credentials.TmpSecretKey, diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go index ad5917304c..e668c3d19d 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_credential.go @@ -56,6 +56,7 @@ func (c *RoleArnCredential) refresh() { newCre, err := c.source.GetCredential() if err != nil { log.Println(err) + return } *c = *newCre.(*RoleArnCredential) } diff --git a/vendor/modules.txt b/vendor/modules.txt index d6f1737f10..b5c6e20f17 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1160,7 +1160,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016 -# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 +# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.887 ## explicit; go 1.11 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors