Skip to content

extend IAM datastore with lower case values for faster access #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions policy_sentry/analysis/expand.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Functions to expand wilcard actions into a full list of actions."""
from __future__ import annotations

import logging
import copy
import fnmatch
Expand All @@ -8,7 +10,7 @@
logger = logging.getLogger(__name__)


def expand(action):
def expand(action: str | list[str]) -> list[str]:
"""
expand the action wildcards into a full action

Expand All @@ -26,10 +28,11 @@ def expand(action):
expanded_actions.extend(expand(item))
return expanded_actions

if "*" in action:
if action == "*":
return all_actions.copy()
elif "*" in action:
expanded = [
expanded_action
# for expanded_action in all_permissions
for expanded_action in all_actions
if fnmatch.fnmatchcase(expanded_action.lower(), action.lower())
]
Expand All @@ -47,7 +50,7 @@ def expand(action):
return [action]


def determine_actions_to_expand(action_list):
def determine_actions_to_expand(action_list: list[str]) -> list[str]:
"""
Determine if an action needs to get expanded from its wildcard

Expand All @@ -57,13 +60,13 @@ def determine_actions_to_expand(action_list):
List: A list of actions
"""
new_action_list = []
for action in range(len(action_list)):
if "*" in action_list[action]:
expanded_action = expand(action_list[action])
for action in action_list:
if "*" in action:
expanded_action = expand(action)
new_action_list.extend(expanded_action)
else:
# If there is no wildcard, copy that action name over to the new_action_list
new_action_list.append(action_list[action])
new_action_list.append(action)
new_action_list.sort()
return new_action_list

Expand Down
Loading