Beispiel #1
0
    def get_owners(cls, project_id, data):
        """
        For a given project_id, and event data blob.

        If Everyone is returned, this means we implicitly are
        falling through our rules and everyone is responsible.

        If an empty list is returned, this means there are explicitly
        no owners.
        """
        try:
            ownership = cls.objects.get(project_id=project_id)
        except cls.DoesNotExist:
            ownership = cls(
                project_id=project_id,
            )

        rules = []
        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    rules.append(rule)

        if not rules:
            return cls.Everyone if ownership.fallthrough else [], None

        owners = {o for rule in rules for o in rule.owners}

        return filter(None, resolve_actors(owners, project_id).values()), rules
Beispiel #2
0
    def get_owners(cls, project_id, data):
        """
        For a given project_id, and event data blob.

        If Everyone is returned, this means we implicitly are
        falling through our rules and everyone is responsible.

        If an empty list is returned, this means there are explicitly
        no owners.
        """
        try:
            ownership = cls.objects.get(project_id=project_id)
        except cls.DoesNotExist:
            ownership = cls(
                project_id=project_id,
            )

        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    # This is O(n) to resolve, but should be fine for now
                    # since we don't even explain that you can use multiple
                    # let alone a number that would be potentially abusive.
                    owners = []
                    for o in rule.owners:
                        try:
                            owners.append(resolve_actor(o, project_id))
                        except UnknownActor:
                            continue
                    return owners, rule.matcher

        owners = cls.Everyone if ownership.fallthrough else []
        return owners, None
Beispiel #3
0
    def get_owners(cls, project_id, data):
        """
        For a given project_id, and event data blob.

        If Everyone is returned, this means we implicitly are
        falling through our rules and everyone is responsible.

        If an empty list is returned, this means there are explicitly
        no owners.
        """
        try:
            ownership = cls.objects.get(project_id=project_id)
        except cls.DoesNotExist:
            ownership = cls(
                project_id=project_id,
            )

        rules = []
        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    rules.append(rule)

        if not rules:
            return cls.Everyone if ownership.fallthrough else [], None

        owners = {o for rule in rules for o in rule.owners}

        return filter(None, resolve_actors(owners, project_id).values()), rules
Beispiel #4
0
    def get_owners(cls, project_id, data):
        """
        For a given project_id, and event data blob.

        If Everyone is returned, this means we implicitly are
        falling through our rules and everyone is responsible.

        If an empty list is returned, this means there are explicitly
        no owners.
        """
        try:
            ownership = cls.objects.get(project_id=project_id)
        except cls.DoesNotExist:
            ownership = cls(
                project_id=project_id,
            )

        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    # This is O(n) to resolve, but should be fine for now
                    # since we don't even explain that you can use multiple
                    # let alone a number that would be potentially abusive.
                    owners = []
                    for o in rule.owners:
                        try:
                            owners.append(resolve_actor(o, project_id))
                        except UnknownActor:
                            continue
                    return owners, rule.matcher

        owners = cls.Everyone if ownership.fallthrough else []
        return owners, None
Beispiel #5
0
    def _matching_ownership_rules(cls, ownership, project_id, data):
        rules = []
        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    rules.append(rule)

        return rules
Beispiel #6
0
    def _matching_ownership_rules(cls, ownership, project_id, data):
        rules = []
        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    rules.append(rule)

        return rules
    def _matching_ownership_rules(cls, ownership: "ProjectOwnership",
                                  project_id: int,
                                  data: Mapping[str, Any]) -> Sequence["Rule"]:
        rules = []
        if ownership.schema is not None:
            for rule in load_schema(ownership.schema):
                if rule.test(data):
                    rules.append(rule)

        return rules
Beispiel #8
0
def test_load_schema():
    assert load_schema(
        {
            "$version": 1,
            "rules": [
                {
                    "matcher": {"type": "path", "pattern": "*.js"},
                    "owners": [{"type": "team", "identifier": "frontend"}],
                }
            ],
        }
    ) == [Rule(Matcher("path", "*.js"), [Owner("team", "frontend")])]
Beispiel #9
0
def test_load_schema():
    assert load_schema({
        '$version':
        1,
        'rules': [{
            'matcher': {
                'type': 'path',
                'pattern': '*.js',
            },
            'owners': [{
                'type': 'team',
                'identifier': 'frontend',
            }]
        }]
    }) == [Rule(Matcher('path', '*.js'), [Owner('team', 'frontend')])]
Beispiel #10
0
def test_load_schema():
    assert load_schema({
        '$version': 1,
        'rules': [{
            'matcher': {
                'type': 'path',
                'pattern': '*.js',
            },
            'owners': [{
                'type': 'team',
                'identifier': 'frontend',
            }]
        }]
    }) == [Rule(
        Matcher('path', '*.js'),
        [Owner('team', 'frontend')]
    )]