|
4 | 4 | - [环境要求](#环境要求) |
5 | 5 | - [访问凭据](#访问凭据) |
6 | 6 | - [AK、SK设置](#aksk设置) |
| 7 | + - [STS Token设置](#sts-token设置) |
7 | 8 | - [EndPoint配置](#endpoint配置) |
8 | 9 | - [自定义Endpoint](#自定义endpoint) |
9 | 10 | - [自定义RegionId](#自定义regionid) |
|
40 | 41 |
|
41 | 42 | # 访问凭据 |
42 | 43 |
|
43 | | -为保障资源访问安全,火山引擎 Python SDK 目前暂时只支持 **AK/SK**认证设置。 |
| 44 | +为保障资源访问安全,火山引擎 Python SDK 目前支持 `AK/SK`和 `STS Token` 认证设置。 |
44 | 45 |
|
45 | 46 | ## AK、SK设置 |
46 | 47 |
|
@@ -87,6 +88,53 @@ except ApiException as e: |
87 | 88 | pass |
88 | 89 | ``` |
89 | 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 | + |
90 | 138 |
|
91 | 139 | # EndPoint配置 |
92 | 140 |
|
|
0 commit comments