Retention
get_project_retention_id(project_name_or_id)
async
Get the retention policy ID for a project.
API Spec Inconsistency
The retention policy ID field for a project is marked as a string in the API spec, but the retention endpoints expect an integer ID. This method will always return an integer. If the project has a retention ID that cannot be converted to int, the method raises a HarborAPIException
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name_or_id |
Union[str, int]
|
The name or ID of the project. String arguments are treated as project names. Integer arguments are treated as project IDs. |
required |
Returns:
Type | Description |
---|---|
int
|
The retention policy ID for the project. |
Raises:
Type | Description |
---|---|
NotFound
|
If the project does not have a retention policy ID. |
get_retention_policy(retention_id)
async
Get a retention policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The ID of the retention policy. |
required |
Returns:
Type | Description |
---|---|
RetentionPolicy
|
The retention policy. |
create_retention_policy(policy)
async
Creates a new retention policy. Returns location of the created policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
policy |
RetentionPolicy
|
The retention policy to create. |
required |
Returns:
Type | Description |
---|---|
str
|
The location of the created retention policy. |
update_retention_policy(retention_id, retention)
async
Update a retention policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The ID of the retention policy. |
required |
retention |
RetentionPolicy
|
The retention policy to update. |
required |
delete_retention_policy(retention_id)
async
Delete a retention policy.
Danger
As of Harbor v2.8.0-89ef156d, using this API endpoint will cause a project to break. The endpoint deletes the retention policy for the project but doesn't update the project metadata to reflect this change. This results in an internal server error when attempting to access the project in the Web UI. Additionally, the metadata field will prevent creating a new retention policy for the project in the Web UI. This bug likely affects all versions of Harbor.
Delete the "retention_id"
metadata field to fix the project:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The ID of the retention policy. |
required |
get_retention_tasks(retention_id, execution_id, page=None, page_size=None, limit=None)
async
Get the retention tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The ID of the retention policy. |
required |
execution_id |
int
|
The ID of the retention execution. |
required |
page |
Optional[int]
|
The page number. |
None
|
page_size |
Optional[int]
|
The page size. |
None
|
limit |
Optional[int]
|
The maximum number of tasks to return. |
None
|
Returns:
Type | Description |
---|---|
List[RetentionExecutionTask]
|
The retention tasks. |
get_retention_metadata()
async
get_retention_execution_task_log(retention_id, execution_id, task_id)
async
Get the log for a retention execution task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The id of the retention policy. |
required |
execution_id |
int
|
The id of the retention execution. |
required |
task_id |
int
|
The id of the retention task. |
required |
Returns:
Type | Description |
---|---|
str
|
The log for the task. |
get_retention_executions(retention_id, page=1, page_size=10, limit=None)
async
Get the retention executions for a policy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
retention_id |
int
|
The id of the retention policy. |
required |
page |
int
|
The page number to return. |
1
|
page_size |
int
|
The number of items to return per page. |
10
|
limit |
Optional[int]
|
The maximum number of items to return. |
None
|
Returns:
Type | Description |
---|---|
List[RetentionExecution]
|
The retention executions for the policy. |