Пример #1
0
def store(request):
    if request.method != "POST":
        return HttpResponseNotAllowed("This method only supports POST requests")

    if request.META.get("HTTP_AUTHORIZATION", "").startswith("Sentry"):
        auth_vars = parse_auth_header(request.META["HTTP_AUTHORIZATION"])

        signature = auth_vars.get("sentry_signature")
        timestamp = auth_vars.get("sentry_timestamp")

        format = "json"

        data = request.raw_post_data

        # Signed data packet
        if signature and timestamp:
            try:
                timestamp = float(timestamp)
            except ValueError:
                return HttpResponseBadRequest("Invalid timestamp")

            if timestamp < time.time() - 3600:  # 1 hour
                return HttpResponseGone("Message has expired")

            sig_hmac = get_signature(data, timestamp)
            if sig_hmac != signature:
                return HttpResponseForbidden("Invalid signature")
        else:
            return HttpResponse("Unauthorized", status_code=401)
    else:
        data = request.POST.get("data")
        if not data:
            return HttpResponseBadRequest("Missing data")

        format = request.POST.get("format", "pickle")

        if format not in ("pickle", "json"):
            return HttpResponseBadRequest("Invalid format")

        # Legacy request (deprecated as of 2.0)
        key = request.POST.get("key")

        if key != settings.KEY:
            warnings.warn(
                "A client is sending the `key` parameter, which will be removed in Sentry 2.0", DeprecationWarning
            )
            return HttpResponseForbidden("Invalid credentials")

    logger = logging.getLogger("sentry.server")

    try:
        try:
            data = base64.b64decode(data).decode("zlib")
        except zlib.error:
            data = base64.b64decode(data)
    except Exception, e:
        # This error should be caught as it suggests that there's a
        # bug somewhere in the client's code.
        logger.exception("Bad data received")
        return HttpResponseForbidden("Bad data decoding request (%s, %s)" % (e.__class__.__name__, e))
Пример #2
0
    def send(self, **kwargs):
        "Sends the message to the server."
        if settings.REMOTE_URL:
            message = base64.b64encode(json.dumps(kwargs).encode("zlib"))
            for url in settings.REMOTE_URL:
                timestamp = time.time()
                signature = get_signature(message, timestamp)
                headers = {
                    "Authorization": get_auth_header(
                        signature, timestamp, "%s/%s" % (self.__class__.__name__, sentry.VERSION)
                    ),
                    "Content-Type": "application/octet-stream",
                }

                try:
                    return self.send_remote(url=url, data=message, headers=headers)
                except urllib2.HTTPError, e:
                    body = e.read()
                    logger.error(
                        "Unable to reach Sentry log server: %s (url: %%s, body: %%s)" % (e,),
                        url,
                        body,
                        exc_info=True,
                        extra={"data": {"body": body, "remote_url": url}},
                    )
                    logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))
                except urllib2.URLError, e:
                    logger.error(
                        "Unable to reach Sentry log server: %s (url: %%s)" % (e,),
                        url,
                        exc_info=True,
                        extra={"data": {"remote_url": url}},
                    )
                    logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))
