Files
Olares/docs/zh/developer/develop/advanced/secret.md
2025-07-17 11:58:59 +08:00

132 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
outline: [2, 3]
---
# 密钥
在应用中通常需要保存一些重要的用户信息例如外部系统的“密码”和“访问令牌”。Olares 提供了一个统一的 Vault 安全存储各种密钥(基于 Infisical
应用只需要做简单的申请,即可获得接口访问权限。申请方式是在应用 Chart 的 [OlaresManifest.yaml](../package/manifest.md#sysdata) 中添加 `sysData` 权限,例如:
```yaml
permission:
sysData:
- dataType: secret
group: secret.infisical
version: v1
ops:
- RetrieveSecret?workspace=your-app # 每个应用申明自己独立的workspace
- CreateSecret?workspace=your-app
- DeleteSecret?workspace=your-app
- UpdateSecret?workspace=your-app
- ListSecret?workspace=your-app
```
## 调用接口
你可以像请求其他 Provider 一样调用 API。使用 ops 的全名(包括 workspace 参数)作为 URI。
调用接口时需要加入 header。
```http
X-Authorization: <cookie auth_token>
```
### RetrieveSecret
- **Request Body**
```json
{
"name": "string", // secret name
"env": "string" // environment of secret, test | dev | staging | prod (default)
}
```
- **Success Response**
```json
{
"code": http.StatusOK, // 200 is ok
"message": "",
"data":{
"name": "string", // secret name
"value": "string", // secret value
"env": "string" // environment of secret, test | dev | staging | prod
}
}
```
### CreateSecret
- **Request Body**
```json
{
"name": "string", // secret name
"value": "string", // secret value
"env": "string" // environment of secret, test | dev | staging | prod (default)
}
```
- **Success Response**
```json
{
"code": http.StatusOK, // 200 is ok
"message": "",
"data":""
}
```
### DeleteSecret
- **Request Body**
```json
{
"name": "string", // secret name
"env": "string" // environment of secret, test | dev | staging | prod (default)
}
```
- **Success Response**
```json
{
"code": http.StatusOK, // 200 is ok
"message": "",
"data":""
}
```
### UpdateSecret
- **Request Body**
```json
{
"name": "string", // secret name
"value": "string", // secret value
"env": "string" // environment of secret, test | dev | staging | prod (default)
}
```
- **Success Response**
```json
{
"code": http.StatusOK, // 200 is ok
"message": "",
"data":""
}
```
### ListSecret
- **Request Body**
```json
{
"env": "string" // environment of secret, test | dev | staging | prod (default)
}
```
- **Success Response**
```json
{
"code": http.StatusOK, // 200 is ok
"message": "",
"data":{
"name": "string", // secret name
"value": "string", // secret value
"env": "string" // environment of secret, test | dev | staging | prod
}
}
```