Skip to content

Commit c1c79fb

Browse files
committed
rename all
1 parent 0cfd3f5 commit c1c79fb

File tree

4 files changed

+133
-137
lines changed

4 files changed

+133
-137
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_sources()

src/ai/backend/manager/models/rbac/__init__.py

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919

2020

2121
__all__: Sequence[str] = (
22-
"BaseACLPermission",
22+
"BasePermission",
2323
"ClientContext",
2424
"DomainScope",
2525
"ProjectScope",
2626
"UserScope",
2727
"StorageHost",
2828
"ImageRegistry",
2929
"ScalingGroup",
30-
"AbstractACLPermissionContext",
31-
"AbstractACLPermissionContextBuilder",
30+
"AbstractPermissionContext",
31+
"AbstractPermissionContextBuilder",
3232
)
3333

3434

35-
class BaseACLPermission(enum.StrEnum):
35+
class BasePermission(enum.StrEnum):
3636
pass
3737

3838

39-
ACLPermissionType = TypeVar("ACLPermissionType", bound=BaseACLPermission)
39+
PermissionType = TypeVar("PermissionType", bound=BasePermission)
4040

4141

4242
class Bypass(enum.Enum):
@@ -127,97 +127,97 @@ async def _get_or_init_project_ctx(self, db_session: AsyncSession) -> ProjectCon
127127
return self._project_ctx
128128

129129

130-
class BaseACLScope(metaclass=ABCMeta):
130+
class BaseScope(metaclass=ABCMeta):
131131
@abstractmethod
132132
def __str__(self) -> str:
133133
pass
134134

135135

136136
@dataclass(frozen=True)
137-
class DomainScope(BaseACLScope):
137+
class DomainScope(BaseScope):
138138
domain_name: str
139-
139+
140140
def __str__(self) -> str:
141141
return f"Domain(name: {self.domain_name})"
142142

143143

144144
@dataclass(frozen=True)
145-
class ProjectScope(BaseACLScope):
145+
class ProjectScope(BaseScope):
146146
project_id: uuid.UUID
147-
147+
148148
def __str__(self) -> str:
149149
return f"Project(id: {self.project_id})"
150150

151151

152152
@dataclass(frozen=True)
153-
class UserScope(BaseACLScope):
153+
class UserScope(BaseScope):
154154
user_id: uuid.UUID
155155

156156
def __str__(self) -> str:
157157
return f"User(id: {self.user_id})"
158158

159159

160-
# Extra ACL scope is to address some scopes that contain specific object types
160+
# Extra scope is to address some scopes that contain specific object types
161161
# such as registries for images, scaling groups for agents, storage hosts for vfolders etc.
162-
class ExtraACLScope:
162+
class ExtraScope:
163163
pass
164164

165165

166166
@dataclass(frozen=True)
167-
class StorageHost(ExtraACLScope):
167+
class StorageHost(ExtraScope):
168168
name: str
169169

170170

171171
@dataclass(frozen=True)
172-
class ImageRegistry(ExtraACLScope):
172+
class ImageRegistry(ExtraScope):
173173
name: str
174174

175175

176176
@dataclass(frozen=True)
177-
class ScalingGroup(ExtraACLScope):
177+
class ScalingGroup(ExtraScope):
178178
name: str
179179

180180

181-
ACLObjectType = TypeVar("ACLObjectType")
182-
ACLObjectIDType = TypeVar("ACLObjectIDType")
181+
ObjectType = TypeVar("ObjectType")
182+
ObjectIDType = TypeVar("ObjectIDType")
183183

184184

