Skip to content

Commit a519398

Browse files
release 3.0.5-beta source code for python
1 parent cb2a419 commit a519398

File tree

643 files changed

+116619
-3463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

643 files changed

+116619
-3463
lines changed

CHANGELOG.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
# __3.0.4-beta__ __2020-6-30__
2+
## __HuaweiCloud SDK Core__
3+
- ### Features
4+
- None
5+
- ### Bug Fix
6+
- None
7+
- ### Change
8+
- Use with_http_handler to replace with_enable_http_log to support users to customize the request log output in the troubleshooting scenario.
9+
10+
## __HuaweiCloud SDK CTS__
11+
- ### Features
12+
- Support Cloud Trace Service.
13+
- ### Bug Fix
14+
- None
15+
- ### Change
16+
- None
17+
18+
## __HuaweiCloud SDK EVS__
19+
- ### Features
20+
- None
21+
- ### Bug Fix
22+
- None
23+
- ### Change
24+
- Support full service interface.
25+
26+
## __HuaweiCloud SDK IoTDA__
27+
- ### Features
28+
- Support IoT Device Access Service.
29+
- ### Bug Fix
30+
- None
31+
- ### Change
32+
- None
33+
34+
135
# __3.0.3-beta__ __2020-06-15__
236
## __HuaweiCloud SDK Core__
337
- ### Features
@@ -9,7 +43,6 @@
943
- ### Change
1044
- None
1145

12-
# __3.0.3-beta__ __2020-06-15__
1346
## __HuaweiCloud SDK DevStar__
1447
- ### Features
1548
- Support query template list.

CHANGELOG_CN.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
# __3.0.4-beta__ __2020-06-30__
2+
## __HuaweiCloud SDK Core__
3+
- ### 新增特性
4+
-
5+
- ### 解决问题
6+
-
7+
- ### 特性变更
8+
- 使用with_http_handler替代原有的with_enable_http_log开关,支持用户在问题定位场景自定义请求日志输出。
9+
10+
## __HuaweiCloud SDK CTS__
11+
- ### 新增特性
12+
- 支持云审计服务。
13+
- ### 解决问题
14+
-
15+
- ### 特性变更
16+
-
17+
18+
## __HuaweiCloud SDK EVS__
19+
- ### 新增特性
20+
-
21+
- ### 解决问题
22+
-
23+
- ### 特性变更
24+
- 支持全量服务接口。
25+
26+
## __HuaweiCloud SDK IoTDA__
27+
- ### 新增特性
28+
- 支持设备接入服务。
29+
- ### 解决问题
30+
-
31+
- ### 特性变更
32+
-
33+
34+
135
# __3.0.3-beta__ __2020-06-15__
236
## __HuaweiCloud SDK Core__
337
- ### 新增特性
@@ -9,7 +43,6 @@
943
- ### 特性变更
1044
-
1145

12-
# __3.0.3-beta__ __2020-06-15__
1346
## __HuaweiCloud SDK DevStar__
1447
- ### 新增特性
1548
- 支持查询模板列表。

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
118118
.with_endpoint(endpoint) \
119119
.with_file_log(path="test.log", log_level=logging.INFO) \ # Write log files
120120
.with_stream_log(log_level=logging.INFO) \ # Write log to console
121-
.with_enable_http_log(True) \ # log whole http request and response
122121
.build()
123122
```
124123

@@ -134,8 +133,11 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
134133
- `stream`: stream object, default is sys.stdout.
135134
- `log_level`: log level, default is INFO.
136135

137-
**Warning**
138-
- `with_enable_http_log`: We recommend you only use this for debugging purposes. Disable it in your production environments, as it records the whole request and response data, which may contains sensitive data, and it could be very large.
136+
After enabled log, the SDK will print the access log by default, every request will be recorded in console like: '%(asctime)s %(thread)d %(name)s %(filename)s %(lineno)d %(levelname)s %(message)s'
137+
138+
```shell script
139+
2020-06-16 10:44:02,019 4568 HuaweiCloud-SDK http_handler.py 28 INFO "GET https://vpc.cn-north-1.myhuaweicloud.com/v1/0904f9e1f100d2932f94c01f9aa1cfd7/vpcs" 200 11 0:00:00.543430 b5c927ffdab8401e772e70aa49972037
140+
```
139141

140142
5. Send a request and print response.
141143

@@ -185,6 +187,47 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
185187
print(response.result())
186188
```
187189

