@@ -26,6 +26,7 @@ import (
2626 monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
2727 redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412"
2828 scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
29+ sts "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts/v20180813"
2930 tag "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag/v20180813"
3031 tcaplusdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb/v20190823"
3132 tke "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke/v20180525"
@@ -35,8 +36,10 @@ import (
3536
3637// TencentCloudClient is client for all TencentCloud service
3738type TencentCloudClient struct {
38- Region string
3939 Credential * common.Credential
40+ Region string
41+ Protocol string
42+ Domain string
4043
4144 cosConn * s3.S3
4245 mysqlConn * cdb.Client
@@ -52,6 +55,7 @@ type TencentCloudClient struct {
5255 mongodbConn * mongodb.Client
5356 tkeConn * tke.Client
5457 camConn * cam.Client
58+ stsConn * sts.Client
5559 gaapConn * gaap.Client
5660 sslConn * ssl.Client
5761 cfsConn * cfs.Client
@@ -62,26 +66,18 @@ type TencentCloudClient struct {
6266 esConn * es.Client
6367}
6468
65- // NewTencentCloudClient returns a new TencentCloudClient
66- func NewTencentCloudClient (secretId , secretKey , securityToken , region string ) * TencentCloudClient {
67- return & TencentCloudClient {
68- Region : region ,
69- Credential : common .NewTokenCredential (
70- secretId ,
71- secretKey ,
72- securityToken ,
73- ),
74- }
75- }
76-
77- // NewTencentCloudClientProfile returns a new ClientProfile
78- func NewTencentCloudClientProfile (timeout int ) * profile.ClientProfile {
69+ // NewClientProfile returns a new ClientProfile
70+ func (me * TencentCloudClient ) NewClientProfile (timeout int ) * profile.ClientProfile {
7971 cpf := profile .NewClientProfile ()
8072
8173 // all request use method POST
8274 cpf .HttpProfile .ReqMethod = "POST"
8375 // request timeout
8476 cpf .HttpProfile .ReqTimeout = timeout
77+ // request protocol
78+ cpf .HttpProfile .Scheme = me .Protocol
79+ // request domain
80+ cpf .HttpProfile .RootDomain = me .Domain
8581 // default language
8682 cpf .Language = "en-US"
8783
@@ -120,7 +116,7 @@ func (me *TencentCloudClient) UseMysqlClient() *cdb.Client {
120116 return me .mysqlConn
121117 }
122118
123- cpf := NewTencentCloudClientProfile (300 )
119+ cpf := me . NewClientProfile (300 )
124120 me .mysqlConn , _ = cdb .NewClient (me .Credential , me .Region , cpf )
125121 me .mysqlConn .WithHttpTransport (& LogRoundTripper {})
126122
@@ -133,7 +129,7 @@ func (me *TencentCloudClient) UseRedisClient() *redis.Client {
133129 return me .redisConn
134130 }
135131
136- cpf := NewTencentCloudClientProfile (300 )
132+ cpf := me . NewClientProfile (300 )
137133 me .redisConn , _ = redis .NewClient (me .Credential , me .Region , cpf )
138134 me .redisConn .WithHttpTransport (& LogRoundTripper {})
139135
@@ -146,7 +142,7 @@ func (me *TencentCloudClient) UseAsClient() *as.Client {
146142 return me .asConn
147143 }
148144
149- cpf := NewTencentCloudClientProfile (300 )
145+ cpf := me . NewClientProfile (300 )
150146 me .asConn , _ = as .NewClient (me .Credential , me .Region , cpf )
151147 me .asConn .WithHttpTransport (& LogRoundTripper {})
152148
@@ -159,7 +155,7 @@ func (me *TencentCloudClient) UseVpcClient() *vpc.Client {
159155 return me .vpcConn
160156 }
161157
162- cpf := NewTencentCloudClientProfile (300 )
158+ cpf := me . NewClientProfile (300 )
163159 me .vpcConn , _ = vpc .NewClient (me .Credential , me .Region , cpf )
164160 me .vpcConn .WithHttpTransport (& LogRoundTripper {})
165161
@@ -172,7 +168,7 @@ func (me *TencentCloudClient) UseCbsClient() *cbs.Client {
172168 return me .cbsConn
173169 }
174170
175- cpf := NewTencentCloudClientProfile (300 )
171+ cpf := me . NewClientProfile (300 )
176172 me .cbsConn , _ = cbs .NewClient (me .Credential , me .Region , cpf )
177173 me .cbsConn .WithHttpTransport (& LogRoundTripper {})
178174
@@ -185,7 +181,7 @@ func (me *TencentCloudClient) UseDcClient() *dc.Client {
185181 return me .dcConn
186182 }
187183
188- cpf := NewTencentCloudClientProfile (300 )
184+ cpf := me . NewClientProfile (300 )
189185 me .dcConn , _ = dc .NewClient (me .Credential , me .Region , cpf )
190186 me .dcConn .WithHttpTransport (& LogRoundTripper {})
191187
@@ -198,7 +194,7 @@ func (me *TencentCloudClient) UseMongodbClient() *mongodb.Client {
198194 return me .mongodbConn
199195 }
200196
201- cpf := NewTencentCloudClientProfile (300 )
197+ cpf := me . NewClientProfile (300 )
202198 me .mongodbConn , _ = mongodb .NewClient (me .Credential , me .Region , cpf )
203199 me .mongodbConn .WithHttpTransport (& LogRoundTripper {})
204200
@@ -211,7 +207,7 @@ func (me *TencentCloudClient) UseClbClient() *clb.Client {
211207 return me .clbConn
212208 }
213209
214- cpf := NewTencentCloudClientProfile (300 )
210+ cpf := me . NewClientProfile (300 )
215211 me .clbConn , _ = clb .NewClient (me .Credential , me .Region , cpf )
216212 me .clbConn .WithHttpTransport (& LogRoundTripper {})
217213
@@ -224,7 +220,7 @@ func (me *TencentCloudClient) UseCvmClient() *cvm.Client {
224220 return me .cvmConn
225221 }
226222
227- cpf := NewTencentCloudClientProfile (300 )
223+ cpf := me . NewClientProfile (300 )
228224 me .cvmConn , _ = cvm .NewClient (me .Credential , me .Region , cpf )
229225 me .cvmConn .WithHttpTransport (& LogRoundTripper {})
230226
@@ -237,7 +233,7 @@ func (me *TencentCloudClient) UseTagClient() *tag.Client {
237233 return me .tagConn
238234 }
239235
240- cpf := NewTencentCloudClientProfile (300 )
236+ cpf := me . NewClientProfile (300 )
241237 me .tagConn , _ = tag .NewClient (me .Credential , me .Region , cpf )
242238 me .tagConn .WithHttpTransport (& LogRoundTripper {})
243239
@@ -250,7 +246,7 @@ func (me *TencentCloudClient) UseTkeClient() *tke.Client {
250246 return me .tkeConn
251247 }
252248
253- cpf := NewTencentCloudClientProfile (300 )
249+ cpf := me . NewClientProfile (300 )
254250 me .tkeConn , _ = tke .NewClient (me .Credential , me .Region , cpf )
255251 me .tkeConn .WithHttpTransport (& LogRoundTripper {})
256252
@@ -263,7 +259,7 @@ func (me *TencentCloudClient) UseGaapClient() *gaap.Client {
263259 return me .gaapConn
264260 }
265261
266- cpf := NewTencentCloudClientProfile (300 )
262+ cpf := me . NewClientProfile (300 )
267263 me .gaapConn , _ = gaap .NewClient (me .Credential , me .Region , cpf )
268264 me .gaapConn .WithHttpTransport (& LogRoundTripper {})
269265
@@ -276,7 +272,7 @@ func (me *TencentCloudClient) UseSslClient() *ssl.Client {
276272 return me .sslConn
277273 }
278274
279- cpf := NewTencentCloudClientProfile (300 )
275+ cpf := me . NewClientProfile (300 )
280276 me .sslConn , _ = ssl .NewClient (me .Credential , me .Region , cpf )
281277 me .sslConn .WithHttpTransport (& LogRoundTripper {})
282278
@@ -289,20 +285,36 @@ func (me *TencentCloudClient) UseCamClient() *cam.Client {
289285 return me .camConn
290286 }
291287
292- cpf := NewTencentCloudClientProfile (300 )
288+ cpf := me . NewClientProfile (300 )
293289 me .camConn , _ = cam .NewClient (me .Credential , me .Region , cpf )
294290 me .camConn .WithHttpTransport (& LogRoundTripper {})
295291
296292 return me .camConn
297293}
298294
295+ // UseStsClient returns sts client for service
296+ func (me * TencentCloudClient ) UseStsClient () * sts.Client {
297+ /*
298+ me.Credential will changed, don't cache it
299+ if me.stsConn != nil {
300+ return me.stsConn
301+ }
302+ */
303+
304+ cpf := me .NewClientProfile (300 )
305+ me .stsConn , _ = sts .NewClient (me .Credential , me .Region , cpf )
306+ me .stsConn .WithHttpTransport (& LogRoundTripper {})
307+
308+ return me .stsConn
309+ }
310+
299311// UseCfsClient returns cfs client for service
300312func (me * TencentCloudClient ) UseCfsClient () * cfs.Client {
301313 if me .cfsConn != nil {
302314 return me .cfsConn
303315 }
304316
305- cpf := NewTencentCloudClientProfile (300 )
317+ cpf := me . NewClientProfile (300 )
306318 me .cfsConn , _ = cfs .NewClient (me .Credential , me .Region , cpf )
307319 me .cfsConn .WithHttpTransport (& LogRoundTripper {})
308320
@@ -315,7 +327,7 @@ func (me *TencentCloudClient) UseScfClient() *scf.Client {
315327 return me .scfConn
316328 }
317329
318- cpf := NewTencentCloudClientProfile (300 )
330+ cpf := me . NewClientProfile (300 )
319331 me .scfConn , _ = scf .NewClient (me .Credential , me .Region , cpf )
320332 me .scfConn .WithHttpTransport (& LogRoundTripper {})
321333
@@ -328,7 +340,7 @@ func (me *TencentCloudClient) UseTcaplusClient() *tcaplusdb.Client {
328340 return me .tcaplusConn
329341 }
330342
331- cpf := NewTencentCloudClientProfile (300 )
343+ cpf := me . NewClientProfile (300 )
332344 me .tcaplusConn , _ = tcaplusdb .NewClient (me .Credential , me .Region , cpf )
333345 me .tcaplusConn .WithHttpTransport (& LogRoundTripper {})
334346
@@ -341,7 +353,7 @@ func (me *TencentCloudClient) UseDayuClient() *dayu.Client {
341353 return me .dayuConn
342354 }
343355
344- cpf := NewTencentCloudClientProfile (300 )
356+ cpf := me . NewClientProfile (300 )
345357 me .dayuConn , _ = dayu .NewClient (me .Credential , me .Region , cpf )
346358 me .dayuConn .WithHttpTransport (& LogRoundTripper {})
347359
@@ -354,7 +366,7 @@ func (me *TencentCloudClient) UseCdnClient() *cdn.Client {
354366 return me .cdnConn
355367 }
356368
357- cpf := NewTencentCloudClientProfile (300 )
369+ cpf := me . NewClientProfile (300 )
358370 me .cdnConn , _ = cdn .NewClient (me .Credential , me .Region , cpf )
359371 me .cdnConn .WithHttpTransport (& LogRoundTripper {})
360372
@@ -367,7 +379,7 @@ func (me *TencentCloudClient) UseMonitorClient() *monitor.Client {
367379 return me .monitorConn
368380 }
369381
370- cpf := NewTencentCloudClientProfile (300 )
382+ cpf := me . NewClientProfile (300 )
371383 me .monitorConn , _ = monitor .NewClient (me .Credential , me .Region , cpf )
372384 me .monitorConn .WithHttpTransport (& LogRoundTripper {})
373385
@@ -380,7 +392,7 @@ func (me *TencentCloudClient) UseEsClient() *es.Client {
380392 return me .esConn
381393 }
382394
383- cpf := NewTencentCloudClientProfile (300 )
395+ cpf := me . NewClientProfile (300 )
384396 me .esConn , _ = es .NewClient (me .Credential , me .Region , cpf )
385397 me .esConn .WithHttpTransport (& LogRoundTripper {})
386398
0 commit comments