Skip to content

Commit

Permalink
chore: Rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Nov 14, 2024
1 parent 826a0f7 commit f8a599d
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/ai/backend/manager/models/gql_models/container_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ class UpdateQuotaOperationType(enum.StrEnum):

async def update_harbor_project_quota(
operation_type: UpdateQuotaOperationType,
cls: Any,
mutation_cls: Any,
info: graphene.ResolveInfo,
scope_id: ScopeType,
quota: int,
) -> Any:
if not isinstance(scope_id, ProjectScope):
return cls(ok=False, msg="Quota mutation currently supports only the project scope.")
return mutation_cls(
ok=False, msg="Quota mutation currently supports only the project scope."
)

project_id = scope_id.project_id
graph_ctx = info.context
Expand Down Expand Up @@ -134,13 +136,13 @@ async def update_harbor_project_quota(
registry = result.scalars().one_or_none()

if not registry:
return cls(
return mutation_cls(
ok=False,
msg=f"Specified container registry row does not exist. (cr: {registry_name}, gr: {project})",
)

if registry.type != ContainerRegistryType.HARBOR2:
return cls(ok=False, msg="Only HarborV2 registry is supported for now.")
return mutation_cls(ok=False, msg="Only HarborV2 registry is supported for now.")

ssl_verify = registry.ssl_verify
connector = aiohttp.TCPConnector(ssl=ssl_verify)
Expand All @@ -166,22 +168,24 @@ async def update_harbor_project_quota(
async with sess.get(get_quota_id_api, allow_redirects=False, **rqst_args) as resp:
res = await resp.json()
if not res:
return cls(
return mutation_cls(
ok=False, msg=f"Quota entity not found. (project_id: {harbor_project_id})"
)
if len(res) > 1:
return cls(
return mutation_cls(
ok=False,
msg=f"Multiple quota entities found. (project_id: {harbor_project_id})",
)

previous_quota = res[0]["hard"]["storage"]
if operation_type == UpdateQuotaOperationType.DELETE:
if previous_quota == -1:
return cls(ok=False, msg=f"Quota entity not found. (gr: {project_id})")
return mutation_cls(ok=False, msg=f"Quota entity not found. (gr: {project_id})")
elif operation_type == UpdateQuotaOperationType.CREATE:
if previous_quota > 0:
return cls(ok=False, msg=f"Quota limit already exists. (gr: {project_id})")
return mutation_cls(
ok=False, msg=f"Quota limit already exists. (gr: {project_id})"
)

quota_id = res[0]["id"]

Expand All @@ -192,14 +196,14 @@ async def update_harbor_project_quota(
put_quota_api, json=payload, allow_redirects=False, **rqst_args
) as resp:
if resp.status == 200:
return cls(ok=True, msg="success")
return mutation_cls(ok=True, msg="success")
else:
log.error(f"Failed to {operation_type} quota: {await resp.json()}")
return cls(
return mutation_cls(
ok=False, msg=f"Failed to {operation_type} quota. Status code: {resp.status}"
)

return cls(ok=False, msg="Unknown error!")
return mutation_cls(ok=False, msg="Unknown error!")


class CreateQuota(graphene.Mutation):
Expand Down

0 comments on commit f8a599d

Please sign in to comment.