|
1 | 1 | # 目录 |
| 2 | +- [目录](#目录) |
2 | 3 | - [集成SDK](#集成sdk) |
3 | | - - [环境要求](#环境要求) |
4 | | - - [访问凭据](#访问凭据) |
5 | | - - [AK、SK设置](#aksk设置) |
6 | | - - [EndPoint配置](#endpoint配置) |
7 | | - - [自定义Endpoint](#自定义endpoint) |
8 | | - - [自定义RegionId](#自定义regionid) |
9 | | - - [自动化Endpoint寻址](#自动化endpoint寻址) |
10 | | - - [Endpoint默认寻址](#endpoint默认寻址) |
11 | | - - [Http连接池配置](#http连接池配置) |
12 | | - - [Https请求配置](#https请求配置) |
13 | | - - [指定scheme](#指定scheme) |
14 | | - - [忽略SSL验证](#忽略ssl验证) |
15 | | - - [超时配置](#超时配置) |
16 | | - - [重试机制](#重试机制) |
17 | | - - [重试代码配置](#重试代码配置) |
18 | | - - [重试条件](#重试条件) |
19 | | - - [默认重试条件](#默认重试条件) |
20 | | - - [自定义重试条件](#自定义重试条件) |
21 | | - - [退避策略](#退避策略) |
22 | | - - [内置退避策略](#内置退避策略) |
23 | | - - [自定义退避策略](#自定义退避策略) |
24 | | - - [异常处理](#异常处理) |
25 | | - - [Debug机制](#debug机制) |
26 | | - - [指定日志Logger](#指定日志logger) |
| 4 | +- [环境要求](#环境要求) |
| 5 | +- [访问凭据](#访问凭据) |
| 6 | + - [AK、SK设置](#aksk设置) |
| 7 | + - [STS Token设置](#sts-token设置) |
| 8 | +- [EndPoint配置](#endpoint配置) |
| 9 | + - [自定义Endpoint](#自定义endpoint) |
| 10 | + - [自定义RegionId](#自定义regionid) |
| 11 | + - [自动化Endpoint寻址](#自动化endpoint寻址) |
| 12 | + - [Endpoint默认寻址](#endpoint默认寻址) |
| 13 | +- [Http连接池配置](#http连接池配置) |
| 14 | +- [Https请求配置](#https请求配置) |
| 15 | + - [指定scheme](#指定scheme) |
| 16 | +- [Http(s)代理配置](#https代理配置) |
| 17 | + - [配置Http(s)代理](#配置https代理) |
| 18 | + - [注意事项](#注意事项) |
| 19 | + - [忽略SSL验证](#忽略ssl验证) |
| 20 | +- [超时配置](#超时配置) |
| 21 | +- [重试机制](#重试机制) |
| 22 | + - [重试代码配置](#重试代码配置) |
| 23 | + - [重试条件](#重试条件) |
| 24 | + - [默认重试条件](#默认重试条件) |
| 25 | + - [自定义重试条件](#自定义重试条件) |
| 26 | + - [退避策略](#退避策略) |
| 27 | + - [内置退避策略](#内置退避策略) |
| 28 | + - [自定义退避策略](#自定义退避策略) |
| 29 | +- [异常处理](#异常处理) |
| 30 | +- [Debug机制](#debug机制) |
| 31 | +- [指定日志Logger](#指定日志logger) |
27 | 32 |
|
28 | 33 | # 集成SDK |
29 | 34 |
|
|
36 | 41 |
|
37 | 42 | # 访问凭据 |
38 | 43 |
|
39 | | -为保障资源访问安全,火山引擎 Python SDK 目前暂时只支持 **AK/SK**认证设置。 |
| 44 | +为保障资源访问安全,火山引擎 Python SDK 目前支持 `AK/SK`和 `STS Token` 认证设置。 |
40 | 45 |
|
41 | 46 | ## AK、SK设置 |
42 | 47 |
|
@@ -83,6 +88,53 @@ except ApiException as e: |
83 | 88 | pass |
84 | 89 | ``` |
85 | 90 |
|
| 91 | +## STS Token设置 |
| 92 | + |
| 93 | +STS(Security Token Service)是火山引擎提供的临时访问凭证机制。开发者通过服务端调用 STS 接口获取临时凭证(临时 AK、SK 和 Token),有效期可配置,适用于安全要求较高的场景。 |
| 94 | + |
| 95 | +> ⚠️ 注意事项 |
| 96 | +> |
| 97 | +> 1. 最小权限: 仅授予调用方访问所需资源的最小权限,避免使用 * 通配符授予全资源、全操作权限。 |
| 98 | +> 2. 设置合理的有效期: 请根据实际情况设置合理有效期,越短越安全,建议不要超过1小时。 |
| 99 | +
|
| 100 | +支持`configuration`级别全局配置和接口级别的运行时参数设置`RuntimeOption`;`RuntimeOption`设置会覆盖`configuration`全局配置。 |
| 101 | + |
| 102 | +**代码示例:** |
| 103 | +```python |
| 104 | +import volcenginesdkcore,volcenginesdkecs |
| 105 | +from volcenginesdkcore.rest import ApiException |
| 106 | +from volcenginesdkcore.interceptor import RuntimeOption |
| 107 | + |
| 108 | +# 全局设置 |
| 109 | +configuration = volcenginesdkcore.Configuration() |
| 110 | +configuration.ak = "Your ak" |
| 111 | +configuration.sk = "Your sk" |
| 112 | +configuration.session_token = "Your session token" |
| 113 | +configuration.debug = True |
| 114 | +volcenginesdkcore.Configuration.set_default(configuration) |
| 115 | + |
| 116 | +# 接口级别运行时参数设置,会覆盖全局配置 |
| 117 | +runtime_options = RuntimeOption( |
| 118 | + ak = "Your ak", |
| 119 | + sk = "Your sk", |
| 120 | + session_token="Your session token", |
| 121 | + client_side_validation = True, # 开启客户端校验,默认开启 |
| 122 | +) |
| 123 | +api_instance = volcenginesdkecs.ECSApi() |
| 124 | +create_command_request = volcenginesdkecs.CreateCommandRequest( |
| 125 | + command_content="ls -l", |
| 126 | + description="Your command description", |
| 127 | + name="Your command name", |
| 128 | + type="command", |
| 129 | + _configuration=runtime_options, # 配置运行时参数 |
| 130 | +) |
| 131 | +try: |
| 132 | + api_instance.create_command(create_command_request) |
| 133 | +except ApiException as e: |
| 134 | + pass |
| 135 | +``` |
| 136 | + |
| 137 | + |
86 | 138 |
|
87 | 139 | # EndPoint配置 |
88 | 140 |
|
@@ -233,6 +285,35 @@ except ApiException as e: |
233 | 285 | pass |
234 | 286 | ``` |
235 | 287 |
|
| 288 | +# Http(s)代理配置 |
| 289 | + |
| 290 | +> - **默认** |
| 291 | +> 无代理 |
| 292 | +
|
| 293 | +## 配置Http(s)代理 |
| 294 | + |
| 295 | +```python |
| 296 | +configuration = volcenginesdkcore.Configuration() |
| 297 | +configuration.ak = "Your AK" |
| 298 | +configuration.sk = "Your SK" |
| 299 | + |
| 300 | +configuration.http_proxy = "http://your_proxy:8080" |
| 301 | +configuration.https_proxy = "http://your_proxy:8080" |
| 302 | + |
| 303 | +volcenginesdkcore.Configuration.set_default(configuration) |
| 304 | + |
| 305 | +api_instance = volcenginesdkecs.ECSApi() |
| 306 | +``` |
| 307 | + |
| 308 | +## 注意事项 |
| 309 | + |
| 310 | +支持通过以下环境变量配置代理: |
| 311 | + |
| 312 | +http_proxy/HTTP_PROXY, https_proxy/HTTPS_PROXY, no_proxy/NO_PROXY |
| 313 | + |
| 314 | +优先级:代码 > 环境变量 |
| 315 | + |
| 316 | + |
236 | 317 | ## 忽略SSL验证 |
237 | 318 |
|
238 | 319 | > **默认** |
|
0 commit comments