Skip to content

Commit 22828e0

Browse files
authored
Merge pull request feast-dev#20 from dmartinol/feast-rbac
Feast RBAC model
2 parents 9ffce65 + 85eda7e commit 22828e0

2 files changed

Lines changed: 129 additions & 27 deletions

File tree

‎sdk/python/feast/permissions/matcher.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ def is_a_feast_object(resource: Any):
1717
return False
1818

1919

20+
def _get_type(resource: FeastObject) -> Any:
21+
is_mock = isinstance(resource, Mock)
22+
if not is_mock:
23+
return type(resource)
24+
else:
25+
return getattr(resource, "_spec_class", None)
26+
27+
28+
def _is_abstract_type(type: Any) -> bool:
29+
return bool(getattr(type, "__abstractmethods__", False))
30+
31+
2032
def resource_match_config(
2133
resource: FeastObject,
2234
expected_types: list[FeastObject],
@@ -28,10 +40,18 @@ def resource_match_config(
2840
logger.warning(f"None passed to {resource_match_config.__name__}")
2941
return False
3042

43+
_type = _get_type(resource)
3144
if not is_a_feast_object(resource):
32-
logger.warning(f"Given resource is not of a managed type but {type(resource)}")
45+
logger.warning(f"Given resource is not of a managed type but {_type}")
3346
return False
3447

48+
is_abstract = _is_abstract_type(_type)
49+
if is_abstract and not with_subclasses:
50+
logger.debug(
51+
f"Overriding default configuration for abstract type {_type}: with_subclasses=True"
52+
)
53+
with_subclasses = True
54+
3555
if with_subclasses:
3656
# mypy check ignored because of https://github.com/python/mypy/issues/11673, or it raises "Argument 2 to "isinstance" has incompatible type "tuple[Featu ..."
3757
if not isinstance(resource, tuple(expected_types)): # type: ignore

‎sdk/python/tests/unit/permissions/test_permission.py‎

Lines changed: 108 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,44 +96,126 @@ def test_normalized_args():
9696
("invalid string", ALL_RESOURCE_TYPES, False),
9797
("ALL", ALL_RESOURCE_TYPES, False),
9898
("ALL", ALL_RESOURCE_TYPES, False),
99-
(Mock(spec=FeatureView), OnDemandFeatureView, False),
100-
(Mock(spec=FeatureView), FeatureService, False),
101-
(Mock(spec=OnDemandFeatureView), FeatureView, True),
102-
(Mock(spec=OnDemandFeatureView), FeatureService, False),
103-
(Mock(spec=BatchFeatureView), FeatureView, True),
104-
(Mock(spec=BatchFeatureView), FeatureService, False),
105-
(Mock(spec=StreamFeatureView), FeatureView, True),
106-
(Mock(spec=StreamFeatureView), FeatureService, False),
107-
(Mock(spec=Entity), FeatureView, False),
108-
(Mock(spec=Entity), FeatureService, False),
109-
(Mock(spec=Entity), FeatureService, False),
110-
(Mock(spec=FeatureService), FeatureView, True),
111-
(Mock(spec=FeatureService), OnDemandFeatureView, False),
112-
(Mock(spec=DataSource), FeatureView, False),
113-
(Mock(spec=DataSource), FeatureService, False),
114-
(Mock(spec=ValidationReference), FeatureView, False),
115-
(Mock(spec=ValidationReference), FeatureService, False),
99+
(
100+
Mock(spec=FeatureView),
101+
[t for t in get_args(FeastObject) if t not in [FeatureView]],
102+
False,
103+
),
104+
(
105+
Mock(spec=OnDemandFeatureView),
106+
[t for t in get_args(FeastObject) if t not in [OnDemandFeatureView]],
107+
False,
108+
), # OnDemandFeatureView is a BaseFeatureView
109+
(
110+
Mock(spec=BatchFeatureView),
111+
FeatureView,
112+
True,
113+
), # BatchFeatureView is a FeatureView
114+
(
115+
Mock(spec=BatchFeatureView),
116+
[
117+
t
118+
for t in get_args(FeastObject)
119+
if t not in [FeatureView, BatchFeatureView]
120+
],
121+
False,
122+
),
123+
(
124+
Mock(spec=StreamFeatureView),
125+
FeatureView,
126+
True,
127+
), # StreamFeatureView is a FeatureView
128+
(
129+
Mock(spec=StreamFeatureView),
130+
[
131+
t
132+
for t in get_args(FeastObject)
133+
if t not in [FeatureView, StreamFeatureView]
134+
],
135+
False,
136+
),
137+
(
138+
Mock(spec=Entity),
139+
[t for t in get_args(FeastObject) if t not in [Entity]],
140+
False,
141+
),
142+
(
143+
Mock(spec=FeatureService),
144+
[t for t in get_args(FeastObject) if t not in [FeatureService]],
145+
False,
146+
),
147+
(
148+
Mock(spec=DataSource),
149+
[t for t in get_args(FeastObject) if t not in [DataSource]],
150+
False,
151+
),
152+
(
153+
Mock(spec=ValidationReference),
154+
[t for t in get_args(FeastObject) if t not in [ValidationReference]],
155+
False,
156+
),
116157
]
117158
+ [(Mock(spec=t), ALL_RESOURCE_TYPES, True) for t in get_args(FeastObject)]
118159
+ [(Mock(spec=t), [t], True) for t in get_args(FeastObject)],
119160
)
120-
def _test_match_resource_with_subclasses(resource, types, result): # TEMPORARY DISABLED
161+
def test_match_resource_with_subclasses(resource, types, result):
121162
p = Permission(name="test", types=types, with_subclasses=True)
122163
assertpy.assert_that(p.match_resource(resource)).is_equal_to(result)
123164

