tccli 3.0.1193.1__py2.py3-none-any.whl → 3.0.1195.1__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
tccli/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '3.0.1193.1'
1
+ __version__ = '3.0.1195.1'
@@ -492,6 +492,9 @@ SERVICE_VERSIONS = {
492
492
  "mps": [
493
493
  "2019-06-12"
494
494
  ],
495
+ "mqtt": [
496
+ "2024-05-16"
497
+ ],
495
498
  "mrs": [
496
499
  "2020-09-10"
497
500
  ],
@@ -4182,6 +4182,15 @@
4182
4182
  "name": "InstanceId",
4183
4183
  "required": true,
4184
4184
  "type": "string"
4185
+ },
4186
+ {
4187
+ "disabled": false,
4188
+ "document": "变更集群版实例只读组时,InstanceId传实例id,需要额外指定该参数表示操作只读组。 如果操作读写节点则不需指定该参数。",
4189
+ "example": "cdb-xxx|readonly",
4190
+ "member": "string",
4191
+ "name": "OpResourceId",
4192
+ "required": false,
4193
+ "type": "string"
4185
4194
  }
4186
4195
  ],
4187
4196
  "type": "object"
@@ -15995,6 +16004,15 @@
15995
16004
  "name": "ForReadonlyInstance",
15996
16005
  "required": false,
15997
16006
  "type": "bool"
16007
+ },
16008
+ {
16009
+ "disabled": false,
16010
+ "document": "变更集群版实例只读组时,InstanceId传实例id,需要额外指定该参数表示操作只读组。 如果操作读写节点则不需指定该参数。",
16011
+ "example": "cdb-xxx|readonly",
16012
+ "member": "string",
16013
+ "name": "OpResourceId",
16014
+ "required": false,
16015
+ "type": "string"
15998
16016
  }
15999
16017
  ],
16000
16018
  "type": "object"
@@ -16067,6 +16085,15 @@
16067
16085
  "name": "ReleaseDuration",
16068
16086
  "required": false,
16069
16087
  "type": "int"
16088
+ },
16089
+ {
16090
+ "disabled": false,
16091
+ "document": "变更集群版实例只读组时,InstanceId传实例id,需要额外指定该参数表示操作只读组。 如果操作读写节点则不需指定该参数。",
16092
+ "example": "cdb-xxx|readonly",
16093
+ "member": "string",
16094
+ "name": "OpResourceId",
16095
+ "required": false,
16096
+ "type": "string"
16070
16097
  }
16071
16098
  ],
16072
16099
  "type": "object"
@@ -16874,6 +16901,15 @@
16874
16901
  "name": "InstanceId",
16875
16902
  "required": true,
16876
16903
  "type": "string"
16904
+ },
16905
+ {
16906
+ "disabled": false,
16907
+ "document": "变更集群版实例只读组时,InstanceId传实例id,需要额外指定该参数表示操作只读组。 如果操作读写节点则不需指定该参数。",
16908
+ "example": "cdb-xxx|readonly",
16909
+ "member": "string",
16910
+ "name": "OpResourceId",
16911
+ "required": false,
16912
+ "type": "string"
16877
16913
  }
16878
16914
  ],
16879
16915
  "type": "object"
@@ -20049,6 +20085,15 @@
20049
20085
  "name": "WaitSwitch",
20050
20086
  "required": false,
20051
20087
  "type": "bool"
20088
+ },
20089
+ {
20090
+ "disabled": false,
20091
+ "document": "集群版实例指定节点id发起主从切换。",
20092
+ "example": "dbn-xxx",
20093
+ "member": "string",
20094
+ "name": "DstNodeId",
20095
+ "required": false,
20096
+ "type": "string"
20052
20097
  }
20053
20098
  ],
20054
20099
  "type": "object"
@@ -8634,7 +8634,7 @@
8634
8634
  },
8635
8635
  {
8636
8636
  "disabled": false,
8637
- "document": "服务模版id\n注意:此字段可能返回 null,表示取不到有效值。",
8637
+ "document": "服务模板id\n注意:此字段可能返回 null,表示取不到有效值。",
8638
8638
  "example": "tpm-xxxx",
8639
8639
  "member": "string",
8640
8640
  "name": "ServiceTemplateId",
@@ -8684,7 +8684,7 @@
8684
8684
  },
8685
8685
  {
8686
8686
  "disabled": false,
8687
- "document": "源模版名称\n注意:此字段可能返回 null,表示取不到有效值。",
8687
+ "document": "源模板名称\n注意:此字段可能返回 null,表示取不到有效值。",
8688
8688
  "example": "test",
8689
8689
  "member": "string",
8690
8690
  "name": "SouParameterName",
@@ -8734,7 +8734,7 @@
8734
8734
  },
8735
8735
  {
8736
8736
  "disabled": false,
8737
- "document": "目的模版名称\n注意:此字段可能返回 null,表示取不到有效值。",
8737
+ "document": "目的模板名称\n注意:此字段可能返回 null,表示取不到有效值。",
8738
8738
  "example": "test",
8739
8739
  "member": "string",
8740
8740
  "name": "ParameterName",
@@ -8744,7 +8744,7 @@
8744
8744
  },
