Exemplo n.º 1
0
    def matches_frame(self, frame_data, platform):
        # Path matches are always case insensitive
        if self.key in ('path', 'package'):
            if self.key == 'package':
                value = frame_data.get('package') or ''
            else:
                value = frame_data.get('abs_path') or frame_data.get('filename') or ''
            if glob_match(value, self.pattern, ignorecase=True,
                          doublestar=True, path_normalize=True):
                return True
            if not value.startswith('/') and glob_match('/' + value, self.pattern,
                                                        ignorecase=True, doublestar=True, path_normalize=True):
                return True
            return False

        # families need custom handling as well
        if self.key == 'family':
            flags = self.pattern.split(',')
            if 'all' in flags:
                return True
            family = get_behavior_family_for_platform(frame_data.get('platform') or platform)
            return family in flags

        # all other matches are case sensitive
        if self.key == 'function':
            from sentry.stacktraces.functions import get_function_name_for_frame
            value = get_function_name_for_frame(frame_data, platform) or '<unknown>'
        elif self.key == 'module':
            value = frame_data.get('module') or '<unknown>'
        else:
            # should not happen :)
            value = '<unknown>'
        return glob_match(value, self.pattern)
Exemplo n.º 2
0
 def matches_value(self, value):
     if value is None:
         return False
     if self.key in ('path', 'package'):
         if glob_match(value,
                       self.pattern,
                       ignorecase=True,
                       doublestar=True,
                       path_normalize=True):
             return True
         if not value.startswith('/') and glob_match('/' + value,
                                                     self.pattern,
                                                     ignorecase=True,
                                                     doublestar=True,
                                                     path_normalize=True):
             return True
     elif self.key == 'family':
         flags = self.pattern.split(',')
         if 'all' in flags or value in flags:
             return True
     elif glob_match(value,
                     self.pattern,
                     ignorecase=self.key in ('message', 'value')):
         return True
     return False
Exemplo n.º 3
0
 def matches_value(self, value):
     if value is None:
         return False
     if self.key in ("path", "package"):
         if glob_match(value,
                       self.pattern,
                       ignorecase=True,
                       doublestar=True,
                       path_normalize=True):
             return True
         if not value.startswith("/") and glob_match("/" + value,
                                                     self.pattern,
                                                     ignorecase=True,
                                                     doublestar=True,
                                                     path_normalize=True):
             return True
     elif self.key == "family":
         flags = self.pattern.split(",")
         if "all" in flags or value in flags:
             return True
     elif self.key == "app":
         ref_val = get_rule_bool(self.pattern)
         if ref_val is not None and ref_val == value:
             return True
     elif glob_match(value,
                     self.pattern,
                     ignorecase=self.key in ("message", "value")):
         return True
     return False
Exemplo n.º 4
0
    def _positive_frame_match(self, frame_data, platform, exception_data):
        # Path matches are always case insensitive
        if self.key in ("path", "package"):
            if self.key == "package":
                value = frame_data.get("package") or ""
            else:
                value = frame_data.get("abs_path") or frame_data.get(
                    "filename") or ""
            if glob_match(value,
                          self.pattern,
                          ignorecase=True,
                          doublestar=True,
                          path_normalize=True):
                return True
            if not value.startswith("/") and glob_match("/" + value,
                                                        self.pattern,
                                                        ignorecase=True,
                                                        doublestar=True,
                                                        path_normalize=True):
                return True

            return False

        # families need custom handling as well
        if self.key == "family":
            flags = self.pattern.split(",")
            if "all" in flags:
                return True
            family = get_behavior_family_for_platform(
                frame_data.get("platform") or platform)
            return family in flags

        # in-app matching is just a bool
        if self.key == "app":
            ref_val = get_rule_bool(self.pattern)
            return ref_val is not None and ref_val == frame_data.get("in_app")

        # all other matches are case sensitive
        if self.key == "function":
            from sentry.stacktraces.functions import get_function_name_for_frame

            value = get_function_name_for_frame(frame_data,
                                                platform) or "<unknown>"
        elif self.key == "module":
            value = frame_data.get("module") or "<unknown>"
        elif self.key == "type":
            value = get_path(exception_data, "type") or "<unknown>"
        elif self.key == "value":
            value = get_path(exception_data, "value") or "<unknown>"
        elif self.key == "mechanism":
            value = get_path(exception_data, "mechanism",
                             "type") or "<unknown>"
        elif self.key == "category":
            value = get_path(frame_data, "data", "category") or "<unknown>"
        else:
            # should not happen :)
            value = "<unknown>"

        return glob_match(value, self.pattern)
Exemplo n.º 5
0
 def _positive_path_match(self, value):
     if value is None:
         return False
     if glob_match(value, self.pattern, ignorecase=True, doublestar=True, path_normalize=True):
         return True
     if not value.startswith("/") and glob_match(
         "/" + value, self.pattern, ignorecase=True, doublestar=True, path_normalize=True
     ):
         return True
     return False
Exemplo n.º 6
0
def path_like_match(pattern, value):
    """Stand-alone function for use with ``cached``"""
    if glob_match(value,
                  pattern,
                  ignorecase=False,
                  doublestar=True,
                  path_normalize=True):
        return True
    if not value.startswith(b"/") and glob_match(b"/" + value,
                                                 pattern,
                                                 ignorecase=False,
                                                 doublestar=True,
                                                 path_normalize=True):
        return True

    return False
