# 凭据

> 节点访问外部系统时使用的凭据。

Source: https://docs.sommatic.ai/zh/api/reference/credentials/

## 创建新凭据。

`POST /platform-infrastructure/credential/`

返回根据所提供数据创建的凭据。

认证: Bearer 令牌

### 请求体

要创建的凭据对象。

- `organization_id` (string): 此凭据所关联组织的标识符。
- `slug` (string, 必填): 在组织或租户内唯一标识此凭据的稳定语义键。
- `name` (string, 必填): 凭据的可读名称，用于编辑器、日志和审计记录。
- `type` (PlatformInfrastructureCredentialType, 必填): 凭据类型对象 { id, name, title, color }。
  - `id` (integer, 必填): 类型的数字标识符。
  - `name` (string, 必填): 机器可读的类型名称。
  - `title` (string, 必填): 可读标签。
  - `color` (string): 类型徽标的 UI 颜色，可选。
- `description` (string): 可选描述，说明此凭据的用途及适用场景。
- `connector_slug` (string): 此凭据主要关联的 ConnectorModel 引用，可选。
- `provider` (PlatformInfrastructureCredentialProvider): 标识外部服务的提供方对象 { id, name, title, color }，可选。
  - `id` (integer, 必填): 提供方的数字标识符。
  - `name` (string, 必填): 机器可读的提供方名称。
  - `title` (string, 必填): 可读标签。
  - `color` (string): 提供方徽标的 UI 颜色，可选。
- `secret_backend` (string): 保存实际密钥材料的密钥存储后端标识符（例如 "sommatics-vault"、"aws-kms"）。
- `secret_handle` (object): 以 AES-256-GCM 加密的密钥材料，存储为 { iv, content, tag }。创建时加密，仅由 resolve 端点解密。
- `masked_preview` (string): 密钥的掩码预览（例如最后 4 个字符），可选，仅用于 UI 显示。
- `scopes` (array<string>): 与此凭据关联的权限范围、角色或 API 授权列表，可选。
- `allowed_connector_slugs` (array<string>): 允许使用此凭据进行出站调用的连接器键列表，可选。
- `expires_at` (string): 过期时间戳，可选，过期后不得再使用此凭据。
- `last_rotated_at` (string): 底层密钥材料最近一次成功轮换的时间戳。
- `rotation_policy` (PlatformInfrastructureCredentialRotationPolicy): 可选的轮换策略，说明此凭据应如何以及何时轮换。
  - `enabled` (boolean): 此凭据是否启用轮换。
  - `strategy` (object): 轮换策略 { id, name, title }。
    - `id` (integer)
    - `name` (string)
    - `title` (string)
  - `interval_days` (integer): 两次轮换之间的天数。strategy 为 "scheduled" 时适用。
  - `notify_before_days` (integer): 轮换前多少天发送通知。
- `is_revoked` (boolean): 表示此凭据是否已被吊销、不得再使用。
- `is_enabled` (boolean): 表示此凭据当前是否处于激活状态且可用。
- `is_system` (boolean): 表示此凭据是否由平台管理，而非用户创建。
- `tags` (array<string>): 用于治理、搜索和报表的自由格式标签列表，可选。

### 响应

- `200`: 成功。
- `500`: 执行此操作时出错。

### 请求示例

```bash
curl -X POST "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "slug": "<slug>",
       "name": "<name>",
       "type": {
         "id": 0,
         "name": "<name>",
         "title": "<title>"
       }
     }'
```

## 更新现有凭据。

`PATCH /platform-infrastructure/credential/`

使用所提供的数据更新现有凭据。

认证: Bearer 令牌

### 请求体

要更新的凭据对象。

- `organization_id` (string): 此凭据所关联组织的标识符。
- `slug` (string, 必填): 在组织或租户内唯一标识此凭据的稳定语义键。
- `name` (string, 必填): 凭据的可读名称，用于编辑器、日志和审计记录。
- `type` (PlatformInfrastructureCredentialType, 必填): 凭据类型对象 { id, name, title, color }。
  - `id` (integer, 必填): 类型的数字标识符。
  - `name` (string, 必填): 机器可读的类型名称。
  - `title` (string, 必填): 可读标签。
  - `color` (string): 类型徽标的 UI 颜色，可选。
