How to use the parliament.UnknownPrefixException function in parliament

To help you get started, we’ve selected a few parliament 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 duo-labs / parliament / tests / unit / test_action_expansion.py View on Github external
def test_exception_bad_service(self):
        try:
            expand_action("333:listallmybuckets")
            assert False
        except UnknownPrefixException as e:
            assert True
github duo-labs / parliament / parliament / statement.py View on Github external
expanded_actions = []
        for action in actions:
            # Handle special case where all actions are allowed
            if action == "*" or action == "*:*":
                # TODO Should ensure the resource is "*" with this action
                continue

            try:
                # Given an action such as "s3:List*", return all the possible values it could have
                expanded_actions.extend(expand_action(action))
            except UnknownActionException as e:
                self.add_finding(
                    "UNKNOWN_ACTION", detail=str(e), location={"unknown_action": action, "statement": self.stmt}
                )
                return False
            except UnknownPrefixException as e:
                self.add_finding(
                    "UNKNOWN_PREFIX", detail=str(e), location={"statement": self.stmt}
                )
                return False
            except Exception as e:
                self.add_finding(
                    "EXCEPTION", detail=str(e), location={"statement": self.stmt}
                )
                return False

        # Check the resources are correct formatted correctly
        has_malformed_resource = False
        for resource in resources:
            if resource == "*":
                continue
            parts = resource.split(":")