Exemplo n.º 7
0
    def matches_frame(self, frame_data, platform):
        # Path matches are always case insensitive
        if self.key in ('path', 'package'):
            if self.key == 'package':
                value = frame_data.get('package') or ''
            else:
                value = frame_data.get('abs_path') or frame_data.get(
                    'filename') or ''
            if glob_match(value,
                          self.pattern,
                          ignorecase=True,
                          doublestar=True,
                          path_normalize=True):
                return True
            if not value.startswith('/') and glob_match('/' + value,
                                                        self.pattern,
                                                        ignorecase=True,
                                                        doublestar=True,
                                                        path_normalize=True):
                return True
            return False

        # families need custom handling as well
        if self.key == 'family':
            flags = self.pattern.split(',')
            if 'all' in flags:
                return True
            family = get_behavior_family_for_platform(
                frame_data.get('platform') or platform)
            return family in flags

        # in-app matching is just a bool
        if self.key == 'app':
            ref_val = get_rule_bool(self.pattern)
            return ref_val is not None and ref_val == frame_data.get('in_app')

        # all other matches are case sensitive
        if self.key == 'function':
            from sentry.stacktraces.functions import get_function_name_for_frame
            value = get_function_name_for_frame(frame_data,
                                                platform) or '<unknown>'
        elif self.key == 'module':
            value = frame_data.get('module') or '<unknown>'
        else:
            # should not happen :)
            value = '<unknown>'
        return glob_match(value, self.pattern)
Exemplo n.º 8
0
 def matches_value(self, value):
     if value is None:
         return False
     if self.key in ('path', 'package'):
         if glob_match(value, self.pattern, ignorecase=True,
                       doublestar=True, path_normalize=True):
             return True
         if not value.startswith('/') and glob_match(
                 '/' + value, self.pattern, ignorecase=True,
                 doublestar=True, path_normalize=True):
             return True
     elif self.key == 'family':
         flags = self.pattern.split(',')
         if 'all' in flags or value in flags:
             return True
     elif glob_match(value, self.pattern, ignorecase=self.key in ('message', 'value')):
         return True
     return False
Exemplo n.º 9
0
    def matches_frame(self, frame_data, platform):
        # Path matches are always case insensitive
        if self.key in ('path', 'package'):
            if self.key == 'package':
                value = frame_data.get('package') or ''
            else:
                value = frame_data.get('abs_path') or frame_data.get(
                    'filename') or ''
            if glob_match(value,
                          self.pattern,
                          ignorecase=True,
                          doublestar=True,
                          path_normalize=True):
                return True
            if not value.startswith('/') and glob_match('/' + value,
                                                        self.pattern,
                                                        ignorecase=True,
                                                        doublestar=True,
                                                        path_normalize=True):
                return True
            return False

        # families need custom handling as well
        if self.key == 'family':
            flags = self.pattern.split(',')
            if 'all' in flags:
                return True
            family = get_grouping_family_for_platform(
                frame_data.get('platform') or platform)
            return family in flags

        # all other matches are case sensitive
        if self.key == 'function':
            from sentry.grouping.strategies.utils import trim_function_name
            value = trim_function_name(
                frame_data.get('function') or '<unknown>',
                frame_data.get('platform') or platform)
        elif self.key == 'module':
            value = frame_data.get('module') or '<unknown>'
        else:
            # should not happen :)
            value = '<unknown>'
        return glob_match(value, self.pattern)
Exemplo n.º 10
0
    def test_path(self, data):
        for frame in _iter_frames(data):
            filename = frame.get("filename") or frame.get("abs_path")

            if not filename:
                continue

            if glob_match(filename, self.pattern, ignorecase=True, path_normalize=True):
                return True

        return False
Exemplo n.º 11
0
    def test_frames(self, data, keys):
        for frame in _iter_frames(data):
            value = next((frame.get(key) for key in keys if frame.get(key)), None)

            if not value:
                continue

            if glob_match(value, self.pattern, ignorecase=True, path_normalize=True):
                return True

        return False
Exemplo n.º 12
0
    def _positive_match(self, values):
        # path is special in that it tests against two values (abs_path and path)
        if self.key == "path":
            value = values.get("abs_path")
            if self._positive_path_match(value):
                return True
            alt_value = values.get("filename")
            if alt_value != value:
                if self._positive_path_match(value):
                    return True
            return False

        # message tests against value as well as this is what users expect
        if self.key == "message":
            for key in ("message", "value"):
                value = values.get(key)
                if value is not None and glob_match(
                        value, self.pattern, ignorecase=True):
                    return True
            return False

        value = values.get(self.key)
        if value is None:
            return False
        elif self.key == "package":
            if self._positive_path_match(value):
                return True
        elif self.key == "family":
            flags = self.pattern.split(",")
            if "all" in flags or value in flags:
                return True
        elif self.key == "app":
            ref_val = get_rule_bool(self.pattern)
            if ref_val is not None and ref_val == value:
                return True
        elif glob_match(value,
                        self.pattern,
                        ignorecase=self.key in ("level", "value")):
            return True
        return False
Exemplo n.º 13
0
 def __call__(self):
     return glob_match(self.value, self.pat, **self.kwargs)
Exemplo n.º 14
0
 def test_tag(self, data):
     tag = self.type[5:]
     for k, v in get_path(data, "tags", filter=True) or ():
         if k == tag and glob_match(v, self.pattern):
             return True
     return False
Exemplo n.º 15
0
 def __call__(self):
     return glob_match(**self.__dict__)
Exemplo n.º 16
0
 def __call__(self):
     return glob_match(**self.__dict__)
Exemplo n.º 17
0
 def test_url(self, data):
     try:
         url = data["request"]["url"]
     except KeyError:
         return False
     return url and glob_match(url, self.pattern, ignorecase=True)
Exemplo n.º 18
0
 def test_tag(self, data):
     tag = self.type[5:]
     for k, v in data.get("tags"):
         if k == tag and glob_match(v, self.pattern):
             return True
     return False