-
Notifications
You must be signed in to change notification settings - Fork 175
refactor(BA-4521): replace ScopeType/EntityType with RBACElementType in RBAC layers #9999
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
Changes from all commits
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 @@ | ||
| Refactor RBAC layers to use unified RBACElementType enum replacing ScopeType and EntityType |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ai.backend.common.data.permission.types import EntityType, ScopeType | ||
| from ai.backend.common.data.permission.types import RBACElementType | ||
| from ai.backend.common.dto.manager.rbac.request import ( | ||
| SearchEntitiesRequest, | ||
| ) | ||
|
|
@@ -28,9 +28,9 @@ class EntityAdapter(BaseFilterAdapter): | |
|
|
||
| def build_querier( | ||
| self, | ||
| scope_type: ScopeType, | ||
| scope_type: RBACElementType, | ||
| scope_id: str, | ||
| entity_type: EntityType, | ||
| entity_type: RBACElementType, | ||
| request: SearchEntitiesRequest, | ||
| ) -> BatchQuerier: | ||
| """Build a BatchQuerier for entity search. | ||
|
|
@@ -45,9 +45,9 @@ def build_querier( | |
| BatchQuerier with scope conditions and pagination settings | ||
| """ | ||
| conditions = [ | ||
| EntityScopeConditions.by_scope_type(scope_type), | ||
| EntityScopeConditions.by_scope_type(scope_type.to_scope_type()), | ||
| EntityScopeConditions.by_scope_id(scope_id), | ||
| EntityScopeConditions.by_entity_type(entity_type), | ||
| EntityScopeConditions.by_entity_type(entity_type.to_entity_type()), | ||
|
Comment on lines
+48
to
+50
|
||
| ] | ||
| pagination = OffsetPagination(limit=request.limit, offset=request.offset) | ||
| return BatchQuerier(conditions=conditions, orders=[], pagination=pagination) | ||
|
|
@@ -62,6 +62,6 @@ def convert_to_dto(self, data: EntityData) -> EntityDTO: | |
| EntityDTO for API response | ||
| """ | ||
| return EntityDTO( | ||
| entity_type=data.entity_type, | ||
| entity_type=data.entity_type.to_element(), | ||
| entity_id=data.entity_id, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,7 @@ def to_create_object_permission_action( | |||||
| creator = Creator( | ||||||
| spec=ObjectPermissionCreatorSpec( | ||||||
| role_id=request.role_id, | ||||||
| entity_type=request.entity_type, | ||||||
| entity_type=request.entity_type.to_element(), | ||||||
|
||||||
| entity_type=request.entity_type.to_element(), | |
| entity_type=request.entity_type, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,9 +43,9 @@ def to_create_permission_action(request: CreatePermissionRequest) -> CreatePermi | |
| creator = Creator( | ||
| spec=PermissionCreatorSpec( | ||
| role_id=request.role_id, | ||
| scope_type=request.scope_type, | ||
| scope_type=request.scope_type.to_element(), | ||
| scope_id=request.scope_id, | ||
| entity_type=request.entity_type, | ||
| entity_type=request.entity_type.to_element(), | ||
|
Comment on lines
+46
to
+48
|
||
| operation=request.operation, | ||
| ) | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ai.backend.common.data.permission.types import ScopeType | ||
| from ai.backend.common.data.permission.types import RBACElementType | ||
| from ai.backend.common.dto.manager.rbac.request import ( | ||
| ScopeFilter, | ||
| ScopeOrder, | ||
|
|
@@ -36,16 +36,22 @@ | |
| class ScopeAdapter(BaseFilterAdapter): | ||
| """Adapter for converting scope requests to BatchQuerier objects.""" | ||
|
|
||
| def build_querier(self, scope_type: ScopeType, request: SearchScopesRequest) -> BatchQuerier: | ||
| """Build a BatchQuerier based on scope type.""" | ||
| def build_querier( | ||
| self, scope_type: RBACElementType | None, request: SearchScopesRequest | ||
| ) -> BatchQuerier: | ||
| """Build a BatchQuerier based on scope type. | ||
|
|
||
| ``scope_type`` is ``None`` for the GLOBAL scope, which has no | ||
|
Member
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. Would it be possible to add GLOBAL as an enum value? |
||
| ``RBACElementType`` equivalent. | ||
| """ | ||
| if scope_type is None: | ||
| return self._build_global_scope_querier(request) | ||
| match scope_type: | ||
| case ScopeType.GLOBAL: | ||
| return self._build_global_scope_querier(request) | ||
| case ScopeType.DOMAIN: | ||
| case RBACElementType.DOMAIN: | ||
| return self._build_domain_scope_querier(request) | ||
| case ScopeType.PROJECT: | ||
| case RBACElementType.PROJECT: | ||
| return self._build_project_scope_querier(request) | ||
| case ScopeType.USER: | ||
| case RBACElementType.USER: | ||
| return self._build_user_scope_querier(request) | ||
| case _: | ||
| raise NotImplementedError( | ||
|
|
@@ -177,4 +183,6 @@ def convert_to_dto(self, data: ScopeData) -> ScopeDTO: | |
| Returns: | ||
| ScopeDTO for API response | ||
| """ | ||
| return ScopeDTO(scope_type=data.id.scope_type, scope_id=data.id.scope_id, name=data.name) | ||
| return ScopeDTO( | ||
| scope_type=data.id.scope_type.to_element(), scope_id=data.id.scope_id, name=data.name | ||
| ) | ||
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.
Breaking API change:
scope_typeis typed asRBACElementType | None, but if a client sends"global"in the URL path, Pydantic will raise a validation error because"global"is not a validRBACElementTypevalue and path parameters won't naturally becomeNone. TheNonecase can only be reached if the path parameter is somehow omitted, which typically isn't how path parameters work. You likely need a custom validator or a separate union type that maps"global"toNone.