Пример #3
0
def store(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed('This method only supports POST requests')

    if request.META.get('HTTP_AUTHORIZATION', '').startswith('Sentry'):
        auth_vars = parse_auth_header(request.META['HTTP_AUTHORIZATION'])

        signature = auth_vars.get('sentry_signature')
        timestamp = auth_vars.get('sentry_timestamp')

        format = 'json'

        data = request.raw_post_data

        # Signed data packet
        if signature and timestamp:
            try:
                timestamp = float(timestamp)
            except ValueError:
                return HttpResponseBadRequest('Invalid timestamp')

            if timestamp < time.time() - 3600: # 1 hour
                return HttpResponseGone('Message has expired')

            sig_hmac = get_signature(data, timestamp)
            if sig_hmac != signature:
                return HttpResponseForbidden('Invalid signature')
        else:
            return HttpResponse('Unauthorized', status_code=401)
    else:
        data = request.POST.get('data', request.raw_post_data)

        if not data:
            return HttpResponseBadRequest('Missing data')

        format = request.POST.get('format', 'json')

        if format not in ('pickle', 'json'):
            return HttpResponseBadRequest('Invalid format')

        # Legacy request (deprecated as of 2.0)
        key = request.POST.get('key', settings.KEY)

        if key != settings.KEY:
            warnings.warn('A client is sending the `key` parameter, which will be removed in Sentry 2.0', DeprecationWarning)
            return HttpResponseForbidden('Invalid credentials')

    logger = logging.getLogger('sentry.server')

    try:
        try:
            data = base64.b64decode(data).decode('zlib')
        except zlib.error:
            data = base64.b64decode(data)
    except Exception, e:
        # This error should be caught as it suggests that there's a
        # bug somewhere in the client's code.
        logger.exception('Bad data received')
        return HttpResponseForbidden('Bad data decoding request (%s, %s)' % (e.__class__.__name__, e))
Пример #4
0
 def _postWithSignature(self, data):
     ts = time.time()
     message = base64.b64encode(json.dumps(transform(data)))
     sig = get_signature(message, ts)
     
     resp = self.client.post(reverse('sentry-store'), message,
         content_type='application/octet-stream',
         HTTP_AUTHORIZATION=get_auth_header(sig, ts, '_postWithSignature'),
     )
     return resp
Пример #5
0
 def _postWithSignature(self, data):
     ts = time.time()
     message = base64.b64encode(json.dumps(transform(data)))
     sig = get_signature(message, ts)
     
     resp = self.client.post(reverse('sentry-store'), message,
         content_type='application/octet-stream',
         HTTP_AUTHORIZATION=get_auth_header(sig, ts, '_postWithSignature'),
     )
     return resp
Пример #6
0
def store():
    if request.environ.get('AUTHORIZATION', '').startswith('Sentry'):
        auth_vars = parse_auth_header(request.META['AUTHORIZATION'])
        
        signature = auth_vars.get('sentry_signature')
        timestamp = auth_vars.get('sentry_timestamp')

        format = 'json'

        data = request.raw_post_data

        # Signed data packet
        if signature and timestamp:
            try:
                timestamp = float(timestamp)
            except ValueError:
                abort(400, 'Invalid Timestamp')

            if timestamp < time.time() - 3600: # 1 hour
                abort(410, 'Message has expired')

            sig_hmac = get_signature(data, timestamp)
            if sig_hmac != signature:
                abort(403, 'Invalid signature')
        else:
            abort(401,'Unauthorized')
    else:
        data = request.form.get('data')
        if not data:
            abort(400, 'Missing data')

        format = request.form.get('format', 'pickle')

        if format not in ('pickle', 'json'):
            abort(400, 'Invalid format')

        # Legacy request (deprecated as of 2.0)
        key = request.form.get('key')
        
        if key != app.config['KEY']:
            warnings.warn('A client is sending the `key` parameter, which will be removed in Sentry 2.0', DeprecationWarning)
            abort(403, 'Invalid credentials')

    logger = logging.getLogger('sentry.server')

    try:
        try:
            data = base64.b64decode(data).decode('zlib')
        except zlib.error:
            data = base64.b64decode(data)
    except Exception, e:
        # This error should be caught as it suggests that there's a
        # bug somewhere in the client's code.
        logger.exception('Bad data received')
        abort(400, 'Bad data decoding request (%s, %s)' % (e.__class__.__name__, e))
Пример #7
0
    def send(self, **kwargs):
        "Sends the message to the server."
        if settings.REMOTE_URL:
            for url in settings.REMOTE_URL:
                message = base64.b64encode(
                    simplejson.dumps(kwargs).encode('zlib'))
                timestamp = time.time()
                signature = get_signature(message, timestamp)
                headers = {
                    'Authorization':
                    get_auth_header(
                        signature, timestamp,
                        '%s/%s' % (self.__class__.__name__, sentry.VERSION)),
                    'Content-Type':
                    'application/octet-stream',
                }

                try:
                    return self.send_remote(url=url,
                                            data=message,
                                            headers=headers)
                except urllib2.HTTPError, e:
                    body = e.read()
                    logger.error(
                        'Unable to reach Sentry log server: %s (url: %%s, body: %%s)'
                        % (e, ),
                        url,
                        body,
                        exc_info=sys.exc_info(),
                        extra={'data': {
                            'body': body,
                            'remote_url': url
                        }})
                    logger.log(
                        kwargs.pop('level', None) or logging.ERROR,
                        kwargs.pop('message', None))
                except urllib2.URLError, e:
                    logger.error(
                        'Unable to reach Sentry log server: %s (url: %%s)' %
                        (e, ),
                        url,
                        exc_info=sys.exc_info(),
                        extra={'data': {
                            'remote_url': url
                        }})
                    logger.log(
                        kwargs.pop('level', None) or logging.ERROR,
                        kwargs.pop('message', None))
Пример #8
0
 def send(self, **kwargs):
     "Sends the message to the server."
     if settings.REMOTE_URL:
         for url in settings.REMOTE_URL:
             message = base64.b64encode(json.dumps(kwargs).encode('zlib'))
             timestamp = time.time()
             signature = get_signature(message, timestamp)
             headers={
                 'Authorization': get_auth_header(signature, timestamp, '%s/%s' % (self.__class__.__name__, sentry.VERSION)),
                 'Content-Type': 'application/octet-stream',
             }
             
             try:
                 return self.send_remote(url=url, data=message, headers=headers)
             except urllib2.HTTPError, e:
                 body = e.read()
                 logger.error('Unable to reach Sentry log server: %s (url: %%s, body: %%s)' % (e,), url, body,
                              exc_info=sys.exc_info(), extra={'data':{'body': body, 'remote_url': url}})
                 logger.log(kwargs.pop('level', None) or logging.ERROR, kwargs.pop('message', None))
             except urllib2.URLError, e:
                 logger.error('Unable to reach Sentry log server: %s (url: %%s)' % (e,), url,
                              exc_info=sys.exc_info(), extra={'data':{'remote_url': url}})
                 logger.log(kwargs.pop('level', None) or logging.ERROR, kwargs.pop('message', None))
Пример #9
0
def store(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed(
            'This method only supports POST requests')

    if request.META.get('HTTP_AUTHORIZATION', '').startswith('Sentry'):
        auth_vars = parse_auth_header(request.META['HTTP_AUTHORIZATION'])

        signature = auth_vars.get('sentry_signature')
        timestamp = auth_vars.get('sentry_timestamp')

        format = 'json'

        data = request.raw_post_data

        # Signed data packet
        if signature and timestamp:
            try:
                timestamp = float(timestamp)
            except ValueError:
                return HttpResponseBadRequest('Invalid timestamp')

            if timestamp < time.time() - 3600:  # 1 hour
                return HttpResponseGone('Message has expired')

            sig_hmac = get_signature(data, timestamp)
            if sig_hmac != signature:
                return HttpResponseForbidden('Invalid signature')
        else:
            return HttpResponse('Unauthorized', status_code=401)
    else:
        data = request.POST.get('data')
        if not data:
            return HttpResponseBadRequest('Missing data')

        format = request.POST.get('format', 'pickle')

        if format not in ('pickle', 'json'):
            return HttpResponseBadRequest('Invalid format')

        # Legacy request (deprecated as of 2.0)
        key = request.POST.get('key')

        if key != settings.KEY:
            warnings.warn(
                'A client is sending the `key` parameter, which will be removed in Sentry 2.0',
                DeprecationWarning)
            return HttpResponseForbidden('Invalid credentials')

    logger = logging.getLogger('sentry.server')

    try:
        try:
            data = base64.b64decode(data).decode('zlib')
        except zlib.error:
            data = base64.b64decode(data)
    except Exception, e:
        # This error should be caught as it suggests that there's a
        # bug somewhere in the client's code.
        logger.exception('Bad data received')
        return HttpResponseForbidden('Bad data decoding request (%s, %s)' %
                                     (e.__class__.__name__, e))