190+
8. Troubleshooting
191+
192+
In some situation, you may need to debug your http requests, original http request and response information will be needed. The SDK provides a listener function to obtain the original encrypted http request and response information.
193+
194+
**Warning:** The original http log can only be used in troubleshooting scenarios, please do not print the original http header or body in the production environment. The log content is not encrypted and may contain sensitive information such as the password of your ECS or the password of your IAM user account, etc. When the response body is binary content, the body will be printed as "***" without detailed information.
195+
196+
```python
197+
def response_handler(**kwargs):
198+
logger = kwargs.get("logger")
199+
response = kwargs.get("response")
200+
request = response.request
201+
202+
base = "> Request %s %s HTTP/1.1" % (request.method, request.path_url) + "\n"
203+
if len(request.headers) != 0:
204+
base = base + "> Headers:" + "\n"
205+
for each in request.headers:
206+
base = base + " %s : %s" % (each, request.headers[each]) + "\n"
207+
base = base + "> Body: %s" % request.body + "\n\n"
208+
209+
base = base + "< Response HTTP/1.1 %s " % response.status_code + "\n"
210+
if len(response.headers) != 0:
211+
base = base + "< Headers:" + "\n"
212+
for each in response.headers:
213+
base = base + " %s : %s" % (each, response.headers[each],) + "\n"
214+
base = base + "< Body: %s" % response.content
215+
logger.debug(base)
216+
217+
client = VpcClient.new_builder(VpcClient) \
218+
.with_http_config(config) \
219+
.with_credentials(credentials) \
220+
.with_endpoint(endpoint) \
221+
.with_file_log(path="test.log", log_level=logging.INFO) \
222+
.with_stream_log(log_level=logging.INFO) \
223+
.with_http_handler(HttpHandler().add_response_handler(response_handler)) \
224+
.build()
225+
```
226+
227+
**where:**
228+
229+
HttpHandler supports add_request_handler and add_response_handler.
230+
188231
## Code example
189232

190233
The following example shows how to query a list of VPC in a specific region. Substitute the values for `{your ak string}`, `{your sk string}`, `{your endpoint}` and `{your project id}`.

