Help us learn about your current experience with the documentation. Take the survey.
容器仓库保护规则 API
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed
列出容器仓库保护规则
获取项目容器仓库中的容器仓库保护规则列表。
GET /api/v4/projects/:id/registry/protection/repository/rules支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
如果成功,将返回状态码 200 和一个容器仓库保护规则列表。
可能返回以下状态码:
200 OK:保护规则列表。401 Unauthorized:访问令牌无效。403 Forbidden:用户没有权限列出此项目的保护规则。404 Not Found:未找到项目。
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules"示例响应:
[
{
"id": 1,
"project_id": 7,
"repository_path_pattern": "flightjs/flight0",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer"
},
{
"id": 2,
"project_id": 7,
"repository_path_pattern": "flightjs/flight1",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer"
},
]创建容器仓库保护规则
为项目的容器仓库创建容器仓库保护规则。
POST /api/v4/projects/:id/registry/protection/repository/rules支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
repository_path_pattern |
string | 是 | 受保护规则保护的容器仓库路径模式。例如 flight/flight-*。允许使用通配符 *。 |
minimum_access_level_for_push |
string | 否 | 向容器仓库推送容器镜像所需的最低 GitLab 访问级别。例如 maintainer、owner 或 admin。当未设置 minimum_access_level_for_delete 时,必须提供此参数。 |
minimum_access_level_for_delete |
string | 否 | 在容器仓库中删除容器镜像所需的最低 GitLab 访问级别。例如 maintainer、owner、admin。当未设置 minimum_access_level_for_push 时,必须提供此参数。 |
如果成功,将返回状态码 201 和已创建的容器仓库保护规则。
可能返回以下状态码:
201 Created:保护规则创建成功。400 Bad Request:保护规则无效。401 Unauthorized:访问令牌无效。403 Forbidden:用户没有权限创建保护规则。404 Not Found:未找到项目。422 Unprocessable Entity:无法创建保护规则。例如,因为repository_path_pattern已被占用。
示例请求:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules" \
--data '{
"repository_path_pattern": "flightjs/flight-needs-to-be-a-unique-path",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer"
}'更新容器仓库保护规则
更新项目容器仓库中的容器仓库保护规则。
PATCH /api/v4/projects/:id/registry/protection/repository/rules/:protection_rule_id支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
protection_rule_id |
integer | 是 | 要更新的保护规则的 ID。 |
repository_path_pattern |
string | 否 | 受保护规则保护的容器仓库路径模式。例如 flight/flight-*。允许使用通配符 *。 |
minimum_access_level_for_push |
string | 否 | 向容器仓库推送容器镜像所需的最低 GitLab 访问级别。例如 maintainer、owner 或 admin。当未设置 minimum_access_level_for_delete 时,必须提供此参数。要取消设置该值,请使用空字符串 ""。 |
minimum_access_level_for_delete |
string | 否 | 在容器仓库中删除容器镜像所需的最低 GitLab 访问级别。例如 maintainer、owner、admin。当未设置 minimum_access_level_for_push 时,必须提供此参数。要取消设置该值,请使用空字符串 ""。 |
如果成功,将返回状态码 200 和更新后的保护规则。
可能返回以下状态码:
200 OK:保护规则更新成功。400 Bad Request:保护规则无效。401 Unauthorized:访问令牌无效。403 Forbidden:用户没有权限更新保护规则。404 Not Found:未找到项目。422 Unprocessable Entity:无法更新保护规则。例如,因为repository_path_pattern已被占用。
示例请求:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules/32" \
--data '{
"repository_path_pattern": "flight/flight-*"
}'删除容器仓库保护规则
从项目的容器仓库中删除容器仓库保护规则。
DELETE /api/v4/projects/:id/registry/protection/repository/rules/:protection_rule_id支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码路径。 |
protection_rule_id |
integer | 是 | 要删除的容器仓库保护规则的 ID。 |
如果成功,将返回状态码 204 No Content。
可能返回以下状态码:
204 No Content:保护规则删除成功。400 Bad Request:id或protection_rule_id缺失或无效。401 Unauthorized:访问令牌无效。403 Forbidden:用户没有权限删除保护规则。404 Not Found:未找到项目或保护规则。
示例请求:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/7/registry/protection/repository/rules/1"