okta-expression-parser 0.4.2__tar.gz → 0.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: okta-expression-parser
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: Returns a boolean by passing Okta profile data to an Okta Expression using Okta Expression Language
5
5
  Author: Mathew Moon
6
6
  Author-email: me@mathewmoon.net
@@ -22,7 +22,7 @@ log_level = environ.get("LOG_LEVEL", "ERROR")
22
22
 
23
23
  log_rank = log_levels.index(log_level)
24
24
 
25
- for level_name in list(reversed(log_levels))[:log_rank +1]:
25
+ for level_name in list(reversed(log_levels))[: log_rank + 1]:
26
26
  log_attr = level_name.lower()
27
27
  setattr(sly.yacc.SlyLogger, log_attr, lambda self, msg, *args, **kwargs: None)
28
28
 
@@ -340,47 +340,34 @@ class ExpressionParser(sly.Parser):
340
340
 
341
341
  return p.operand in self.__group_ids
342
342
 
343
+ def _member_group_names(self) -> List[str]:
344
+ """Names of the groups in `group_data` that the user is actually a member of"""
345
+ return [
346
+ name
347
+ for group_id, group in self.group_data.items()
348
+ if group_id in self.__group_ids
349
+ and (name := (group.get("profile") or {}).get("name")) is not None
350
+ ]
351
+
343
352
  @_('MEMBEROFNAME "(" operand ")"')
344
353
  def condition(self, p: YaccProduction):
345
354
  """Tests if a user is a member of a group with a specific name"""
346
-
347
- matches = [
348
- v for k, v in self.group_data.items() if v["profile"]["name"] == p.operand
349
- ]
350
-
351
- return bool(matches)
355
+ return p.operand in self._member_group_names()
352
356
 
353
357
  @_('MEMBEROFGROUPSTARTSWITH "(" operand ")"')
354
358
  def condition(self, p: YaccProduction):
355
- """Tests if a user is a member of a group with a specific name"""
356
-
357
- matches = [
358
- v
359
- for k, v in self.group_data.items()
360
- if v["profile"]["name"].startswith(p.operand)
361
- ]
362
-
363
- return bool(matches)
359
+ """Tests if a user is a member of a group whose name starts with a prefix"""
360
+ return any(n.startswith(p.operand) for n in self._member_group_names())
364
361
 
365
362
  @_('MEMBEROFGROUPCONTAINS "(" operand ")"')
366
363
  def condition(self, p: YaccProduction):
367
- """Tests if a user is a member of a group with a specific name"""
368
-
369
- matches = [
370
- v for k, v in self.group_data.items() if p.operand in v["profile"]["name"]
371
- ]
372
-
373
- return bool(matches)
364
+ """Tests if a user is a member of a group whose name contains a substring"""
365
+ return any(p.operand in n for n in self._member_group_names())
374
366
 
375
367
  @_('MEMBEROFGROUPNAMEREGEX "(" operand ")"')
376
368
  def condition(self, p: YaccProduction):
377
- """Tests if a user is a member of a group with a specific name"""
378
-
379
- for _, group in self.group_data.items():
380
- if match(p.operand, group["profile"]["name"]):
381
- return True
382
-
383
- return False
369
+ """Tests if a user is a member of a group whose name matches a regex"""
370
+ return any(match(p.operand, n) for n in self._member_group_names())
384
371
 
385
372
  @_("operand QUESTION_MARK operand COLON operand") # noqa: 821
386
373
  @_("condition QUESTION_MARK operand COLON operand") # noqa: 821
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "okta-expression-parser"
3
- version = "0.4.2"
3
+ version = "0.4.3"
4
4
  description = "Returns a boolean by passing Okta profile data to an Okta Expression using Okta Expression Language"
5
5
  authors = ["Mathew Moon <me@mathewmoon.net>"]
6
6
  readme = "README.md"