README_CN.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
.with_endpoint(endpoint) \
122122
.with_file_log(path="test.log", log_level=logging.INFO) \ # 日志打印至文件
123123
.with_stream_log(log_level=logging.INFO) \ # 日志打印至控制台
124-
.with_enable_http_log(True) \ # 打开HTTP请求日志
125124
.build()
126125
```
127126

@@ -136,9 +135,12 @@
136135
- `with_stream_log` 支持如下配置:
137136
- `stream`: 流对象,默认sys.stdout。
138137
- `log_level`: 日志级别,默认INFO。
139-
140-
**注意:**
141-
- `with_enable_http_log`: http日志仅用于开发场景下的问题定位,生产环境不推荐打开此功能。由于此功能会打印详细的请求以及相应信息,可能包含敏感信息,同时可能导致日志文件过大。
138+
139+
打开日志开关后,每次请求将打印访问日志,格式如下:'%(asctime)s %(thread)d %(name)s %(filename)s %(lineno)d %(levelname)s %(message)s'
140+
141+
```shell script
142+
2020-06-16 10:44:02,019 4568 HuaweiCloud-SDK http_handler.py 28 INFO "GET https://vpc.cn-north-1.myhuaweicloud.com/v1/0904f9e1f100d2932f94c01f9aa1cfd7/vpcs" 200 11 0:00:00.543430 b5c927ffdab8401e772e70aa49972037
143+
```
142144

143145
5. 发送请求并查看响应.
144146

@@ -158,7 +160,7 @@
158160
| | | RetryOutageException | 在重试策略消耗完成已后,仍无有效的响应 |
159161
| ServiceResponseException | 服务器响应异常 | ServerResponseException | 服务端内部错误,Http响应码:[500,] |
160162
| | | ClientRequestException | 请求参数不合法,Http响应码:[400, 500) |
161-
163+
162164
```python
163165
# 异常处理
164166
try:
@@ -188,6 +190,48 @@
188190
print(response.result())
189191
```
190192

193+
8. 问题定位
194+
195+
在某些场景下可能对业务发出的Http请求进行Debug,需要看到原始的Http请求和返回信息,SDK提供侦听器功能来获取原始的为加密的Http请求和返回信息。
196+
197+
**注意:** 原始信息打印仅在debug阶段使用,请不要在生产系统中将原始的Http头和Body信息打印到日志,这些信息并未加密且其中包含敏感数据,例如所创建虚拟机的密码,IAM用户的密码等;
198+
当Body体为二进制内容,即Content-Type标识为二进制时 body为"***",详细内容不输出。
199+
200+
```python
201+
def response_handler(**kwargs):
202+
logger = kwargs.get("logger")
203+
response = kwargs.get("response")
204+
request = response.request
205+
206+
base = "> Request %s %s HTTP/1.1" % (request.method, request.path_url) + "\n"
207+
if len(request.headers) != 0:
208+
base = base + "> Headers:" + "\n"
209+
for each in request.headers:
210+
base = base + " %s : %s" % (each, request.headers[each]) + "\n"
211+
base = base + "> Body: %s" % request.body + "\n\n"
212+
213+
base = base + "< Response HTTP/1.1 %s " % response.status_code + "\n"
214+
if len(response.headers) != 0:
215+
base = base + "< Headers:" + "\n"
216+
for each in response.headers:
217+
base = base + " %s : %s" % (each, response.headers[each],) + "\n"
218+
base = base + "< Body: %s" % response.content
219+
logger.debug(base)
220+
221+
client = VpcClient.new_builder(VpcClient) \
222+
.with_http_config(config) \
223+
.with_credentials(credentials) \
224+
.with_endpoint(endpoint) \
225+
.with_file_log(path="test.log", log_level=logging.INFO) \
226+
.with_stream_log(log_level=logging.INFO) \
227+
.with_http_handler(HttpHandler().add_response_handler(response_handler)) \
228+
.build()
229+
```
230+
231+
**说明:**
232+
233+
HttpHandler支持如下方法add_request_handler、add_response_handler。
234+
191235
## 代码实例
192236
193237
使用如下代码同步查询特定Region下的VPC清单,调用前请根据实际情况替换如下变量:`{your ak string}``{your sk string}``{your endpoint}` 以及 `{your project id}`

README_PYPI.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
116116
.with_endpoint(endpoint) \
117117
.with_file_log(path="test.log", log_level=logging.INFO) \ # Write log files
118118
.with_stream_log(log_level=logging.INFO) \ # Write log to console
119-
.with_enable_http_log(True) \ # log whole http request and response
120119
.build()
121120
```
122121

@@ -131,9 +130,12 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
131130
- `with_stream_log`:
132131
- `stream`: stream object, default is sys.stdout.
133132
- `log_level`: log level, default is INFO.
134-
135-
**Warning**
136-
- `with_enable_http_log`: We recommend you only use this for debugging purposes. Disable it in your production environments, as it records the whole request and response data, which may contains sensitive data, and it could be very large.
133+
134+
After enabled log, the SDK will print the access log by default, every request will be recorded in console like: '%(asctime)s %(thread)d %(name)s %(filename)s %(lineno)d %(levelname)s %(message)s'
135+
136+
```shell script
137+
2020-06-16 10:44:02,019 4568 HuaweiCloud-SDK http_handler.py 28 INFO "GET https://vpc.cn-north-1.myhuaweicloud.com/v1/0904f9e1f100d2932f94c01f9aa1cfd7/vpcs" 200 11 0:00:00.543430 b5c927ffdab8401e772e70aa49972037
138+
```
137139

138140
5. Send a request and print response.
139141

