2019-09-03 09:52:41 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import base
|
2021-03-15 09:08:48 +01:00
|
|
|
import v2_swagger_client
|
2019-09-03 09:52:41 +02:00
|
|
|
|
|
|
|
class Retention(base.Base):
|
2021-01-08 12:05:42 +01:00
|
|
|
def __init__(self):
|
|
|
|
super(Retention,self).__init__(api_type="retention")
|
|
|
|
|
2019-09-03 09:52:41 +02:00
|
|
|
def get_metadatas(self, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
metadatas, status_code, _ = self._get_client(**kwargs).get_rentenition_metadata_with_http_info()
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return metadatas
|
|
|
|
|
|
|
|
def create_retention_policy(self, project_id, selector_repository="**", selector_tag="**", expect_status_code = 201, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
policy=v2_swagger_client.RetentionPolicy(
|
2019-09-03 09:52:41 +02:00
|
|
|
algorithm='or',
|
|
|
|
rules=[
|
2021-03-15 09:08:48 +01:00
|
|
|
v2_swagger_client.RetentionRule(
|
2019-09-03 09:52:41 +02:00
|
|
|
disabled=False,
|
|
|
|
action="retain",
|
|
|
|
template="always",
|
|
|
|
params= {
|
|
|
|
|
|
|
|
},
|
|
|
|
scope_selectors={
|
|
|
|
"repository": [
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "repoMatches",
|
|
|
|
"pattern": selector_repository
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
tag_selectors=[
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "matches",
|
|
|
|
"pattern": selector_tag
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
|
|
|
trigger= {
|
|
|
|
"kind": "Schedule",
|
|
|
|
"settings": {
|
|
|
|
"cron": ""
|
|
|
|
},
|
|
|
|
"references": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scope= {
|
|
|
|
"level": "project",
|
|
|
|
"ref": project_id
|
|
|
|
},
|
|
|
|
)
|
2021-03-15 09:08:48 +01:00
|
|
|
_, status_code, header = self._get_client(**kwargs).create_retention_with_http_info(policy)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return base._get_id_from_header(header)
|
|
|
|
|
|
|
|
def get_retention_policy(self, retention_id, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
policy, status_code, _ = self._get_client(**kwargs).get_retention_with_http_info(retention_id)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return policy
|
|
|
|
|
2023-02-17 07:56:13 +01:00
|
|
|
def update_retention_policy(self, retention_id, project_id, selector_repository="**", selector_tag="**", cron="", expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
policy=v2_swagger_client.RetentionPolicy(
|
2019-09-03 09:52:41 +02:00
|
|
|
id=retention_id,
|
|
|
|
algorithm='or',
|
|
|
|
rules=[
|
2021-03-15 09:08:48 +01:00
|
|
|
v2_swagger_client.RetentionRule(
|
2019-09-03 09:52:41 +02:00
|
|
|
disabled=False,
|
|
|
|
action="retain",
|
|
|
|
template="always",
|
2023-02-17 07:56:13 +01:00
|
|
|
params= {},
|
2019-09-03 09:52:41 +02:00
|
|
|
scope_selectors={
|
|
|
|
"repository": [
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "repoMatches",
|
|
|
|
"pattern": selector_repository
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
tag_selectors=[
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "matches",
|
|
|
|
"pattern": selector_tag
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
|
|
|
trigger= {
|
|
|
|
"kind": "Schedule",
|
|
|
|
"settings": {
|
2023-02-17 07:56:13 +01:00
|
|
|
"cron": cron
|
2019-09-03 09:52:41 +02:00
|
|
|
},
|
|
|
|
"references": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scope= {
|
|
|
|
"level": "project",
|
|
|
|
"ref": project_id
|
|
|
|
},
|
|
|
|
)
|
2021-03-15 09:08:48 +01:00
|
|
|
_, status_code, _ = self._get_client(**kwargs).update_retention_with_http_info(retention_id, policy)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
|
2020-05-08 05:52:42 +02:00
|
|
|
def update_retention_add_rule(self, retention_id, selector_repository="**", selector_tag="**", with_untag="True", expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
retention_rule = v2_swagger_client.RetentionRule(
|
|
|
|
disabled=False,
|
|
|
|
action="retain",
|
|
|
|
template="always",
|
|
|
|
params= {
|
|
|
|
|
|
|
|
},
|
|
|
|
scope_selectors={
|
|
|
|
"repository": [
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "repoMatches",
|
|
|
|
"pattern": selector_repository
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
tag_selectors=[
|
|
|
|
{
|
|
|
|
"kind": "doublestar",
|
|
|
|
"decoration": "matches",
|
|
|
|
"extras":'["untagged":'+with_untag+']',
|
|
|
|
"pattern": selector_tag
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-09-03 09:52:41 +02:00
|
|
|
client = self._get_client(**kwargs)
|
2021-01-08 12:05:42 +01:00
|
|
|
policy, status_code, _ = client.get_retention_with_http_info(retention_id)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(200, status_code)
|
2021-03-15 09:08:48 +01:00
|
|
|
policy.rules.append(retention_rule)
|
2021-01-08 12:05:42 +01:00
|
|
|
_, status_code, _ = client.update_retention_with_http_info(retention_id, policy)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
|
|
|
|
def trigger_retention_policy(self, retention_id, dry_run=False, expect_status_code = 201, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
_, status_code, _ = self._get_client(**kwargs).trigger_retention_execution_with_http_info(retention_id, {"dry_run":dry_run})
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
|
|
|
|
def stop_retention_execution(self, retention_id, exec_id, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
r, status_code, _ = self._get_client(**kwargs).operate_retention_execution_with_http_info(retention_id, exec_id, {"action":"stop"})
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return r
|
|
|
|
|
|
|
|
def get_retention_executions(self, retention_id, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
r, status_code, _ = self._get_client(**kwargs).list_retention_executions_with_http_info(retention_id)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return r
|
|
|
|
|
|
|
|
def get_retention_exec_tasks(self, retention_id, exec_id, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
r, status_code, _ = self._get_client(**kwargs).list_retention_tasks_with_http_info(retention_id, exec_id)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return r
|
|
|
|
|
|
|
|
def get_retention_exec_task_log(self, retention_id, exec_id, task_id, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
r, status_code, _ = self._get_client(**kwargs).get_retention_task_log_with_http_info(retention_id, exec_id, task_id)
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return r
|
|
|
|
|
|
|
|
def get_retention_metadatas(self, expect_status_code = 200, **kwargs):
|
2021-03-15 09:08:48 +01:00
|
|
|
r, status_code, _ = self._get_client(**kwargs).get_rentenition_metadata_with_http_info()
|
2019-09-03 09:52:41 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return r
|