|
1 | 1 | import logging |
2 | 2 | import os |
| 3 | +from types import Optional, Tuple |
3 | 4 |
|
| 5 | +from ..adapters.protocols import BaseAdapter |
4 | 6 | from ..queries import AccessBlobFilter |
| 7 | +from ..server.schemas import Principal |
| 8 | +from ..type_aliases import AccessBlob, AccessTags, Filters, Scopes |
5 | 9 | from ..utils import Sentinel, import_object |
6 | 10 | from .protocols import AccessPolicy |
7 | 11 | from .scopes import ALL_SCOPES, PUBLIC_SCOPES |
|
24 | 28 | class DummyAccessPolicy(AccessPolicy): |
25 | 29 | "Impose no access restrictions." |
26 | 30 |
|
27 | | - async def allowed_scopes(self, node, principal, authn_access_tags, authn_scopes): |
| 31 | + async def init_node( |
| 32 | + self, |
| 33 | + principal: Principal, |
| 34 | + authn_access_tags: Optional[AccessTags], |
| 35 | + authn_scopes: Scopes, |
| 36 | + access_blob: Optional[AccessBlob] = None, |
| 37 | + ) -> Tuple[bool, AccessBlob]: |
| 38 | + "Do nothing; there is no persistent state to initialize." |
| 39 | + return (False, access_blob) |
| 40 | + |
| 41 | + async def allowed_scopes( |
| 42 | + self, |
| 43 | + node: BaseAdapter, |
| 44 | + principal: Principal, |
| 45 | + authn_access_tags: Optional[AccessTags], |
| 46 | + authn_scopes: Scopes, |
| 47 | + ) -> Scopes: |
| 48 | + "Always allow all scopes." |
28 | 49 | return ALL_SCOPES |
29 | 50 |
|
30 | | - async def filters(self, node, principal, authn_access_tags, authn_scopes, scopes): |
| 51 | + async def filters( |
| 52 | + self, |
| 53 | + node: BaseAdapter, |
| 54 | + principal: Principal, |
| 55 | + authn_access_tags: Optional[AccessTags], |
| 56 | + authn_scopes: Scopes, |
| 57 | + scopes: Scopes, |
| 58 | + ) -> Filters: |
| 59 | + "Always impose no filtering on results." |
31 | 60 | return [] |
32 | 61 |
|
33 | 62 |
|
@@ -74,8 +103,12 @@ def _is_admin(self, authn_scopes): |
74 | 103 | return False |
75 | 104 |
|
76 | 105 | async def init_node( |
77 | | - self, principal, authn_access_tags, authn_scopes, access_blob=None |
78 | | - ): |
| 106 | + self, |
| 107 | + principal: Principal, |
| 108 | + authn_access_tags: Optional[AccessTags], |
| 109 | + authn_scopes: Scopes, |
| 110 | + access_blob: Optional[AccessBlob] = None, |
| 111 | + ) -> Tuple[bool, AccessBlob]: |
79 | 112 | if principal.type == "service": |
80 | 113 | identifier = str(principal.uuid) |
81 | 114 | else: |
@@ -157,8 +190,13 @@ async def init_node( |
157 | 190 | return access_blob_modified, access_blob_from_policy |
158 | 191 |
|
159 | 192 | async def modify_node( |
160 | | - self, node, principal, authn_access_tags, authn_scopes, access_blob |
161 | | - ): |
| 193 | + self, |
| 194 | + node: BaseAdapter, |
| 195 | + principal: Principal, |
| 196 | + authn_access_tags: Optional[AccessTags], |
| 197 | + authn_scopes: Scopes, |
| 198 | + access_blob: Optional[AccessBlob], |
| 199 | + ) -> Tuple[bool, AccessBlob]: |
162 | 200 | if principal.type == "service": |
163 | 201 | identifier = str(principal.uuid) |
164 | 202 | else: |
@@ -279,7 +317,13 @@ async def modify_node( |
279 | 317 | # modified means the blob to-be-used was changed in comparison to the user input |
280 | 318 | return access_blob_modified, access_blob_from_policy |
281 | 319 |
|
282 | | - async def allowed_scopes(self, node, principal, authn_access_tags, authn_scopes): |
| 320 | + async def allowed_scopes( |
| 321 | + self, |
| 322 | + node: BaseAdapter, |
| 323 | + principal: Principal, |
| 324 | + authn_access_tags: Optional[AccessTags], |
| 325 | + authn_scopes: Scopes, |
| 326 | + ) -> Scopes: |
283 | 327 | # If this is being called, filter_for_access has let us get this far. |
284 | 328 | # However, filters and allowed_scopes should always be implemented to |
285 | 329 | # give answers consistent with each other. |
@@ -318,7 +362,14 @@ async def allowed_scopes(self, node, principal, authn_access_tags, authn_scopes) |
318 | 362 |
|
319 | 363 | return allowed |
320 | 364 |
|
321 | | - async def filters(self, node, principal, authn_access_tags, authn_scopes, scopes): |
| 365 | + async def filters( |
| 366 | + self, |
| 367 | + node: BaseAdapter, |
| 368 | + principal: Principal, |
| 369 | + authn_access_tags: Optional[AccessTags], |
| 370 | + authn_scopes: Scopes, |
| 371 | + scopes: Scopes, |
| 372 | + ) -> Filters: |
322 | 373 | queries = [] |
323 | 374 | query_filter = AccessBlobFilter |
324 | 375 |
|
|
0 commit comments