124165

125166
@pytest.mark.parametrize(
126-
"resource, result",
167+
"resource, types, result",
127168
[
128-
(None, False),
129-
("invalid string", False),
130-
("ALL", False),
131-
("ALL", False),
169+
(None, ALL_RESOURCE_TYPES, False),
170+
("invalid string", ALL_RESOURCE_TYPES, False),
171+
("ALL", ALL_RESOURCE_TYPES, False),
172+
("ALL", ALL_RESOURCE_TYPES, False),
173+
(
174+
Mock(spec=FeatureView),
175+
[t for t in get_args(FeastObject) if t not in [FeatureView]],
176+
False,
177+
),
178+
(
179+
Mock(spec=OnDemandFeatureView),
180+
[t for t in get_args(FeastObject) if t not in [OnDemandFeatureView]],
181+
False,
182+
),
183+
(
184+
Mock(spec=BatchFeatureView),
185+
[t for t in get_args(FeastObject) if t not in [BatchFeatureView]],
186+
False,
187+
),
188+
(
189+
Mock(spec=StreamFeatureView),
190+
[t for t in get_args(FeastObject) if t not in [StreamFeatureView]],
191+
False,
192+
),
193+
(
194+
Mock(spec=Entity),
195+
[t for t in get_args(FeastObject) if t not in [Entity]],
196+
False,
197+
),
198+
(
199+
Mock(spec=FeatureService),
200+
[t for t in get_args(FeastObject) if t not in [FeatureService]],
201+
False,
202+
),
203+
(
204+
Mock(spec=DataSource),
205+
[t for t in get_args(FeastObject) if t not in [DataSource]],
206+
False,
207+
),
208+
(
209+
Mock(spec=ValidationReference),
210+
[t for t in get_args(FeastObject) if t not in [ValidationReference]],
211+
False,
212+
),
132213
]
133-
+ [(Mock(spec=t), True) for t in get_args(FeastObject)],
214+
+ [(Mock(spec=t), ALL_RESOURCE_TYPES, True) for t in get_args(FeastObject)]
215+
+ [(Mock(spec=t), [t], True) for t in get_args(FeastObject)],
134216
)
135-
def test_match_resource_no_subclasses(resource, result):
136-
p = Permission(name="test", with_subclasses=False)
217+
def test_match_resource_no_subclasses(resource, types, result):
218+
p = Permission(name="test", types=types, with_subclasses=False)
137219
assertpy.assert_that(p.match_resource(resource)).is_equal_to(result)
138220

139221

0 commit comments

Comments
 (0)