-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdecorator.py
More file actions
42 lines (33 loc) · 1.41 KB
/
decorator.py
File metadata and controls
42 lines (33 loc) · 1.41 KB
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
import logging
from typing import Union
from feast.permissions.action import AuthzedAction
from feast.permissions.matcher import is_a_feast_object
from feast.permissions.security_manager import assert_permissions
logger = logging.getLogger(__name__)
def require_permissions(actions: Union[list[AuthzedAction], AuthzedAction]):
"""
A decorator to define the actions that are executed from the decorated class method and that must be protected
against unauthorized access.
The first parameter of the protected method must be `self`
Args:
actions: The list of actions that must be permitted to the current user.
"""
def require_permissions_decorator(func):
def permission_checker(*args, **kwargs):
logger.debug(f"permission_checker for {args}, {kwargs}")
resource = args[0]
if not is_a_feast_object(resource):
raise NotImplementedError(
f"The first argument is not of a managed type but {type(resource)}"
)
return assert_permissions(
resource=resource,
actions=actions,
)
logger.debug(
f"Current User can invoke {actions} on {resource.name}:{type(resource)} "
)
result = func(*args, **kwargs)
return result
return permission_checker
return require_permissions_decorator