15.3.5. 使用 Red Hat Quay API 为命名空间创建一个自动修剪策略
您可以使用 Red Hat Quay API 端点来管理命名空间自动运行策略。
先决条件
- 您已创建了 OAuth 访问令牌。
- 已登陆到 Red Hat Quay。
流程
输入以下
POST /api/v1/organization/{orgname}/autoprunepolicy/命令,创建一个新策略来限制机构中允许的标签数:$ curl -X POST -H "Authorization: Bearer <access_token>" -H "Content-Type: application/json" -d '{"method": "number_of_tags", "value": 10}' http://<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/另外,您可以在创建日期后将标签设置为在指定时间过期:
$ curl -X POST -H "Authorization: Bearer <access_token>" -H "Content-Type: application/json" -d '{ "method": "creation_date", "value": "7d"}' http://<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/输出示例
{"uuid": "73d64f05-d587-42d9-af6d-e726a4a80d6e"}可选。您可以将额外策略添加到机构中,并传递
tagPattern和tagPatternMatches字段,以仅修剪与给定 regex 模式匹配的标签。例如:$ curl -X POST \ -H "Authorization: Bearer <bearer_token>" \ -H "Content-Type: application/json" \ -d '{ "method": "creation_date", "value": "7d", "tagPattern": "^v*", "tagPatternMatches": <true>1 }' \ "https://<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/"- 1
- 将
tagPatternMatches设置为True会导致修剪与给定正则表达式模式匹配的标签。在本例中,与^v*匹配的标签会被修剪。输出示例
{"uuid": "ebf7448b-93c3-4f14-bf2f-25aa6857c7b0"}
您可以使用
PUT /api/v1/organization/{orgname}/autoprunepolicy/{policy_uuid}命令更新机构的自动修剪策略。例如:$ curl -X PUT -H "Authorization: Bearer <bearer_token>" -H "Content-Type: application/json" -d '{ "method": "creation_date", "value": "4d", "tagPattern": "^v*", "tagPatternMatches": true }' "<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/<uuid>"此命令不返回输出。继续下一步。
输入以下命令检查自动修剪策略:
$ curl -X GET -H "Authorization: Bearer <access_token>" http://<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/输出示例
{"policies": [{"uuid": "ebf7448b-93c3-4f14-bf2f-25aa6857c7b0", "method": "creation_date", "value": "4d", "tagPattern": "^v*", "tagPatternMatches": true}, {"uuid": "da4d0ad7-3c2d-4be8-af63-9c51f9a501bc", "method": "number_of_tags", "value": 10, "tagPattern": null, "tagPatternMatches": true}, {"uuid": "17b9fd96-1537-4462-a830-7f53b43f94c2", "method": "creation_date", "value": "7d", "tagPattern": "^v*", "tagPatternMatches": true}]}您可以输入以下命令来删除您的机构的自动修剪策略。请注意,删除策略需要 UUID。
$ curl -X DELETE -H "Authorization: Bearer <access_token>" http://<quay-server.example.com>/api/v1/organization/<organization_name>/autoprunepolicy/73d64f05-d587-42d9-af6d-e726a4a80d6e