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)
|
||||
location = response_headers.get("Location") or response_headers.get("location") or ""
|
||||
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())
|
||||
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()
|
||||
if not refreshed_id.isdigit():
|
||||
raise RuntimeError(f"retention created but id was not returned: status={status} location={location!r}")
|
||||
if refreshed_id.isdigit():
|
||||
retention_id = int(refreshed_id)
|
||||
else:
|
||||
retention_id = int(match.group(1))
|
||||
elif retention_id is None:
|
||||
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}")
|
||||
else:
|
||||
status, existing_policy, _ = request("GET", f"/retentions/{retention_id}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user