There is a Python script that should set a policy for cleaning Docker images
headers = {"PRIVATE-TOKEN": TOKEN}
data_binary = {
"container_expiration_policy_attributes": {
"cadence": "1month",
"enabled": "true",
"keep_n": "1",
"older_than": "14d",
"name_regex": "",
"name_regex_delete": ".*",
"name_regex_keep": ".*-master"
}
}
url = f"https://hidden/api/v4/projects/{str(project_id)}"
r = requests.put(url, headers=headers, data=json.dumps(data_binary))
json_data = r.json()
pprint.pprint(json_data)
It returns an error on startup
{'error': 'allow_merge_on_skipped_pipeline, autoclose_referenced_issues, '
'auto_devops_enabled, auto_devops_deploy_strategy, '
'auto_cancel_pending_pipelines, build_coverage_regex, '
'build_git_strategy, build_timeout, builds_access_level, '
'ci_config_path, ci_default_git_depth, '
'ci_forward_deployment_enabled, container_registry_enabled, '
'container_expiration_policy_attributes, default_branch, '
'description, emails_disabled, forking_access_level, '
'issues_access_level, lfs_enabled, merge_requests_access_level, '
'merge_method, name, '
'only_allow_merge_if_all_discussions_are_resolved, '
'only_allow_merge_if_pipeline_succeeds, pages_access_level, path, '
'printing_merge_request_link_enabled, public_builds, '
'remove_source_branch_after_merge, repository_access_level, '
'request_access_enabled, resolve_outdated_diff_discussions, '
'shared_runners_enabled, snippets_access_level, tag_list, '
'visibility, wiki_access_level, avatar, suggestion_commit_message, '
'repository_storage, compliance_framework_setting, packages_enabled, '
'service_desk_enabled, issues_enabled, jobs_enabled, '
'merge_requests_enabled, wiki_enabled, snippets_enabled, '
'approvals_before_merge, '
'external_authorization_classification_label, import_url, '
'fallback_approvals_required are missing, at least one parameter '
'must be provided'}
as I understand the key is the following
...container_expiration_policy_attributes... are missing
Although I pointed the field out. What is the problem?
The solution is to add Content-type
headers = {"PRIVATE-TOKEN": TOKEN,
"Content-type": "application/json;charset=UTF-8"}