-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(BA-145): Implement CRUD API for managing Harbor per-project Quota #3090
base: topic/11-06-feat_implement_per-project_images_api_based_on_rbac
Are you sure you want to change the base?
Changes from all commits
c0a866c
0b4d490
1cdd4f7
4340b3d
24ef066
1e9657f
5e8d363
b951004
b921b84
b4ded10
8eb35a7
1a8aa1c
74b33ff
71a5248
3ad7658
deac59b
7413034
7810008
c5ef78b
71def5d
5e3372b
9986638
5cde26d
c0b8b01
15babbf
e0c2733
2c18a6b
b842771
19fc673
5282271
0323070
124f5ab
5380b19
5d9cc35
28581eb
641fb16
61b1e3b
d04366d
2f96d2d
e1b1fa0
bdb8392
840c219
bb53fb1
40a954f
b4a87c8
357f7a4
b2dcb58
2ff19a0
b002ed3
7ea569f
1c566f9
9c2743c
4aa7c8f
723fa90
207e09a
4a383db
34ef4b2
d60431e
5970ad2
73f36b0
886d323
a9e6284
238f03f
3242582
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Implement CRUD API for managing Harbor per-project Quota. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import textwrap | ||
from typing import Any, Iterable, Optional, Sequence | ||
|
||
from ai.backend.client.output.fields import group_fields | ||
from ai.backend.client.output.types import FieldSpec | ||
from ai.backend.common.utils import b64encode | ||
|
||
from ...cli.types import Undefined, undefined | ||
from ..session import api_session | ||
|
@@ -293,3 +295,101 @@ async def remove_users( | |
} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["modify_group"] | ||
|
||
@api_function | ||
@classmethod | ||
async def get_container_registry_quota(cls, group_id: str) -> int: | ||
""" | ||
Get Quota Limit for the group's container registry. | ||
Currently only HarborV2 registry is supported. | ||
|
||
You need an admin privilege for this operation. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
query($id: String!) { | ||
group_node(id: $id) { | ||
registry_quota | ||
} | ||
} | ||
""" | ||
) | ||
|
||
variables = {"id": b64encode(f"group_node:{group_id}")} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["group_node"]["registry_quota"] | ||
|
||
@api_function | ||
@classmethod | ||
async def create_container_registry_quota(cls, group_id: str, quota: int) -> dict: | ||
""" | ||
Create Quota Limit for the group's container registry. | ||
Currently only HarborV2 registry is supported. | ||
|
||
You need an admin privilege for this operation. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
mutation($scope_id: ScopeField!, $quota: Int!) { | ||
create_container_registry_quota( | ||
scope_id: $scope_id, quota: $quota) { | ||
ok msg | ||
} | ||
} | ||
""" | ||
) | ||
|
||
scope_id = f"project:{group_id}" | ||
variables = {"scope_id": scope_id, "quota": quota} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["create_container_registry_quota"] | ||
|
||
@api_function | ||
@classmethod | ||
async def update_container_registry_quota(cls, group_id: str, quota: int) -> dict: | ||
""" | ||
Update Quota Limit for the group's container registry. | ||
Currently only HarborV2 registry is supported. | ||
|
||
You need an admin privilege for this operation. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
mutation($scope_id: ScopeField!, $quota: Int!) { | ||
update_container_registry_quota( | ||
scope_id: $scope_id, quota: $quota) { | ||
ok msg | ||
} | ||
} | ||
""" | ||
) | ||
|
||
scope_id = f"project:{group_id}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fregataa If possible, instead of hardcoding the What do you think about moving the types related to |
||
variables = {"scope_id": scope_id, "quota": quota} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["update_container_registry_quota"] | ||
|
||
@api_function | ||
@classmethod | ||
async def delete_container_registry_quota(cls, group_id: str) -> dict: | ||
""" | ||
Delete Quota Limit for the group's container registry. | ||
Currently only HarborV2 registry is supported. | ||
|
||
You need an admin privilege for this operation. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
mutation($scope_id: ScopeField!) { | ||
delete_container_registry_quota( | ||
scope_id: $scope_id) { | ||
ok msg | ||
} | ||
} | ||
""" | ||
) | ||
|
||
scope_id = f"project:{group_id}" | ||
variables = {"scope_id": scope_id} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["delete_container_registry_quota"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fregataa Registry quota READ operation can be executed even if the user is not an admin.
However, it seems that GQL queries in the current SDK can only be executed through
Admin
.What do you think about adding this
query
,_query
functions toUser
as well?