Skip to content

Commit

Permalink
feat/iacExtInfo2
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenEarth committed Mar 6, 2024
1 parent bf71563 commit 788f8e6
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 57 deletions.
122 changes: 96 additions & 26 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -634,15 +651,21 @@ 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
}

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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1365,28 +1423,40 @@ 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
}

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
}

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
}
Expand Down
9 changes: 9 additions & 0 deletions tencentcloud/connectivity/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion tencentcloud/services/cdb/service_tencentcloud_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tencentcloud/services/cdn/service_tencentcloud_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions tencentcloud/services/cfw/service_tencentcloud_cfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tencentcloud/services/cls/service_tencentcloud_cls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 9 additions & 1 deletion tencentcloud/services/gaap/service_tencentcloud_gaap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 788f8e6

Please sign in to comment.