8745
8745
  {
8746
8746
  "disabled": false,
8747
- "document": "端口模版名称\n注意:此字段可能返回 null,表示取不到有效值。",
8747
+ "document": "端口模板名称\n注意:此字段可能返回 null,表示取不到有效值。",
8748
8748
  "example": "test",
8749
8749
  "member": "string",
8750
8750
  "name": "ProtocolPortName",
@@ -4906,7 +4906,7 @@
4906
4906
  },
4907
4907
  {
4908
4908
  "disabled": false,
4909
- "document": "请求发起源,默认为vss表示漏洞扫描服务,云安全中心的用户请填充csip",
4909
+ "document": "请求发起源,vss表示漏洞扫描服务,云安全中心的用户请填充csip,默认csip",
4910
4910
  "example": "vss/csip",
4911
4911
  "member": "string",
4912
4912
  "name": "ScanFrom",
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from tccli.services.mqtt.mqtt_client import action_caller
4
+
@@ -0,0 +1,248 @@
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.mqtt.v20240516 import mqtt_client as mqtt_client_v20240516
15
+ from tencentcloud.mqtt.v20240516 import models as models_v20240516
16
+
17
+ from jmespath import search
18
+ import time
19
+
20
+ def doDescribeInstance(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) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
31
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
32
+ else:
33
+ cred = credential.Credential(
34
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
35
+ )
36
+ http_profile = HttpProfile(
37
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
38
+ reqMethod="POST",
39
+ endpoint=g_param[OptionsDefine.Endpoint],
40
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
41
+ )
42
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
43
+ if g_param[OptionsDefine.Language]:
44
+ profile.language = g_param[OptionsDefine.Language]
45
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
46
+ client = mod.MqttClient(cred, g_param[OptionsDefine.Region], profile)
47
+ client._sdkVersion += ("_CLI_" + __version__)
48
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
49
+ model = models.DescribeInstanceRequest()
50
+ model.from_json_string(json.dumps(args))
51
+ start_time = time.time()
52
+ while True:
53
+ rsp = client.DescribeInstance(model)
54
+ result = rsp.to_json_string()
55
+ try:
56
+ json_obj = json.loads(result)
57
+ except TypeError as e:
58
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
59
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
60
+ break
61
+ cur_time = time.time()
62
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
63
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
64
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
65
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
66
+ else:
67
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
68
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
69
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
70
+
71
+
72
+ def doDescribeInstanceList(args, parsed_globals):
73
+ g_param = parse_global_arg(parsed_globals)
74
+
75
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
76
+ cred = credential.CVMRoleCredential()
77
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
78
+ cred = credential.STSAssumeRoleCredential(
79
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
80
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
81
+ )
82
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
83
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
84
+ else:
85
+ cred = credential.Credential(
86
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
87
+ )
88
+ http_profile = HttpProfile(
89
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
90
+ reqMethod="POST",
91
+ endpoint=g_param[OptionsDefine.Endpoint],
92
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
93
+ )
94
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
95
+ if g_param[OptionsDefine.Language]:
96
+ profile.language = g_param[OptionsDefine.Language]
97
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
98
+ client = mod.MqttClient(cred, g_param[OptionsDefine.Region], profile)
99
+ client._sdkVersion += ("_CLI_" + __version__)
100
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
101
+ model = models.DescribeInstanceListRequest()
102
+ model.from_json_string(json.dumps(args))
103
+ start_time = time.time()
104
+ while True:
105
+ rsp = client.DescribeInstanceList(model)
106
+ result = rsp.to_json_string()
107
+ try:
108
+ json_obj = json.loads(result)
109
+ except TypeError as e:
110
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
111
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
112
+ break
113
+ cur_time = time.time()
114
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
115
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
116
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
117
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
118
+ else:
119
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
120
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
121
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
122
+
123
+
124
+ CLIENT_MAP = {
125
+ "v20240516": mqtt_client_v20240516,
126
+
127
+ }
128
+
129
+ MODELS_MAP = {
130
+ "v20240516": models_v20240516,
131
+
132
+ }
133
+
134
+ ACTION_MAP = {
135
+ "DescribeInstance": doDescribeInstance,
136
+ "DescribeInstanceList": doDescribeInstanceList,
137
+
138
+ }
139
+
140
+ AVAILABLE_VERSION_LIST = [
141
+ "v20240516",
142
+
143
+ ]
144
+
145
+
146
+ def action_caller():
147
+ return ACTION_MAP
148
+
149
+
150
+ def parse_global_arg(parsed_globals):
151
+ g_param = parsed_globals
152
+
153
+ is_exist_profile = True
154
+ if not parsed_globals["profile"]:
155
+ is_exist_profile = False
156
+ g_param["profile"] = os.environ.get("TCCLI_PROFILE", "default")
157
+
158
+ configure_path = os.path.join(os.path.expanduser("~"), ".tccli")
159
+ is_conf_exist, conf_path = Utils.file_existed(configure_path, g_param["profile"] + ".configure")
160
+ is_cred_exist, cred_path = Utils.file_existed(configure_path, g_param["profile"] + ".credential")
161
+
162
+ conf = {}
163
+ cred = {}
164
+
165
+ if is_conf_exist:
166
+ conf = Utils.load_json_msg(conf_path)
167
+ if is_cred_exist:
168
+ cred = Utils.load_json_msg(cred_path)
169
+
170
+ if not (isinstance(conf, dict) and isinstance(cred, dict)):
171
+ raise ConfigurationError(
172
+ "file: %s or %s is not json format"
173
+ % (g_param["profile"] + ".configure", g_param["profile"] + ".credential"))
174
+
175
+ if OptionsDefine.Token not in cred:
176
+ cred[OptionsDefine.Token] = None
177
+
178
+ if not is_exist_profile:
179
+ if os.environ.get(OptionsDefine.ENV_SECRET_ID) and os.environ.get(OptionsDefine.ENV_SECRET_KEY):
180
+ cred[OptionsDefine.SecretId] = os.environ.get(OptionsDefine.ENV_SECRET_ID)
181
+ cred[OptionsDefine.SecretKey] = os.environ.get(OptionsDefine.ENV_SECRET_KEY)
182
+ cred[OptionsDefine.Token] = os.environ.get(OptionsDefine.ENV_TOKEN)
183
+
184
+ if os.environ.get(OptionsDefine.ENV_REGION):
185
+ conf[OptionsDefine.SysParam][OptionsDefine.Region] = os.environ.get(OptionsDefine.ENV_REGION)
186
+
187
+ if os.environ.get(OptionsDefine.ENV_ROLE_ARN) and os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME):
188
+ cred[OptionsDefine.RoleArn] = os.environ.get(OptionsDefine.ENV_ROLE_ARN)
189
+ cred[OptionsDefine.RoleSessionName] = os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME)
190
+
191
+ for param in g_param.keys():
192
+ if g_param[param] is None:
193
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.Token]:
194
+ if param in cred:
195
+ g_param[param] = cred[param]
196
+ elif not (g_param[OptionsDefine.UseCVMRole.replace('-', '_')]
197
+ or os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN)):
198
+ raise ConfigurationError("%s is invalid" % param)
199
+ elif param in [OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.Language]:
200
+ if param in conf[OptionsDefine.SysParam]:
201
+ g_param[param] = conf[OptionsDefine.SysParam][param]
202
+ elif param != OptionsDefine.Language:
203
+ raise ConfigurationError("%s is invalid" % param)
204
+ elif param.replace('_', '-') in [OptionsDefine.RoleArn, OptionsDefine.RoleSessionName]:
205
+ if param.replace('_', '-') in cred:
206
+ g_param[param] = cred[param.replace('_', '-')]
207
+
208
+ try:
209
+ if g_param[OptionsDefine.ServiceVersion]:
210
+ g_param[OptionsDefine.Version] = "v" + g_param[OptionsDefine.ServiceVersion].replace('-', '')
211
+ else:
212
+ version = conf["mqtt"][OptionsDefine.Version]
213
+ g_param[OptionsDefine.Version] = "v" + version.replace('-', '')
214
+
215
+ if g_param[OptionsDefine.Endpoint] is None:
216
+ g_param[OptionsDefine.Endpoint] = conf["mqtt"][OptionsDefine.Endpoint]
217
+ g_param["sts_cred_endpoint"] = conf.get("sts", {}).get("endpoint")
218
+ except Exception as err:
219
+ raise ConfigurationError("config file:%s error, %s" % (conf_path, str(err)))
220
+
221
+ if g_param[OptionsDefine.Version] not in AVAILABLE_VERSION_LIST:
222
+ raise Exception("available versions: %s" % " ".join(AVAILABLE_VERSION_LIST))
223
+
224
+ if g_param[OptionsDefine.Waiter]:
225
+ param = eval(g_param[OptionsDefine.Waiter])
226
+ if 'expr' not in param:
227
+ raise Exception('`expr` in `--waiter` must be defined')
228
+ if 'to' not in param:
229
+ raise Exception('`to` in `--waiter` must be defined')
230
+ if 'timeout' not in param:
231
+ if 'waiter' in conf and 'timeout' in conf['waiter']:
232
+ param['timeout'] = conf['waiter']['timeout']
233
+ else:
234
+ param['timeout'] = 180
235
+ if 'interval' not in param:
236
+ if 'waiter' in conf and 'interval' in conf['waiter']:
237
+ param['interval'] = conf['waiter']['interval']
238
+ else:
239
+ param['interval'] = 5
240
+ param['interval'] = min(param['interval'], param['timeout'])
241
+ g_param['OptionsDefine.WaiterInfo'] = param
242
+
243
+ if six.PY2:
244
+ for key, value in g_param.items():
245
+ if isinstance(value, six.text_type):
246
+ g_param[key] = value.encode('utf-8')
247
+ return g_param
248
+