Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def minimize_statement_actions(desired_actions, all_actions, minchars=None): # pylint: disable=missing-function-docstring
minimized_actions = set()
denied_prefixes = get_denied_prefixes_from_desired(
desired_actions, all_actions)
for action in desired_actions:
if action in denied_prefixes:
# print("Action is a denied prefix. Action: {}".format(action))
minimized_actions.add(action)
continue
found_prefix = False
prefixes = _get_prefixes_for_action(action)
for prefix in prefixes:
permission = prefix.split(":")[1]
if check_min_permission_length(permission, minchars=minchars):
continue
# If the action name is not empty
if prefix not in denied_prefixes:
# pylint: disable=literal-comparison
if permission is not '':
if prefix not in desired_actions:
prefix = "{}*".format(prefix)
minimized_actions.add(prefix)
found_prefix = True
break
if not found_prefix:
print("Could not suitable prefix. Defaulting to {}".format(
def get_denied_prefixes_from_desired(desired_actions, all_actions): # pylint: disable=missing-function-docstring
denied_actions = all_actions.difference(desired_actions)
denied_prefixes = set()
for denied_action in denied_actions:
for denied_prefix in _get_prefixes_for_action(denied_action):
denied_prefixes.add(denied_prefix)
return denied_prefixes