Closed nikolasj closed 1 year ago
I have not added that yet. I will add it some time in the next couple of days.
Thanks, I'll wait. A very necessary endpoint.
I've played with it a bit myself now, and I have to say the API endpoints are a bit of an undocumented mess... You can definitely reverse-engineer it by creating retention rules in the web interface, then inspecting the resulting policy data from the API, but it's not ideal.
The API relies on magic string variables to denote the different retention rules and strategies, none of which are documented in the official API spec. So while these new methods should definitely work, it's not really feasible for me to document all the possible values that can be assigned to a RetentionPolicy
object.
Take for instance this rule in the web interface:
Results in this policy (JSON representation):
{
"id": 1,
"algorithm": "or",
"rules": [
{
"id": null,
"priority": null,
"disabled": null,
"action": "retain",
"template": "latestPushedK",
"params": {
"latestPushedK": 5
},
"tag_selectors": [
{
"kind": "doublestar",
"decoration": "matches",
"pattern": "**",
"extras": "{\"untagged\":true}"
}
],
"scope_selectors": {
"repository": [
{
"kind": "doublestar",
"decoration": "repoMatches",
"pattern": "**",
"extras": null
}
]
}
}
],
"trigger": {
"kind": "Schedule",
"settings": {
"cron": ""
},
"references": null
},
"scope": {
"level": "project",
"ref": 7
}
}
You can see stuff like "doublestar"
, "matches"
and "repoMatches"
. None of which are documented in the API spec.
Thank you! Now I will check. Could you tell me in your example the scope section refers to the project? i.e. ref: 7 is the project id?
ref: 7 is the project id?
Yes. Call get_retention_policy()
with the retention ID you get from get_project_retention_id()
, and you should get a similar policy object.
Just call .json()
on the returned policy object if you want a similar JSON representation.
I'll try to add some syntactic sugar to the retention endpoint methods in the future if Harbor doesn't provide a better API schema for it, but I don't have time right now. So I'm closing this issue for now, as the general API spec compliant methods are now implemented.
Now I have not found an endpoint for creating a retention policy. Can you add? I would also like to see an example.