Skip to content

Commit a06d95c

Browse files
committed
extend IAM datastore with lower case values for faster access
1 parent e50799a commit a06d95c

File tree

14 files changed

+363294
-290964
lines changed

14 files changed

+363294
-290964
lines changed

policy_sentry/analysis/expand.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Functions to expand wilcard actions into a full list of actions."""
2+
from __future__ import annotations
3+
24
import logging
35
import copy
46
import fnmatch
@@ -8,7 +10,7 @@
810
logger = logging.getLogger(__name__)
911

1012

11-
def expand(action):
13+
def expand(action: str | list[str]) -> list[str]:
1214
"""
1315
expand the action wildcards into a full action
1416
@@ -26,10 +28,11 @@ def expand(action):
2628
expanded_actions.extend(expand(item))
2729
return expanded_actions
2830

29-
if "*" in action:
31+
if action == "*":
32+
return all_actions.copy()
33+
elif "*" in action:
3034
expanded = [
3135
expanded_action
32-
# for expanded_action in all_permissions
3336
for expanded_action in all_actions
3437
if fnmatch.fnmatchcase(expanded_action.lower(), action.lower())
3538
]
@@ -47,7 +50,7 @@ def expand(action):
4750
return [action]
4851

4952

50-
def determine_actions_to_expand(action_list):
53+
def determine_actions_to_expand(action_list: list[str]) -> list[str]:
5154
"""
5255
Determine if an action needs to get expanded from its wildcard
5356
@@ -57,13 +60,13 @@ def determine_actions_to_expand(action_list):
5760
List: A list of actions
5861
"""
5962
new_action_list = []
60-
for action in range(len(action_list)):
61-
if "*" in action_list[action]:
62-
expanded_action = expand(action_list[action])
63+
for action in action_list:
64+
if "*" in action:
65+
expanded_action = expand(action)
6366
new_action_list.extend(expanded_action)
6467
else:
6568
# If there is no wildcard, copy that action name over to the new_action_list
66-
new_action_list.append(action_list[action])
69+
new_action_list.append(action)
6770
new_action_list.sort()
6871
return new_action_list
6972

0 commit comments

Comments
 (0)