Esempio n. 1
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
Esempio 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 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
Esempio n. 3
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)
Esempio n. 4
0
 def _to_config_structure(self):
     if self.key == 'family':
         arg = ''.join(filter(None, [FAMILIES.get(x) for x in self.pattern.split(',')]))
     elif self.key == 'app':
         arg = {True: '1', False: '0'}.get(get_rule_bool(self.pattern), '')
     else:
         arg = self.pattern
     return MATCH_KEYS[self.key] + arg
Esempio n. 5
0
 def _to_config_structure(self):
     if self.key == "family":
         arg = "".join([_f for _f in [FAMILIES.get(x) for x in self.pattern.split(",")] if _f])
     elif self.key == "app":
         arg = {True: "1", False: "0"}.get(get_rule_bool(self.pattern), "")
     else:
         arg = self.pattern
     return MATCH_KEYS[self.key] + arg
Esempio n. 6
0
 def _to_config_structure(self):
     if self.key == 'family':
         arg = ''.join(filter(None, [FAMILIES.get(x) for x in self.pattern.split(',')]))
     elif self.key == 'app':
         arg = {True: '1', False: '0'}.get(get_rule_bool(self.pattern), '')
     else:
         arg = self.pattern
     return MATCH_KEYS[self.key] + arg
Esempio 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)
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
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)
Esempio n. 11
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._ref_val = get_rule_bool(self.pattern)