185185
@dataclass
186-
class AbstractACLPermissionContext(
187-
Generic[ACLPermissionType, ACLObjectType, ACLObjectIDType], metaclass=ABCMeta
186+
class AbstractPermissionContext(
187+
Generic[PermissionType, ObjectType, ObjectIDType], metaclass=ABCMeta
188188
):
189189
"""
190-
Define ACL permissions under given User, Project or Domain scopes.
190+
Define permissions under given User, Project or Domain scopes.
191191
Each field of this class represents a mapping of ["accessible scope id", "permissions under the scope"].
192192
For example, `project` field has a mapping of ["accessible project id", "permissions under the project"].
193193
{
194194
"PROJECT_A_ID": {"READ", "WRITE", "DELETE"}
195195
"PROJECT_B_ID": {"READ"}
196196
}
197197
198-
`additional` and `overriding` fields have a mapping of ["ACL object id", "permissions applied to the object"].
199-
`additional` field is used to add permissions to specific ACL objects. It can be used for admins.
198+
`additional` and `overriding` fields have a mapping of ["object id", "permissions applied to the object"].
199+
`additional` field is used to add permissions to specific objects. It can be used for admins.
200200
`overriding` field is used to address exceptional cases such as permission overriding or cover other scopes(scaling groups or storage hosts etc).
201201
"""
202202

203-
user_id_to_permission_map: Mapping[uuid.UUID, frozenset[ACLPermissionType]] = field(
203+
user_id_to_permission_map: Mapping[uuid.UUID, frozenset[PermissionType]] = field(
204204
default_factory=dict
205205
)
206-
project_id_to_permission_map: Mapping[uuid.UUID, frozenset[ACLPermissionType]] = field(
206+
project_id_to_permission_map: Mapping[uuid.UUID, frozenset[PermissionType]] = field(
207207
default_factory=dict
208208
)
209-
domain_name_to_permission_map: Mapping[str, frozenset[ACLPermissionType]] = field(
209+
domain_name_to_permission_map: Mapping[str, frozenset[PermissionType]] = field(
210210
default_factory=dict
211211
)
212212

213-
object_id_to_additional_permission_map: Mapping[
214-
ACLObjectIDType, frozenset[ACLPermissionType]
215-
] = field(default_factory=dict)
216-
object_id_to_overriding_permission_map: Mapping[
217-
ACLObjectIDType, frozenset[ACLPermissionType]
218-
] = field(default_factory=dict)
213+
object_id_to_additional_permission_map: Mapping[ObjectIDType, frozenset[PermissionType]] = (
214+
field(default_factory=dict)
215+
)
216+
object_id_to_overriding_permission_map: Mapping[ObjectIDType, frozenset[PermissionType]] = (
217+
field(default_factory=dict)
218+
)
219219

220-
def filter_by_permission(self, permission_to_include: ACLPermissionType) -> None:
220+
def filter_by_permission(self, permission_to_include: PermissionType) -> None:
221221
self.user_id_to_permission_map = {
222222
uid: permissions
223223
for uid, permissions in self.user_id_to_permission_map.items()
@@ -249,30 +249,28 @@ async def build_query(self) -> sa.sql.Select | None:
249249
pass
250250

251251
@abstractmethod
252-
async def calculate_final_permission(
253-
self, acl_obj: ACLObjectType
254-
) -> frozenset[ACLPermissionType]:
252+
async def calculate_final_permission(self, acl_obj: ObjectType) -> frozenset[PermissionType]:
255253
"""
256-
Calculate the final permissions applied to the given ACL object based on the fields in this class.
254+
Calculate the final permissions applied to the given object based on the fields in this class.
257255
"""
258256
pass
259257

260258

261-
ACLPermissionContextType = TypeVar("ACLPermissionContextType", bound=AbstractACLPermissionContext)
259+
PermissionContextType = TypeVar("PermissionContextType", bound=AbstractPermissionContext)
262260

263261

264-
class AbstractACLPermissionContextBuilder(
265-
Generic[ACLPermissionType, ACLPermissionContextType], metaclass=ABCMeta
262+
class AbstractPermissionContextBuilder(
263+
Generic[PermissionType, PermissionContextType], metaclass=ABCMeta
266264
):
267265
@classmethod
268266
async def build(
269267
cls,
270268
db_session: AsyncSession,
271269
ctx: ClientContext,
272-
target_scope: BaseACLScope,
270+
target_scope: BaseScope,
273271
*,
274-
permission: ACLPermissionType | None = None,
275-
) -> ACLPermissionContextType:
272+
permission: PermissionType | None = None,
273+
) -> PermissionContextType:
276274
match target_scope:
277275
case UserScope(user_id=user_id):
278276
result = await cls._build_in_user_scope(db_session, ctx, user_id)
@@ -281,7 +279,7 @@ async def build(
281279
case DomainScope(domain_name=domain_name):
282280
result = await cls._build_in_domain_scope(db_session, ctx, domain_name)
283281
case _:
284-
raise RuntimeError(f"invalid ACL scope `{target_scope}`")
282+
raise RuntimeError(f"invalid scope `{target_scope}`")
285283
if permission is not None:
286284
result.filter_by_permission(permission)
287285
return result
@@ -293,7 +291,7 @@ async def _build_in_user_scope(
293291
db_session: AsyncSession,
294292
ctx: ClientContext,
295293
user_id: uuid.UUID,
296-
) -> ACLPermissionContextType:
294+
) -> PermissionContextType:
297295
pass
298296

299297
@classmethod
@@ -303,7 +301,7 @@ async def _build_in_project_scope(
303301
db_session: AsyncSession,
304302
ctx: ClientContext,
305303
project_id: uuid.UUID,
306-
) -> ACLPermissionContextType:
304+
) -> PermissionContextType:
307305
pass
308306

309307
@classmethod
@@ -313,5 +311,5 @@ async def _build_in_domain_scope(
313311
db_session: AsyncSession,
314312
ctx: ClientContext,
315313
domain_name: str,
316-
) -> ACLPermissionContextType:
314+
) -> PermissionContextType:
317315
pass

src/ai/backend/manager/models/rbac/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class RBACException(Exception):
32
pass
43

0 commit comments

Comments
 (0)