How to use the policyuniverse.expander_minimizer._get_prefixes_for_action function in policyuniverse

To help you get started, we’ve selected a few policyuniverse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / policy_sentry / policy_sentry / writing / minimize.py View on Github external
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(
github salesforce / policy_sentry / policy_sentry / writing / minimize.py View on Github external
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