fix harbor retention setup
This commit is contained in:
parent
96f1c9dacb
commit
7078b694de
@ -268,23 +268,17 @@ if retention_id is None:
|
|||||||
status, _, response_headers = request("POST", "/retentions", payload)
|
status, _, response_headers = request("POST", "/retentions", payload)
|
||||||
location = response_headers.get("Location") or response_headers.get("location") or ""
|
location = response_headers.get("Location") or response_headers.get("location") or ""
|
||||||
match = re.search(r"/retentions/(\d+)", location)
|
match = re.search(r"/retentions/(\d+)", location)
|
||||||
if not match:
|
if match:
|
||||||
|
retention_id = int(match.group(1))
|
||||||
|
|
||||||
status, refreshed_project, _ = request("GET", project_path())
|
status, refreshed_project, _ = request("GET", project_path())
|
||||||
refreshed_metadata = dict((refreshed_project or {}).get("metadata") or {}) if isinstance(refreshed_project, dict) else {}
|
refreshed_metadata = dict((refreshed_project or {}).get("metadata") or {}) if isinstance(refreshed_project, dict) else {}
|
||||||
refreshed_id = str(refreshed_metadata.get("retention_id") or "").strip()
|
refreshed_id = str(refreshed_metadata.get("retention_id") or "").strip()
|
||||||
if not refreshed_id.isdigit():
|
if refreshed_id.isdigit():
|
||||||
raise RuntimeError(f"retention created but id was not returned: status={status} location={location!r}")
|
|
||||||
retention_id = int(refreshed_id)
|
retention_id = int(refreshed_id)
|
||||||
else:
|
elif retention_id is None:
|
||||||
retention_id = int(match.group(1))
|
raise RuntimeError(f"retention created but id was not returned: status={status} location={location!r}")
|
||||||
|
|
||||||
try:
|
|
||||||
request("POST", project_path("/metadatas/"), {"retention_id": str(retention_id)})
|
|
||||||
except RuntimeError as exc:
|
|
||||||
if "409" in str(exc):
|
|
||||||
request("PUT", project_path("/metadatas/retention_id"), {"retention_id": str(retention_id)})
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
print(f"created retention_id={retention_id}")
|
print(f"created retention_id={retention_id}")
|
||||||
else:
|
else:
|
||||||
status, existing_policy, _ = request("GET", f"/retentions/{retention_id}")
|
status, existing_policy, _ = request("GET", f"/retentions/{retention_id}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user