forked from aliyun/aliyun-openapi-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,56 @@ | ||
# 域名 | ||
|
||
Endpoint 是请求访问的域名 | ||
|
||
优先级:request > profile > rules | ||
|
||
```python | ||
from aliyunsdkcore.client import AcsClient | ||
from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest | ||
|
||
client = AcsClient( | ||
'ACCESS_KEY_ID', | ||
'ACCESS_KEY_SECRET', | ||
) | ||
# 全局生效 | ||
client.add_endpoint("region_id", "product", "your endpoint") | ||
|
||
request = DescribeRegionsRequest() | ||
# 只对当前request生效 | ||
request.endpoint = 'your endpoint' | ||
# 拼接规则设置网络,参数:share、 inner、 vpc、 public | ||
request.request_network = 'public' | ||
response = client.do_action_with_exception(request) | ||
``` | ||
|
||
拼接规则方式需要产品端支持并符合规范方可使用。 | ||
# 域名 | ||
|
||
Endpoint 是请求接口服务的网络域名,如 `ecs.cn-hangzhou.aliyuncs.com` | ||
|
||
### Endpoint 寻址 | ||
|
||
[相关源码](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/endpoint/default_endpoint_resolver.py) | ||
|
||
1. 用户自定义 | ||
|
||
`用户自定义`是优先级最高的寻址逻辑,可以直接指定 endpoint 的具体内容。 | ||
|
||
```python | ||
# 全局生效 | ||
client = AcsClient() | ||
client.add_endpoint("<region_id>", "<product>", "<endpoint>") | ||
|
||
# 只对当前 Request 生效 | ||
request = DescribeRegionsRequest() | ||
request.set_endpoint("<endpoint>") | ||
``` | ||
|
||
2. Endpoint 拼接规则 | ||
|
||
在请求 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)) | ||
|
||
```python | ||
# 公网请求 | ||
request.request_network = "public" # 因为 `network` 的默认值为 `public`,所以默认情况下不需要配置 `network` | ||
|
||
# 跨域请求 | ||
request.request_network = "share" | ||
|
||
# Ipv6 请求 | ||
request.request_network = "ipv6" | ||
|
||
# 代理请求 | ||
request.request_network = "proxy" | ||
|
||
# 内部请求 | ||
request.request_network = "inner" | ||
|
||
# Ipv4/Ipv6 双协议栈 | ||
request.request_network = "dualstack" | ||
|
||
# vpc 请求 | ||
request.request_network = "vpc" | ||
``` | ||
|
||
3. 根据 Python SDK Core 中的 [endpoints.json](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/data/endpoints.json) 数据文件进行寻址 | ||
|
||
内部操作,无需额外配置。 | ||
|
||
4. 请求 Location 服务接口,从远端获取 | ||
|
||
需要产品 SDK 具备 `ServiceCode` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,55 @@ | ||
# Endpoint | ||
|
||
The endpoint is the domain you want to access | ||
|
||
Priority:request > profile > rules | ||
|
||
```python | ||
from aliyunsdkcore.client import AcsClient | ||
from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest | ||
|
||
client = AcsClient( | ||
'ACCESS_KEY_ID', | ||
'ACCESS_KEY_SECRET', | ||
) | ||
# global | ||
client.add_endpoint("region_id", "product", "your endpoint") | ||
|
||
request = DescribeRegionsRequest() | ||
# Only the current request is valid | ||
request.endpoint = 'your endpoint' | ||
# Splicing rules set the network; parameter:share、 inner、 vpc、 public | ||
request.request_network = 'public' | ||
response = client.do_action_with_exception(request) | ||
``` | ||
|
||
Splicing rules need to be supported by the product side and conform to the specification before they can be used。 | ||
# Endpoint | ||
|
||
Endpoint is the domain name of the service API. like `ecs.cn-hangzhou.aliyuncs.com` | ||
|
||
### Search Endpoint | ||
|
||
[Related source code](https://github.com/aliyun/aliyun-openapi-python-sdk/blob/master/aliyun-python-sdk-core/aliyunsdkcore/endpoint/default_endpoint_resolver.py) | ||
|
||
1. User custom defined | ||
|
||
`User custom defined` is the highest-priority logic to search endpoint and allows you to specify endpoint specifics directly. | ||
|
||
```python | ||
# Global effect | ||
client = AcsClient() | ||
client.add_endpoint("<region_id>", "<product>", "<endpoint>") | ||
|
||
|
||
# Only works for the current request | ||
request = DescribeRegionsRequest() | ||
request.set_endpoint("<endpoint>") | ||
``` | ||
|
||
2. Endpoint Splicing Rules | ||
|
||
`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)) | ||
|
||
```python | ||
# Public network request(default) | ||
request.request_network = "public" # Since the default value of `network` is `public`, there is no need to configure `network` by default. | ||
|
||
# Share-domain request | ||
request.request_network = "share" | ||
|
||
# Ipv6 network request | ||
request.request_network = "ipv6" | ||
|
||
# Proxy network request | ||
request.request_network = "proxy" | ||
|
||
# Internal network request | ||
request.request_network = "inner" | ||
|
||
# Ipv4/Ipv6 Dual Stack | ||
request.request_network = "dualstack" | ||
|
||
# Vpc network request | ||
request.request_network = "vpc" | ||
``` | ||
|
||
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. | ||
|
||
4. Request Location Service API to get `Endpoint` from the remote end. | ||
|
||
Requires product SDK with `ServiceCode`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters