tccli-intl-en 3.1.6.1__py2.py3-none-any.whl → 3.1.7.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,714 @@
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+ import sys
4
+ import six
5
+ import json
6
+ import tccli.options_define as OptionsDefine
7
+ import tccli.format_output as FormatOutput
8
+ from tccli import __version__
9
+ from tccli.utils import Utils
10
+ from tccli.exceptions import ConfigurationError, ClientError, ParamError
11
+ from tencentcloud.common import credential
12
+ from tencentcloud.common.profile.http_profile import HttpProfile
13
+ from tencentcloud.common.profile.client_profile import ClientProfile
14
+ from tencentcloud.smh.v20210712 import smh_client as smh_client_v20210712
15
+ from tencentcloud.smh.v20210712 import models as models_v20210712
16
+
17
+ from jmespath import search
18
+ import time
19
+
20
+ def doDescribeOfficialInstances(args, parsed_globals):
21
+ g_param = parse_global_arg(parsed_globals)
22
+
23
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
24
+ cred = credential.CVMRoleCredential()
25
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
26
+ cred = credential.STSAssumeRoleCredential(
27
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
28
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
29
+ )
30
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
31
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
32
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
33
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
34
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
35
+ else:
36
+ cred = credential.Credential(
37
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
38
+ )
39
+ http_profile = HttpProfile(
40
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
41
+ reqMethod="POST",
42
+ endpoint=g_param[OptionsDefine.Endpoint],
43
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
44
+ )
45
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
46
+ if g_param[OptionsDefine.Language]:
47
+ profile.language = g_param[OptionsDefine.Language]
48
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
49
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
50
+ client._sdkVersion += ("_CLI_" + __version__)
51
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
52
+ model = models.DescribeOfficialInstancesRequest()
53
+ model.from_json_string(json.dumps(args))
54
+ start_time = time.time()
55
+ while True:
56
+ rsp = client.DescribeOfficialInstances(model)
57
+ result = rsp.to_json_string()
58
+ try:
59
+ json_obj = json.loads(result)
60
+ except TypeError as e:
61
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
62
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
63
+ break
64
+ cur_time = time.time()
65
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
66
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
67
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
68
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
69
+ else:
70
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
71
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
72
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
73
+
74
+
75
+ def doDescribeLibraries(args, parsed_globals):
76
+ g_param = parse_global_arg(parsed_globals)
77
+
78
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
79
+ cred = credential.CVMRoleCredential()
80
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
81
+ cred = credential.STSAssumeRoleCredential(
82
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
83
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
84
+ )
85
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
86
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
87
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
88
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
89
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
90
+ else:
91
+ cred = credential.Credential(
92
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
93
+ )
94
+ http_profile = HttpProfile(
95
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
96
+ reqMethod="POST",
97
+ endpoint=g_param[OptionsDefine.Endpoint],
98
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
99
+ )
100
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
101
+ if g_param[OptionsDefine.Language]:
102
+ profile.language = g_param[OptionsDefine.Language]
103
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
104
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
105
+ client._sdkVersion += ("_CLI_" + __version__)
106
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
107
+ model = models.DescribeLibrariesRequest()
108
+ model.from_json_string(json.dumps(args))
109
+ start_time = time.time()
110
+ while True:
111
+ rsp = client.DescribeLibraries(model)
112
+ result = rsp.to_json_string()
113
+ try:
114
+ json_obj = json.loads(result)
115
+ except TypeError as e:
116
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
117
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
118
+ break
119
+ cur_time = time.time()
120
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
121
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
122
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
123
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
124
+ else:
125
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
126
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
127
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
128
+
129
+
130
+ def doCreateLibrary(args, parsed_globals):
131
+ g_param = parse_global_arg(parsed_globals)
132
+
133
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
134
+ cred = credential.CVMRoleCredential()
135
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
136
+ cred = credential.STSAssumeRoleCredential(
137
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
138
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
139
+ )
140
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
141
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
142
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
143
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
144
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
145
+ else:
146
+ cred = credential.Credential(
147
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
148
+ )
149
+ http_profile = HttpProfile(
150
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
151
+ reqMethod="POST",
152
+ endpoint=g_param[OptionsDefine.Endpoint],
153
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
154
+ )
155
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
156
+ if g_param[OptionsDefine.Language]:
157
+ profile.language = g_param[OptionsDefine.Language]
158
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
159
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
160
+ client._sdkVersion += ("_CLI_" + __version__)
161
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
162
+ model = models.CreateLibraryRequest()
163
+ model.from_json_string(json.dumps(args))
164
+ start_time = time.time()
165
+ while True:
166
+ rsp = client.CreateLibrary(model)
167
+ result = rsp.to_json_string()
168
+ try:
169
+ json_obj = json.loads(result)
170
+ except TypeError as e:
171
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
172
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
173
+ break
174
+ cur_time = time.time()
175
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
176
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
177
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
178
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
179
+ else:
180
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
181
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
182
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
183
+
184
+
185
+ def doSendSmsCode(args, parsed_globals):
186
+ g_param = parse_global_arg(parsed_globals)
187
+
188
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
189
+ cred = credential.CVMRoleCredential()
190
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
191
+ cred = credential.STSAssumeRoleCredential(
192
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
193
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
194
+ )
195
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
196
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
197
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
198
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
199
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
200
+ else:
201
+ cred = credential.Credential(
202
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
203
+ )
204
+ http_profile = HttpProfile(
205
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
206
+ reqMethod="POST",
207
+ endpoint=g_param[OptionsDefine.Endpoint],
208
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
209
+ )
210
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
211
+ if g_param[OptionsDefine.Language]:
212
+ profile.language = g_param[OptionsDefine.Language]
213
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
214
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
215
+ client._sdkVersion += ("_CLI_" + __version__)
216
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
217
+ model = models.SendSmsCodeRequest()
218
+ model.from_json_string(json.dumps(args))
219
+ start_time = time.time()
220
+ while True:
221
+ rsp = client.SendSmsCode(model)
222
+ result = rsp.to_json_string()
223
+ try:
224
+ json_obj = json.loads(result)
225
+ except TypeError as e:
226
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
227
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
228
+ break
229
+ cur_time = time.time()
230
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
231
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
232
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
233
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
234
+ else:
235
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
236
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
237
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
238
+
239
+
240
+ def doDescribeTrafficPackages(args, parsed_globals):
241
+ g_param = parse_global_arg(parsed_globals)
242
+
243
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
244
+ cred = credential.CVMRoleCredential()
245
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
246
+ cred = credential.STSAssumeRoleCredential(
247
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
248
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
249
+ )
250
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
251
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
252
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
253
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
254
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
255
+ else:
256
+ cred = credential.Credential(
257
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
258
+ )
259
+ http_profile = HttpProfile(
260
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
261
+ reqMethod="POST",
262
+ endpoint=g_param[OptionsDefine.Endpoint],
263
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
264
+ )
265
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
266
+ if g_param[OptionsDefine.Language]:
267
+ profile.language = g_param[OptionsDefine.Language]
268
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
269
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
270
+ client._sdkVersion += ("_CLI_" + __version__)
271
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
272
+ model = models.DescribeTrafficPackagesRequest()
273
+ model.from_json_string(json.dumps(args))
274
+ start_time = time.time()
275
+ while True:
276
+ rsp = client.DescribeTrafficPackages(model)
277
+ result = rsp.to_json_string()
278
+ try:
279
+ json_obj = json.loads(result)
280
+ except TypeError as e:
281
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
282
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
283
+ break
284
+ cur_time = time.time()
285
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
286
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
287
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
288
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
289
+ else:
290
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
291
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
292
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
293
+
294
+
295
+ def doVerifySmsCode(args, parsed_globals):
296
+ g_param = parse_global_arg(parsed_globals)
297
+
298
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
299
+ cred = credential.CVMRoleCredential()
300
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
301
+ cred = credential.STSAssumeRoleCredential(
302
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
303
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
304
+ )
305
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
306
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
307
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
308
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
309
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
310
+ else:
311
+ cred = credential.Credential(
312
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
313
+ )
314
+ http_profile = HttpProfile(
315
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
316
+ reqMethod="POST",
317
+ endpoint=g_param[OptionsDefine.Endpoint],
318
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
319
+ )
320
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
321
+ if g_param[OptionsDefine.Language]:
322
+ profile.language = g_param[OptionsDefine.Language]
323
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
324
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
325
+ client._sdkVersion += ("_CLI_" + __version__)
326
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
327
+ model = models.VerifySmsCodeRequest()
328
+ model.from_json_string(json.dumps(args))
329
+ start_time = time.time()
330
+ while True:
331
+ rsp = client.VerifySmsCode(model)
332
+ result = rsp.to_json_string()
333
+ try:
334
+ json_obj = json.loads(result)
335
+ except TypeError as e:
336
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
337
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
338
+ break
339
+ cur_time = time.time()
340
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
341
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
342
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
343
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
344
+ else:
345
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
346
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
347
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
348
+
349
+
350
+ def doDescribeOfficialOverview(args, parsed_globals):
351
+ g_param = parse_global_arg(parsed_globals)
352
+
353
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
354
+ cred = credential.CVMRoleCredential()
355
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
356
+ cred = credential.STSAssumeRoleCredential(
357
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
358
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
359
+ )
360
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
361
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
362
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
363
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
364
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
365
+ else:
366
+ cred = credential.Credential(
367
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
368
+ )
369
+ http_profile = HttpProfile(
370
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
371
+ reqMethod="POST",
372
+ endpoint=g_param[OptionsDefine.Endpoint],
373
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
374
+ )
375
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
376
+ if g_param[OptionsDefine.Language]:
377
+ profile.language = g_param[OptionsDefine.Language]
378
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
379
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
380
+ client._sdkVersion += ("_CLI_" + __version__)
381
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
382
+ model = models.DescribeOfficialOverviewRequest()
383
+ model.from_json_string(json.dumps(args))
384
+ start_time = time.time()
385
+ while True:
386
+ rsp = client.DescribeOfficialOverview(model)
387
+ result = rsp.to_json_string()
388
+ try:
389
+ json_obj = json.loads(result)
390
+ except TypeError as e:
391
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
392
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
393
+ break
394
+ cur_time = time.time()
395
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
396
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
397
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
398
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
399
+ else:
400
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
401
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
402
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
403
+
404
+
405
+ def doModifyLibrary(args, parsed_globals):
406
+ g_param = parse_global_arg(parsed_globals)
407
+
408
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
409
+ cred = credential.CVMRoleCredential()
410
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
411
+ cred = credential.STSAssumeRoleCredential(
412
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
413
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
414
+ )
415
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
416
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
417
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
418
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
419
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
420
+ else:
421
+ cred = credential.Credential(
422
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
423
+ )
424
+ http_profile = HttpProfile(
425
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
426
+ reqMethod="POST",
427
+ endpoint=g_param[OptionsDefine.Endpoint],
428
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
429
+ )
430
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
431
+ if g_param[OptionsDefine.Language]:
432
+ profile.language = g_param[OptionsDefine.Language]
433
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
434
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
435
+ client._sdkVersion += ("_CLI_" + __version__)
436
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
437
+ model = models.ModifyLibraryRequest()
438
+ model.from_json_string(json.dumps(args))
439
+ start_time = time.time()
440
+ while True:
441
+ rsp = client.ModifyLibrary(model)
442
+ result = rsp.to_json_string()
443
+ try:
444
+ json_obj = json.loads(result)
445
+ except TypeError as e:
446
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
447
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
448
+ break
449
+ cur_time = time.time()
450
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
451
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
452
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
453
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
454
+ else:
455
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
456
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
457
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
458
+
459
+
460
+ def doDeleteLibrary(args, parsed_globals):
461
+ g_param = parse_global_arg(parsed_globals)
462
+
463
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
464
+ cred = credential.CVMRoleCredential()
465
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
466
+ cred = credential.STSAssumeRoleCredential(
467
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
468
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
469
+ )
470
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
471
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
472
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
473
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
474
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
475
+ else:
476
+ cred = credential.Credential(
477
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
478
+ )
479
+ http_profile = HttpProfile(
480
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
481
+ reqMethod="POST",
482
+ endpoint=g_param[OptionsDefine.Endpoint],
483
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
484
+ )
485
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
486
+ if g_param[OptionsDefine.Language]:
487
+ profile.language = g_param[OptionsDefine.Language]
488
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
489
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
490
+ client._sdkVersion += ("_CLI_" + __version__)
491
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
492
+ model = models.DeleteLibraryRequest()
493
+ model.from_json_string(json.dumps(args))
494
+ start_time = time.time()
495
+ while True:
496
+ rsp = client.DeleteLibrary(model)
497
+ result = rsp.to_json_string()
498
+ try:
499
+ json_obj = json.loads(result)
500
+ except TypeError as e:
501
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
502
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
503
+ break
504
+ cur_time = time.time()
505
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
506
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
507
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
508
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
509
+ else:
510
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
511
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
512
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
513
+
514
+
515
+ def doDescribeLibrarySecret(args, parsed_globals):
516
+ g_param = parse_global_arg(parsed_globals)
517
+
518
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
519
+ cred = credential.CVMRoleCredential()
520
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
521
+ cred = credential.STSAssumeRoleCredential(
522
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
523
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
524
+ )
525
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) \
526
+ and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) \
527
+ and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) \
528
+ and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
529
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
530
+ else:
531
+ cred = credential.Credential(
532
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
533
+ )
534
+ http_profile = HttpProfile(
535
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
536
+ reqMethod="POST",
537
+ endpoint=g_param[OptionsDefine.Endpoint],
538
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
539
+ )
540
+ profile = ClientProfile(httpProfile=http_profile, signMethod="TC3-HMAC-SHA256")
541
+ if g_param[OptionsDefine.Language]:
542
+ profile.language = g_param[OptionsDefine.Language]
543
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
544
+ client = mod.SmhClient(cred, g_param[OptionsDefine.Region], profile)
545
+ client._sdkVersion += ("_CLI_" + __version__)
546
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
547
+ model = models.DescribeLibrarySecretRequest()
548
+ model.from_json_string(json.dumps(args))
549
+ start_time = time.time()
550
+ while True:
551
+ rsp = client.DescribeLibrarySecret(model)
552
+ result = rsp.to_json_string()
553
+ try:
554
+ json_obj = json.loads(result)
555
+ except TypeError as e:
556
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
557
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
558
+ break
559
+ cur_time = time.time()
560
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
561
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
562
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
563
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
564
+ else:
565
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
566
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
567
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
568
+
569
+
570
+ CLIENT_MAP = {
571
+ "v20210712": smh_client_v20210712,
572
+
573
+ }
574
+
575
+ MODELS_MAP = {
576
+ "v20210712": models_v20210712,
577
+
578
+ }
579
+
580
+ ACTION_MAP = {
581
+ "DescribeOfficialInstances": doDescribeOfficialInstances,
582
+ "DescribeLibraries": doDescribeLibraries,
583
+ "CreateLibrary": doCreateLibrary,
584
+ "SendSmsCode": doSendSmsCode,
585
+ "DescribeTrafficPackages": doDescribeTrafficPackages,
586
+ "VerifySmsCode": doVerifySmsCode,
587
+ "DescribeOfficialOverview": doDescribeOfficialOverview,
588
+ "ModifyLibrary": doModifyLibrary,
589
+ "DeleteLibrary": doDeleteLibrary,
590
+ "DescribeLibrarySecret": doDescribeLibrarySecret,
591
+
592
+ }
593
+
594
+ AVAILABLE_VERSION_LIST = [
595
+ "v20210712",
596
+
597
+ ]
598
+
599
+
600
+ def action_caller():
601
+ return ACTION_MAP
602
+
603
+
604
+ def parse_global_arg(parsed_globals):
605
+ g_param = parsed_globals
606
+ cvm_role_flag = True
607
+ for param in parsed_globals.keys():
608
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.RoleArn,
609
+ OptionsDefine.RoleSessionName]:
610
+ if parsed_globals[param] is not None:
611
+ cvm_role_flag = False
612
+ break
613
+ is_exist_profile = True
614
+ if not parsed_globals["profile"]:
615
+ is_exist_profile = False
616
+ g_param["profile"] = os.environ.get("TCCLI_PROFILE", "default")
617
+
618
+ configure_path = os.path.join(os.path.expanduser("~"), ".tccli")
619
+ is_conf_exist, conf_path = Utils.file_existed(configure_path, g_param["profile"] + ".configure")
620
+ is_cred_exist, cred_path = Utils.file_existed(configure_path, g_param["profile"] + ".credential")
621
+
622
+ conf = {}
623
+ cred = {}
624
+
625
+ if is_conf_exist:
626
+ conf = Utils.load_json_msg(conf_path)
627
+ if is_cred_exist:
628
+ cred = Utils.load_json_msg(cred_path)
629
+
630
+ if not (isinstance(conf, dict) and isinstance(cred, dict)):
631
+ raise ConfigurationError(
632
+ "file: %s or %s is not json format"
633
+ % (g_param["profile"] + ".configure", g_param["profile"] + ".credential"))
634
+
635
+ if OptionsDefine.Token not in cred:
636
+ cred[OptionsDefine.Token] = None
637
+
638
+ if not is_exist_profile:
639
+ if os.environ.get(OptionsDefine.ENV_SECRET_ID) and os.environ.get(OptionsDefine.ENV_SECRET_KEY):
640
+ cred[OptionsDefine.SecretId] = os.environ.get(OptionsDefine.ENV_SECRET_ID)
641
+ cred[OptionsDefine.SecretKey] = os.environ.get(OptionsDefine.ENV_SECRET_KEY)
642
+ cred[OptionsDefine.Token] = os.environ.get(OptionsDefine.ENV_TOKEN)
643
+ cvm_role_flag = False
644
+
645
+ if os.environ.get(OptionsDefine.ENV_REGION):
646
+ conf[OptionsDefine.SysParam][OptionsDefine.Region] = os.environ.get(OptionsDefine.ENV_REGION)
647
+
648
+ if os.environ.get(OptionsDefine.ENV_ROLE_ARN) and os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME):
649
+ cred[OptionsDefine.RoleArn] = os.environ.get(OptionsDefine.ENV_ROLE_ARN)
650
+ cred[OptionsDefine.RoleSessionName] = os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME)
651
+ cvm_role_flag = False
652
+
653
+ if cvm_role_flag:
654
+ if "type" in cred and cred["type"] == "cvm-role":
655
+ g_param[OptionsDefine.UseCVMRole.replace('-', '_')] = True
656
+
657
+ for param in g_param.keys():
658
+ if g_param[param] is None:
659
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.Token]:
660
+ if param in cred:
661
+ g_param[param] = cred[param]
662
+ elif not (g_param[OptionsDefine.UseCVMRole.replace('-', '_')]
663
+ or os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN)):
664
+ raise ConfigurationError("%s is invalid" % param)
665
+ elif param in [OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.Language]:
666
+ if param in conf[OptionsDefine.SysParam]:
667
+ g_param[param] = conf[OptionsDefine.SysParam][param]
668
+ elif param != OptionsDefine.Language:
669
+ raise ConfigurationError("%s is invalid" % param)
670
+ elif param.replace('_', '-') in [OptionsDefine.RoleArn, OptionsDefine.RoleSessionName]:
671
+ if param.replace('_', '-') in cred:
672
+ g_param[param] = cred[param.replace('_', '-')]
673
+
674
+ try:
675
+ if g_param[OptionsDefine.ServiceVersion]:
676
+ g_param[OptionsDefine.Version] = "v" + g_param[OptionsDefine.ServiceVersion].replace('-', '')
677
+ else:
678
+ version = conf["smh"][OptionsDefine.Version]
679
+ g_param[OptionsDefine.Version] = "v" + version.replace('-', '')
680
+
681
+ if g_param[OptionsDefine.Endpoint] is None:
682
+ g_param[OptionsDefine.Endpoint] = conf["smh"][OptionsDefine.Endpoint]
683
+ g_param["sts_cred_endpoint"] = conf.get("sts", {}).get("endpoint")
684
+ except Exception as err:
685
+ raise ConfigurationError("config file:%s error, %s" % (conf_path, str(err)))
686
+
687
+ if g_param[OptionsDefine.Version] not in AVAILABLE_VERSION_LIST:
688
+ raise Exception("available versions: %s" % " ".join(AVAILABLE_VERSION_LIST))
689
+
690
+ if g_param[OptionsDefine.Waiter]:
691
+ param = eval(g_param[OptionsDefine.Waiter])
692
+ if 'expr' not in param:
693
+ raise Exception('`expr` in `--waiter` must be defined')
694
+ if 'to' not in param:
695
+ raise Exception('`to` in `--waiter` must be defined')
696
+ if 'timeout' not in param:
697
+ if 'waiter' in conf and 'timeout' in conf['waiter']:
698
+ param['timeout'] = conf['waiter']['timeout']
699
+ else:
700
+ param['timeout'] = 180
701
+ if 'interval' not in param:
702
+ if 'waiter' in conf and 'interval' in conf['waiter']:
703
+ param['interval'] = conf['waiter']['interval']
704
+ else:
705
+ param['interval'] = 5
706
+ param['interval'] = min(param['interval'], param['timeout'])
707
+ g_param['OptionsDefine.WaiterInfo'] = param
708
+
709
+ if six.PY2:
710
+ for key, value in g_param.items():
711
+ if isinstance(value, six.text_type):
712
+ g_param[key] = value.encode('utf-8')
713
+ return g_param
714
+