-
Notifications
You must be signed in to change notification settings - Fork 154
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: 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?
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
7b81657
to
f0cc98f
Compare
47cacdd
to
a6068e1
Compare
f0cc98f
to
f01260a
Compare
f5a8af1
to
917dffd
Compare
Remaining tasks: Adding REST API and SDK. |
f01260a
to
6fcfeae
Compare
1be79c6
to
6b91f24
Compare
6fcfeae
to
548f6f8
Compare
6b91f24
to
81dbd9e
Compare
548f6f8
to
bda8f44
Compare
81dbd9e
to
33c1b79
Compare
bda8f44
to
30b5684
Compare
33c1b79
to
f036297
Compare
30b5684
to
56003a4
Compare
f036297
to
0d5ccf2
Compare
56003a4
to
643e723
Compare
0d5ccf2
to
408bf1f
Compare
""" | ||
) | ||
|
||
scope_id = f"project:{group_id}" |
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 If possible, instead of hardcoding the scope_id
like this, I’d prefer to create a ProjectScope
object and serialize it. However, since the ProjectScope
type is currently located under the models
directory, this violates the pants visibility rule.
What do you think about moving the types related to ScopeField
under the common
directory?
) | ||
|
||
variables = {"id": base64(f"group_node:{group_id}")} | ||
data = await api_session.get().Admin._query(query, variables) |
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 to User
as well?
Co-authored-by: octodog <[email protected]>
Co-authored-by: octodog <[email protected]>
6b415d5
to
cae3fee
Compare
@classmethod | ||
async def get_container_registry_quota(cls, group_id: str) -> int: | ||
""" | ||
Delete Quota Limit for the group's container registry. |
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.
get
cors.add(app.router.add_route("POST", "/registry-quota", create_registry_quota)) | ||
cors.add(app.router.add_route("GET", "/registry-quota", read_registry_quota)) | ||
cors.add(app.router.add_route("PATCH", "/registry-quota", update_registry_quota)) | ||
cors.add(app.router.add_route("DELETE", "/registry-quota", delete_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.
can we use PATCH, DELETE method? @fregataa
if ( | ||
not group_row | ||
or not group_row.container_registry | ||
or "registry" not in group_row.container_registry | ||
or "project" not in group_row.container_registry | ||
): |
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.
make function for this condition to improve readability.
async def handle_harbor_project_quota_operation( | ||
operation_type: Literal["create", "read", "update", "delete"], | ||
db_sess: SASession, | ||
scope_id: ScopeType, | ||
quota: Optional[int], | ||
) -> Optional[int]: |
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.
Don't combine handler functions into one function
that accept multiple operation_types.
Resolves #1911.
Implement CRUD for controlling Harbor per-project Quota.
Important
Currently, the Project Quota API implemented in this PR is only available for the HarborV2 registry.
Details
In practice, the HarborV2 Quota API has no delete or create methods. But if you query a quota that does not exist, it returns -1. Using the update API at this point creates the quota. Updating it back to -1 resets it to an unlimited quota. Using this approach, I implemented all CRUD operations.
Quota mutations can only be executed by
admin
,superadmin
, while quota queries are accessible to regular users if they have READ permissions.Implementation Check list
Client code example
GQL example
Reference
Checklist: (if applicable)
📚 Documentation preview 📚: https://sorna--3090.org.readthedocs.build/en/3090/
📚 Documentation preview 📚: https://sorna-ko--3090.org.readthedocs.build/ko/3090/