summaryrefslogtreecommitdiff
path: root/src/saml2/filter.py
blob: 849cfe5d138d41dbc784ddbcc35570663bc17f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
__author__ = "roland"


class Filter:
    def __init__(self):
        pass

    def __call__(self, *args, **kwargs):
        pass


class AllowDescriptor(Filter):
    def __init__(self, allow):
        """

        :param allow: List of allowed descriptors
        :return:
        """
        super().__init__()
        self.allow = allow

    def __call__(self, entity_descriptor):
        # get descriptors
        _all = []
        for desc in list(entity_descriptor.keys()):
            if desc.endswith("_descriptor"):
                typ, _ = desc.rsplit("_", 1)
                if typ in self.allow:
                    _all.append(typ)
                else:
                    del entity_descriptor[desc]

        if not _all:
            return None
        else:
            return entity_descriptor