-
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
aca7eee
bd8f95e
337802f
0d5cab3
2c6dfa4
c0342fe
b6c6e69
a8b329e
9ea60d8
0f8f273
27f1096
e246353
3cb0e29
f951552
143522f
4355993
863c1e7
7d3ea15
daabe71
2417cb2
d8ac478
8fe98ac
ac72d81
7f11e1c
7aec995
fe6cf74
965b924
629d0bb
4859b80
ba23227
5622c33
7eb42ae
43357ea
73ad689
d5b1c04
01fa97f
bce8f0f
1293569
d4d519e
418df6b
0a1f92b
ece9100
313c437
5be9d88
d2db5c4
1cf38b4
01f3412
df45814
6c373ba
492f2d9
4d62853
421ebb2
d467bad
245ed87
b7a3893
c93ae53
bdb143b
9a59dc9
6363083
3688b17
699decd
b3aa014
0ff41e9
b46a159
5e1700f
8389ce1
6223355
9284c7e
4bb2b83
0986ae3
4db221a
d1f41b6
a5547cb
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?