-
Notifications
You must be signed in to change notification settings - Fork 1
/
orchestator.py
45 lines (38 loc) · 1.46 KB
/
orchestator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from impl import ResourceA, ResourceB
from security.permissions import AuthzedAction
from security.security_manager import SecurityManager
class Orchestrator:
def __init__(self, sm: SecurityManager) -> None:
self.sm = sm
def do_something(self, a: ResourceA, b: ResourceB) -> list[str]:
messages: list[str] = []
# Read from A
try:
print(f"Trying read from {a}")
self.sm.assert_permissions(a, AuthzedAction.READ)
a.read_protected()
messages.append("DONE a.read_protected()")
except PermissionError as e:
messages.append(f"{e}")
try:
print(f"Trying read from {b}")
self.sm.assert_permissions(b, AuthzedAction.READ)
b.read_protected()
messages.append("DONE b.read_protected()")
except PermissionError as e:
messages.append(f"{e}")
try:
print(f"Trying edit of {a}")
self.sm.assert_permissions(a, AuthzedAction.EDIT)
a.edit_protected()
messages.append("DONE a.edit_protected()")
except PermissionError as e:
messages.append(f"{e}")
try:
print(f"Trying edit of {b}")
self.sm.assert_permissions(b, AuthzedAction.EDIT)
b.edit_protected()
messages.append("DONE b.edit_protected()")
except PermissionError as e:
messages.append(f"{e}")
return messages