@@ -181,3 +183,44 @@ HuaweiCloud Python SDK supports Python 3 or later. Run ``python --version`` to c
181183
# get asynchronous response
182184
print(response.result())
183185
```
186+
187+
8. Troubleshooting
188+
189+
In some situation, you may need to debug your http requests, original http request and response information will be needed. The SDK provides a listener function to obtain the original encrypted http request and response information.
190+
191+
**Warning:** The original http log can only be used in troubleshooting scenarios, please do not print the original http header or body in the production environment. The log content is not encrypted and may contain sensitive information such as the password of your ECS or the password of your IAM user account, etc. When the response body is binary content, the body will be printed as "***" without detailed information.
192+
193+
```python
194+
def response_handler(**kwargs):
195+
logger = kwargs.get("logger")
196+
response = kwargs.get("response")
197+
request = response.request
198+
199+
base = "> Request %s %s HTTP/1.1" % (request.method, request.path_url) + "\n"
200+
if len(request.headers) != 0:
201+
base = base + "> Headers:" + "\n"
202+
for each in request.headers:
203+
base = base + " %s : %s" % (each, request.headers[each]) + "\n"
204+
base = base + "> Body: %s" % request.body + "\n\n"
205+
206+
base = base + "< Response HTTP/1.1 %s " % response.status_code + "\n"
207+
if len(response.headers) != 0:
208+
base = base + "< Headers:" + "\n"
209+
for each in response.headers:
210+
base = base + " %s : %s" % (each, response.headers[each],) + "\n"
211+
base = base + "< Body: %s" % response.content
212+
logger.debug(base)
213+
214+
client = {Service}Client.new_builder({Service}Client) \
215+
.with_http_config(config) \
216+
.with_credentials(credentials) \
217+
.with_endpoint(endpoint) \
218+
.with_file_log(path="test.log", log_level=logging.INFO) \
219+
.with_stream_log(log_level=logging.INFO) \
220+
.with_http_handler(HttpHandler().add_response_handler(response_handler)) \
221+
.build()
222+
```
223+
224+
**where:**
225+
226+
HttpHandler supports add_request_handler and add_response_handler.

examples/IoTDA/V5/BatchTask.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# coding: utf-8
2+
from huaweicloudsdkcore.http.http_config import HttpConfig
3+
from huaweicloudsdkcore.auth.credentials import BasicCredentials
4+
from huaweicloudsdkcore.exceptions import exceptions
5+
from huaweicloudsdkiotda.v5 import *
6+
7+
8+
def createBatchTask(client):
9+
try:
10+
app_id = "vWT2abBX135ioL_D028b7NRYJfYa"
11+
document = {
12+
"package_id": "24381244be486f8b3a89ad07"
13+
}
14+
targets = [
15+
"5e19ca2b16b09003ca4dbd98_test003"
16+
]
17+
task_name = "BatchCommandTask"
18+
task_type = "softwareUpgrade"
19+
body = CreateBatchTask(app_id=app_id, document=document, targets=targets, task_name=task_name,
20+
task_type=task_type)
21+
request = CreateBatchTaskRequest(body=body)
22+
response = client.create_batch_task(request)
23+
print(response)
24+
except exceptions.ClientRequestException as e:
25+
print(e.status_code)
26+
print(e.request_id)
27+
print(e.error_code)
28+
print(e.error_msg)
29+
30+
31+
def queryBatchTask(client):
32+
try:
33+
request = ShowBatchTaskRequest(taskId="5ea53331251c3e02075b1499")
34+
response = client.show_batch_task(request)
35+
print(response)
36+
except exceptions.ClientRequestException as e:
37+
print(e.status_code)
38+
print(e.request_id)
39+
print(e.error_code)
40+
print(e.error_msg)
41+
42+
43+
def queryBatchTasks(client):
44+
try:
45+
request = ListBatchTasksRequest(task_type="softwareUpgrade", marker="ffffffffffffffffffffffff")
46+
response = client.list_batch_tasks(request)
47+
print(response)
48+
except exceptions.ClientRequestException as e:
49+
print(e.status_code)
50+
print(e.request_id)
51+
print(e.error_code)
52+
print(e.error_msg)
53+
54+
55+
if __name__ == '__main__':
56+
ak = "{your ak string}"
57+
sk = "{your sk string}"
58+
endpoint = "{your endpoint}"
59+
project_id = "{your project id}"
60+
61+
config = HttpConfig.get_default_config()
62+
config.ignore_ssl_verification = True
63+
credentials = BasicCredentials(ak, sk, project_id)
64+
65+
iotda_client = IoTDAClient().new_builder(IoTDAClient) \
66+
.with_http_config(config) \
67+
.with_credentials(credentials) \
68+
.with_endpoint(endpoint) \
69+
.build()
70+
71+
createBatchTask(iotda_client)
72+
queryBatchTask(iotda_client)
73+
queryBatchTasks(iotda_client)

0 commit comments

Comments
 (0)