- `description` (string): 可选描述，说明此凭据的用途及适用场景。
- `connector_slug` (string): 此凭据主要关联的 ConnectorModel 引用，可选。
- `provider` (PlatformInfrastructureCredentialProvider): 标识外部服务的提供方对象 { id, name, title, color }，可选。
  - `id` (integer, 必填): 提供方的数字标识符。
  - `name` (string, 必填): 机器可读的提供方名称。
  - `title` (string, 必填): 可读标签。
  - `color` (string): 提供方徽标的 UI 颜色，可选。
- `secret_backend` (string): 保存实际密钥材料的密钥存储后端标识符（例如 "sommatics-vault"、"aws-kms"）。
- `secret_handle` (object): 以 AES-256-GCM 加密的密钥材料，存储为 { iv, content, tag }。创建时加密，仅由 resolve 端点解密。
- `masked_preview` (string): 密钥的掩码预览（例如最后 4 个字符），可选，仅用于 UI 显示。
- `scopes` (array<string>): 与此凭据关联的权限范围、角色或 API 授权列表，可选。
- `allowed_connector_slugs` (array<string>): 允许使用此凭据进行出站调用的连接器键列表，可选。
- `expires_at` (string): 过期时间戳，可选，过期后不得再使用此凭据。
- `last_rotated_at` (string): 底层密钥材料最近一次成功轮换的时间戳。
- `rotation_policy` (PlatformInfrastructureCredentialRotationPolicy): 可选的轮换策略，说明此凭据应如何以及何时轮换。
  - `enabled` (boolean): 此凭据是否启用轮换。
  - `strategy` (object): 轮换策略 { id, name, title }。
    - `id` (integer)
    - `name` (string)
    - `title` (string)
  - `interval_days` (integer): 两次轮换之间的天数。strategy 为 "scheduled" 时适用。
  - `notify_before_days` (integer): 轮换前多少天发送通知。
- `is_revoked` (boolean): 表示此凭据是否已被吊销、不得再使用。
- `is_enabled` (boolean): 表示此凭据当前是否处于激活状态且可用。
- `is_system` (boolean): 表示此凭据是否由平台管理，而非用户创建。
- `tags` (array<string>): 用于治理、搜索和报表的自由格式标签列表，可选。

### 响应

- `200`: 成功。
- `500`: 执行此操作时出错。

### 请求示例

```bash
curl -X PATCH "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "slug": "<slug>",
       "name": "<name>",
       "type": {
         "id": 0,
         "name": "<name>",
         "title": "<title>"
       }
     }'
```

## 按 ID 删除凭据。

`DELETE /platform-infrastructure/credential/`

根据提供的 ID 删除凭据。

认证: Bearer 令牌

### 请求体

要删除的凭据 ID

- `id` (string)

### 响应

- `200`: 成功。
- `500`: 执行此操作时出错。

### 请求示例

```bash
curl -X DELETE "https://api.sommatic.ai/platform-infrastructure/credential/" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
       "id": "<id>"
     }'
```

## 按查询选择器获取凭据。

`GET /platform-infrastructure/credential/{queryselector}`

返回与路由中指定的查询选择器和搜索条件匹配的凭据信息。

认证: Bearer 令牌

### 参数

- `queryselector` (path, enum, 必填): 此查询可用的筛选条件 可选值: `id`, `organization-id`, `all`, `status`.
- `search` (query, string): 用于搜索实体的关键字。
- `include_status` (query, string): 可选的状态参数，用于包含指定状态的凭据。
- `exclude_status` (query, string): 可选的状态参数，用于排除指定状态的凭据。
- `page` (query, integer): 页码，从 1 开始（默认 1）。
- `pageSize` (query, integer): 每页记录数（默认 25）。

### 响应

- `200`: 成功。
- `500`: 执行此操作时出错。

### 请求示例

```bash
curl -X GET "https://api.sommatic.ai/platform-infrastructure/credential/<queryselector>" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN"
```
