Skip to content

Commit 4ac2dcf

Browse files
committed
Improve endpoint document
1 parent c8accab commit 4ac2dcf

File tree

3 files changed

+114
-61
lines changed

3 files changed

+114
-61
lines changed

Diff for: docs/6-Endpoint-CN.md

+56-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
1-
# 域名
2-
3-
Endpoint 是请求访问的域名
4-
5-
优先级:request > profile > rules
6-
7-
```python
8-
from aliyunsdkcore.client import AcsClient
9-
from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest
10-
11-
client = AcsClient(
12-
'ACCESS_KEY_ID',
13-
'ACCESS_KEY_SECRET',
14-
)
15-
# 全局生效
16-
client.add_endpoint("region_id", "product", "your endpoint")
17-
18-
request = DescribeRegionsRequest()
19-
# 只对当前request生效
20-
request.endpoint = 'your endpoint'
21-
# 拼接规则设置网络,参数:share、 inner、 vpc、 public
22-
request.request_network = 'public'
23-
response = client.do_action_with_exception(request)
24-
```
25-
26-
拼接规则方式需要产品端支持并符合规范方可使用。
1+
# 域名
2+
3+
Endpoint 是请求接口服务的网络域名,如 `ecs.cn-hangzhou.aliyuncs.com`
4+
5+
### Endpoint 寻址
6+
7+
[相关源码](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/endpoint/default_endpoint_resolver.py)
8+
9+
1. 用户自定义
10+
11+
`用户自定义`是优先级最高的寻址逻辑,可以直接指定 endpoint 的具体内容。
12+
13+
```python
14+
# 全局生效
15+
client = AcsClient()
16+
client.add_endpoint("<region_id>", "<product>", "<endpoint>")
17+
18+
# 只对当前 Request 生效
19+
request = DescribeRegionsRequest()
20+
request.set_endpoint("<endpoint>")
21+
```
22+
23+
2. Endpoint 拼接规则
24+
25+
在请求 vpc 网络时或产品 SDK 具有 Endpoint 数据文件时,当前寻址逻辑才会生效。 Endpoint 数据文件示例 ([Ecs Endpoint Data File](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-ecs/aliyunsdkecs/endpoint.py))
26+
27+
```python
28+
# 公网请求
29+
request.request_network = "public" # 因为 `network` 的默认值为 `public`,所以默认情况下不需要配置 `network`
30+
31+
# 跨域请求
32+
request.request_network = "share"
33+
34+
# Ipv6 请求
35+
request.request_network = "ipv6"
36+
37+
# 代理请求
38+
request.request_network = "proxy"
39+
40+
# 内部请求
41+
request.request_network = "inner"
42+
43+
# Ipv4/Ipv6 双协议栈
44+
request.request_network = "dualstack"
45+
46+
# vpc 请求
47+
request.request_network = "vpc"
48+
```
49+
50+
3. 根据 Python SDK Core 中的 [endpoints.json](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/data/endpoints.json) 数据文件进行寻址
51+
52+
内部操作,无需额外配置。
53+
54+
4. 请求 Location 服务接口,从远端获取
55+
56+
需要产品 SDK 具备 `ServiceCode`

Diff for: docs/6-Endpoint-EN.md

+55-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
1-
# Endpoint
2-
3-
The endpoint is the domain you want to access
4-
5-
Priority:request > profile > rules
6-
7-
```python
8-
from aliyunsdkcore.client import AcsClient
9-
from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest
10-
11-
client = AcsClient(
12-
'ACCESS_KEY_ID',
13-
'ACCESS_KEY_SECRET',
14-
)
15-
# global
16-
client.add_endpoint("region_id", "product", "your endpoint")
17-
18-
request = DescribeRegionsRequest()
19-
# Only the current request is valid
20-
request.endpoint = 'your endpoint'
21-
# Splicing rules set the network; parameter:share、 inner、 vpc、 public
22-
request.request_network = 'public'
23-
response = client.do_action_with_exception(request)
24-
```
25-
26-
Splicing rules need to be supported by the product side and conform to the specification before they can be used。
1+
# Endpoint
2+
3+
Endpoint is the domain name of the service API. like `ecs.cn-hangzhou.aliyuncs.com`
4+
5+
### Search Endpoint
6+
7+
[Related source code](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/endpoint/default_endpoint_resolver.py)
8+
9+
1. User custom defined
10+
11+
`User custom defined` is the highest-priority logic to search endpoint and allows you to specify endpoint specifics directly.
12+
13+
```python
14+
# Global effect
15+
client = AcsClient()
16+
client.add_endpoint("<region_id>", "<product>", "<endpoint>")
17+
18+
19+
# Only works for the current request
20+
request = DescribeRegionsRequest()
21+
request.set_endpoint("<endpoint>")
22+
```
23+
24+
2. Endpoint Splicing Rules
25+
26+
`Endpoint Splicing Rules` does not take effect until the vpc network is enabled or the product SDK has an Endpoint data file. Endpoint Data File Example : ([Ecs Endpoint Data File](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-ecs/aliyunsdkecs/endpoint.py))
27+
28+
```python
29+
# Public network request(default)
30+
request.request_network = "public" # Since the default value of `network` is `public`, there is no need to configure `network` by default.
31+
32+
# Share-domain request
33+
request.request_network = "share"
34+
35+
# Ipv6 network request
36+
request.request_network = "ipv6"
37+
38+
# Proxy network request
39+
request.request_network = "proxy"
40+
41+
# Internal network request
42+
request.request_network = "inner"
43+
44+
# Ipv4/Ipv6 Dual Stack
45+
request.request_network = "dualstack"
46+
47+
# Vpc network request
48+
request.request_network = "vpc"
49+
```
50+
51+
3. Search endpoint from the [endpoints.json](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/data/endpoints.json) endpoint data file in the Java SDK Core Internal operation, no additional configuration required.
52+
53+
4. Request Location Service API to get `Endpoint` from the remote end.
54+
55+
Requires product SDK with `ServiceCode`.

Diff for: python-sdk-functional-test/new_endpoint_test.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from aliyunsdkcore.client import AcsClient
2121
from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest
2222
from aliyunsdkram.request.v20150501.ListAccessKeysRequest import ListAccessKeysRequest
23-
from aliyunsdkros.request.v20150901.DescribeResourcesRequest import DescribeResourcesRequest
23+
from aliyunsdkcs.request.v20151215.DescribeApiVersionRequest import DescribeApiVersionRequest
2424
from aliyunsdkcloudapi.request.v20160714.DescribeApisRequest import DescribeApisRequest
2525
import aliyunsdkcore.acs_exception.error_code as error_code
2626

@@ -338,14 +338,8 @@ def test_call_rpc_request_with_client(self):
338338
response = self.client.do_action_with_exception(request)
339339

340340
def test_call_roa_request_with_client(self):
341-
request = DescribeResourcesRequest()
342-
request.set_StackId("StackId")
343-
request.set_StackName("StackName")
344-
try:
345-
response = self.client.do_action_with_exception(request)
346-
assert False
347-
except ServerException as e:
348-
self.assertEqual("StackNotFound", e.get_error_code())
341+
request = DescribeApiVersionRequest()
342+
self.client.do_action_with_exception(request)
349343

350344
def test_location_service_code_not_equals_product_code(self):
351345
request = DescribeApisRequest()

0 commit comments

Comments
 (0)