19
19
20
20
21
21
__all__ : Sequence [str ] = (
22
- "BaseACLPermission " ,
22
+ "BasePermission " ,
23
23
"ClientContext" ,
24
24
"DomainScope" ,
25
25
"ProjectScope" ,
26
26
"UserScope" ,
27
27
"StorageHost" ,
28
28
"ImageRegistry" ,
29
29
"ScalingGroup" ,
30
- "AbstractACLPermissionContext " ,
31
- "AbstractACLPermissionContextBuilder " ,
30
+ "AbstractPermissionContext " ,
31
+ "AbstractPermissionContextBuilder " ,
32
32
)
33
33
34
34
35
- class BaseACLPermission (enum .StrEnum ):
35
+ class BasePermission (enum .StrEnum ):
36
36
pass
37
37
38
38
39
- ACLPermissionType = TypeVar ("ACLPermissionType " , bound = BaseACLPermission )
39
+ PermissionType = TypeVar ("PermissionType " , bound = BasePermission )
40
40
41
41
42
42
class Bypass (enum .Enum ):
@@ -127,97 +127,97 @@ async def _get_or_init_project_ctx(self, db_session: AsyncSession) -> ProjectCon
127
127
return self ._project_ctx
128
128
129
129
130
- class BaseACLScope (metaclass = ABCMeta ):
130
+ class BaseScope (metaclass = ABCMeta ):
131
131
@abstractmethod
132
132
def __str__ (self ) -> str :
133
133
pass
134
134
135
135
136
136
@dataclass (frozen = True )
137
- class DomainScope (BaseACLScope ):
137
+ class DomainScope (BaseScope ):
138
138
domain_name : str
139
-
139
+
140
140
def __str__ (self ) -> str :
141
141
return f"Domain(name: { self .domain_name } )"
142
142
143
143
144
144
@dataclass (frozen = True )
145
- class ProjectScope (BaseACLScope ):
145
+ class ProjectScope (BaseScope ):
146
146
project_id : uuid .UUID
147
-
147
+
148
148
def __str__ (self ) -> str :
149
149
return f"Project(id: { self .project_id } )"
150
150
151
151
152
152
@dataclass (frozen = True )
153
- class UserScope (BaseACLScope ):
153
+ class UserScope (BaseScope ):
154
154
user_id : uuid .UUID
155
155
156
156
def __str__ (self ) -> str :
157
157
return f"User(id: { self .user_id } )"
158
158
159
159
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
161
161
# such as registries for images, scaling groups for agents, storage hosts for vfolders etc.
162
- class ExtraACLScope :
162
+ class ExtraScope :
163
163
pass
164
164
165
165
166
166
@dataclass (frozen = True )
167
- class StorageHost (ExtraACLScope ):
167
+ class StorageHost (ExtraScope ):
168
168
name : str
169
169
170
170
171
171
@dataclass (frozen = True )
172
- class ImageRegistry (ExtraACLScope ):
172
+ class ImageRegistry (ExtraScope ):
173
173
name : str
174
174
175
175
176
176
@dataclass (frozen = True )
177
- class ScalingGroup (ExtraACLScope ):
177
+ class ScalingGroup (ExtraScope ):
178
178
name : str
179
179
180
180
181
- ACLObjectType = TypeVar ("ACLObjectType " )
182
- ACLObjectIDType = TypeVar ("ACLObjectIDType " )
181
+ ObjectType = TypeVar ("ObjectType " )
182
+ ObjectIDType = TypeVar ("ObjectIDType " )
183
183
184
184
185
185
@dataclass
186
- class AbstractACLPermissionContext (
187
- Generic [ACLPermissionType , ACLObjectType , ACLObjectIDType ], metaclass = ABCMeta
186
+ class AbstractPermissionContext (
187
+ Generic [PermissionType , ObjectType , ObjectIDType ], metaclass = ABCMeta
188
188
):
189
189
"""
190
- Define ACL permissions under given User, Project or Domain scopes.
190
+ Define permissions under given User, Project or Domain scopes.
191
191
Each field of this class represents a mapping of ["accessible scope id", "permissions under the scope"].
192
192
For example, `project` field has a mapping of ["accessible project id", "permissions under the project"].
193
193
{
194
194
"PROJECT_A_ID": {"READ", "WRITE", "DELETE"}
195
195
"PROJECT_B_ID": {"READ"}
196
196
}
197
197
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.
200
200
`overriding` field is used to address exceptional cases such as permission overriding or cover other scopes(scaling groups or storage hosts etc).
201
201
"""
202
202
203
- user_id_to_permission_map : Mapping [uuid .UUID , frozenset [ACLPermissionType ]] = field (
203
+ user_id_to_permission_map : Mapping [uuid .UUID , frozenset [PermissionType ]] = field (
204
204
default_factory = dict
205
205
)
206
- project_id_to_permission_map : Mapping [uuid .UUID , frozenset [ACLPermissionType ]] = field (
206
+ project_id_to_permission_map : Mapping [uuid .UUID , frozenset [PermissionType ]] = field (
207
207
default_factory = dict
208
208
)
209
- domain_name_to_permission_map : Mapping [str , frozenset [ACLPermissionType ]] = field (
209
+ domain_name_to_permission_map : Mapping [str , frozenset [PermissionType ]] = field (
210
210
default_factory = dict
211
211
)
212
212
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
+ )
219
219
220
- def filter_by_permission (self , permission_to_include : ACLPermissionType ) -> None :
220
+ def filter_by_permission (self , permission_to_include : PermissionType ) -> None :
221
221
self .user_id_to_permission_map = {
222
222
uid : permissions
223
223
for uid , permissions in self .user_id_to_permission_map .items ()
@@ -249,30 +249,28 @@ async def build_query(self) -> sa.sql.Select | None:
249
249
pass
250
250
251
251
@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 ]:
255
253
"""
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.
257
255
"""
258
256
pass
259
257
260
258
261
- ACLPermissionContextType = TypeVar ("ACLPermissionContextType " , bound = AbstractACLPermissionContext )
259
+ PermissionContextType = TypeVar ("PermissionContextType " , bound = AbstractPermissionContext )
262
260
263
261
264
- class AbstractACLPermissionContextBuilder (
265
- Generic [ACLPermissionType , ACLPermissionContextType ], metaclass = ABCMeta
262
+ class AbstractPermissionContextBuilder (
263
+ Generic [PermissionType , PermissionContextType ], metaclass = ABCMeta
266
264
):
267
265
@classmethod
268
266
async def build (
269
267
cls ,
270
268
db_session : AsyncSession ,
271
269
ctx : ClientContext ,
272
- target_scope : BaseACLScope ,
270
+ target_scope : BaseScope ,
273
271
* ,
274
- permission : ACLPermissionType | None = None ,
275
- ) -> ACLPermissionContextType :
272
+ permission : PermissionType | None = None ,
273
+ ) -> PermissionContextType :
276
274
match target_scope :
277
275
case UserScope (user_id = user_id ):
278
276
result = await cls ._build_in_user_scope (db_session , ctx , user_id )
@@ -281,7 +279,7 @@ async def build(
281
279
case DomainScope (domain_name = domain_name ):
282
280
result = await cls ._build_in_domain_scope (db_session , ctx , domain_name )
283
281
case _:
284
- raise RuntimeError (f"invalid ACL scope `{ target_scope } `" )
282
+ raise RuntimeError (f"invalid scope `{ target_scope } `" )
285
283
if permission is not None :
286
284
result .filter_by_permission (permission )
287
285
return result
@@ -293,7 +291,7 @@ async def _build_in_user_scope(
293
291
db_session : AsyncSession ,
294
292
ctx : ClientContext ,
295
293
user_id : uuid .UUID ,
296
- ) -> ACLPermissionContextType :
294
+ ) -> PermissionContextType :
297
295
pass
298
296
299
297
@classmethod
@@ -303,7 +301,7 @@ async def _build_in_project_scope(
303
301
db_session : AsyncSession ,
304
302
ctx : ClientContext ,
305
303
project_id : uuid .UUID ,
306
- ) -> ACLPermissionContextType :
304
+ ) -> PermissionContextType :
307
305
pass
308
306
309
307
@classmethod
@@ -313,5 +311,5 @@ async def _build_in_domain_scope(
313
311
db_session : AsyncSession ,
314
312
ctx : ClientContext ,
315
313
domain_name : str ,
316
- ) -> ACLPermissionContextType :
314
+ ) -> PermissionContextType :
317
315
pass
0 commit comments