|
| 1 | +[id="creating-repository-policy-api"] |
| 2 | += Creating an auto-prune policy for a repository using the {productname} API |
| 3 | + |
| 4 | +You can use {productname} API endpoints to manage auto-pruning policies for an repository. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | + |
| 8 | +* You have set `BROWSER_API_CALLS_XHR_ONLY: false` in your `config.yaml` file. |
| 9 | +* You have created an OAuth access token. |
| 10 | +* You have logged into {productname}. |
| 11 | + |
| 12 | +.Procedure |
| 13 | + |
| 14 | +. Enter the following link:https://docs.redhat.com/en/documentation/red_hat_quay/{producty}/html-single/red_hat_quay_api_guide/index#updateorganizationautoprunepolicy[`POST /api/v1/repository/{repository}/autoprunepolicy/`] command create a new policy that limits the number of tags allowed in an organization: |
| 15 | ++ |
| 16 | +[source,terminal] |
| 17 | +---- |
| 18 | +$ curl -X POST -H "Authorization: Bearer <access_token>" -H "Content-Type: application/json" -d '{"method": "number_of_tags","value": 2}' http://<quay-server.example.com>/api/v1/repository/<organization_name>/<repository_name>/autoprunepolicy/ |
| 19 | +---- |
| 20 | ++ |
| 21 | +Alternatively, you can can set tags to expire for a specified time after their creation date: |
| 22 | ++ |
| 23 | +[source,terminal] |
| 24 | +---- |
| 25 | +$ 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/repository/<organization_name>/<repository_name>/autoprunepolicy/ |
| 26 | +---- |
| 27 | ++ |
| 28 | +.Example output |
| 29 | ++ |
| 30 | +[source,terminal] |
| 31 | +---- |
| 32 | +{"uuid": "ce2bdcc0-ced2-4a1a-ac36-78a9c1bed8c7"} |
| 33 | +---- |
| 34 | + |
| 35 | +. Optional. You can add an additional policy and pass in the `tagPattern` and `tagPatternMatches` fields to prune only tags that match the given regex pattern. For example: |
| 36 | ++ |
| 37 | +[source,terminal] |
| 38 | +---- |
| 39 | +$ curl -X POST \ |
| 40 | + -H "Authorization: Bearer <access_token>" \ |
| 41 | + -H "Content-Type: application/json" \ |
| 42 | + -d '{ |
| 43 | + "method": "<creation_date>", |
| 44 | + "value": "<7d>", |
| 45 | + "tagPattern": "<^test.>*", |
| 46 | + "tagPatternMatches": <false> <1> |
| 47 | + }' \ |
| 48 | + "https://<quay-server.example.com>/api/v1/repository/<organization_name>/<repository_name>/autoprunepolicy/" |
| 49 | +---- |
| 50 | +<1> Setting `tagPatternMatches` to `false` makes it so that tags that all tags that _do not_ match the given regex pattern are pruned. In this example, all tags _but_ `^test.` are pruned. |
| 51 | ++ |
| 52 | +.Example output |
| 53 | ++ |
| 54 | +[source,terminal] |
| 55 | +---- |
| 56 | +{"uuid": "b53d8d3f-2e73-40e7-96ff-736d372cd5ef"} |
| 57 | +---- |
| 58 | + |
| 59 | +. You can update your policy for the repository by using the link:https://docs.redhat.com/en/documentation/red_hat_quay/{producty}/html-single/red_hat_quay_api_guide/index#updaterepositoryautoprunepolicy[`PUT /api/v1/repository/{repository}/autoprunepolicy/{policy_uuid}`] command and passing in the UUID. For example: |
| 60 | ++ |
| 61 | +[source,terminal] |
| 62 | +---- |
| 63 | +$ curl -X PUT \ |
| 64 | + -H "Authorization: Bearer <bearer_token>" \ |
| 65 | + -H "Content-Type: application/json" \ |
| 66 | + -d '{ |
| 67 | + "method": "number_of_tags", |
| 68 | + "value": "5", |
| 69 | + "tagPattern": "^test.*", |
| 70 | + "tagPatternMatches": true |
| 71 | + }' \ |
| 72 | + "https://quay-server.example.com/api/v1/repository/<namespace>/<repo_name>/autoprunepolicy/<uuid>" |
| 73 | +---- |
| 74 | ++ |
| 75 | +This command does not return output. Continue to the next step to check your auto-prune policy. |
| 76 | + |
| 77 | +. Check your auto-prune policy by entering the following command: |
| 78 | ++ |
| 79 | +[source,terminal] |
| 80 | +---- |
| 81 | +$ curl -X GET -H "Authorization: Bearer <access_token>" http://<quay-server.example.com>/api/v1/repository/<organization_name>/<repository_name>/autoprunepolicy/ |
| 82 | +---- |
| 83 | ++ |
| 84 | +Alternatively, you can include the UUID: |
| 85 | ++ |
| 86 | +[source,terminal] |
| 87 | +---- |
| 88 | +$ curl -X GET -H "Authorization: Bearer <access_token>" http://<quay-server.example.com>/api/v1/repository/<organization_name>/<repository_name>/autoprunepolicy/ce2bdcc0-ced2-4a1a-ac36-78a9c1bed8c7 |
| 89 | +---- |
| 90 | ++ |
| 91 | +.Example output |
| 92 | ++ |
| 93 | +[source,terminal] |
| 94 | +---- |
| 95 | +{"policies": [{"uuid": "ce2bdcc0-ced2-4a1a-ac36-78a9c1bed8c7", "method": "number_of_tags", "value": 10}]} |
| 96 | +---- |
| 97 | + |
| 98 | +. You can delete the auto-prune policy by entering the following command. Note that deleting the policy requires the UUID. |
| 99 | ++ |
| 100 | +[source,terminal] |
| 101 | +---- |
| 102 | +$ curl -X DELETE -H "Authorization: Bearer <access_token>" http://<quay-server.example.com>/api/v1/repository/<organization_name>/<repository_name>/autoprunepolicy/ce2bdcc0-ced2-4a1a-ac36-78a9c1bed8c7 |
| 103 | +---- |
| 104 | ++ |
| 105 | +.Example output |
| 106 | ++ |
| 107 | +[source,terminal] |
| 108 | +---- |
| 109 | +{"uuid": "ce2bdcc0-ced2-4a1a-ac36-78a9c1bed8c7"} |
| 110 | +---- |
0 commit comments