def generate_payload(self, default_payload, config, context): """ Generate payload by checking Django request object. :param context: current context. :param config: honeybadger configuration. :return: a dict with the generated payload. """ request = current_request() request_payload = { 'url': request.build_absolute_uri(), 'component': request.resolver_match.app_name, 'action': request.resolver_match.func.__name__, 'params': {}, 'session': {}, 'cgi_data': filter_dict(request.META, config.params_filters), 'context': context } if hasattr(request, 'session'): request_payload['session'] = filter_dict(dict(request.session), config.params_filters) if hasattr(request, 'COOKIES'): request_payload['cgi_data']['HTTP_COOKIE'] = filter_dict(request.COOKIES, config.params_filters) if request.method == 'GET': request_payload['params'] = filter_dict(dict(request.GET), config.params_filters) else: request_payload['params'] = filter_dict(dict(request.POST), config.params_filters) default_payload['request'].update(request_payload) return default_payload
def generate_payload(self, config, context): """ Generate payload by checking Django request object. :param context: current context. :param config: honeybadger configuration. :return: a dict with the generated payload. """ request = current_request() payload = { 'url': request.build_absolute_uri(), 'component': request.resolver_match.app_name, 'action': request.resolver_match.func.__name__, 'params': {}, 'session': {}, 'cgi_data': dict(request.META), 'context': context } if hasattr(request, 'session'): payload['session'] = filter_dict(dict(request.session), config.params_filters) payload['params'] = filter_dict(dict(getattr(request, request.method)), config.params_filters) return payload
def _wrapper(request, context, config): current_view = current_app.view_functions[_request.endpoint] if hasattr(current_view, 'view_class'): component = '.'.join((current_view.__module__, current_view.view_class.__name__)) else: component = current_view.__module__ payload = { 'url': _request.base_url, 'component': component, 'action': _request.endpoint, 'params': {}, 'session': filter_dict(dict(session), config.params_filters), 'cgi_data': { k: v for k, v in iteritems(_request.headers) if k not in self.skip_headers }, 'context': context } # Add query params params = filter_dict(dict(_request.args), config.params_filters) params.update(filter_dict(dict(_request.form), config.params_filters)) payload['params'] = params return payload
def generate_payload(self, default_payload, config, context): """ Generate payload by checking the lambda's request event """ request_payload = { "params": { "event": current_event() }, "context": context } default_payload["request"].update( filter_dict(request_payload, config.params_filters)) AWS_ENV_MAP = (("_HANDLER", "handler"), ("AWS_REGION", "region"), ("AWS_EXECUTION_ENV", "runtime"), ("AWS_LAMBDA_FUNCTION_NAME", "function"), ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE", "memory"), ("AWS_LAMBDA_FUNCTION_VERSION", "version"), ("AWS_LAMBDA_LOG_GROUP_NAME", "log_group"), ("AWS_LAMBDA_LOG_STREAM_NAME", "log_name")) lambda_details = { detail[1]: os.environ.get(detail[0], None) for detail in AWS_ENV_MAP } default_payload["details"] = {} default_payload["details"]["Lambda Details"] = lambda_details default_payload["request"]["component"] = lambda_details["function"] default_payload["request"]["action"] = lambda_details["handler"] trace_id = os.environ.get("_X_AMZN_TRACE_ID", None) if trace_id: default_payload["request"]["context"]["lambda_trace_id"] = trace_id return default_payload
def generate_payload(self, default_payload, config, context): """ Generate payload by checking Flask request object. :param context: current context. :param config: honeybadger configuration. :return: a dict with the generated payload. """ from flask import current_app, session, request as _request current_view = current_app.view_functions[_request.endpoint] if hasattr(current_view, 'view_class'): component = '.'.join( (current_view.__module__, current_view.view_class.__name__)) else: component = current_view.__module__ cgi_data = {k: v for k, v in iteritems(_request.headers)} cgi_data.update({ 'REQUEST_METHOD': _request.method, 'HTTP_COOKIE': dict(_request.cookies) }) payload = { 'url': _request.base_url, 'component': component, 'action': _request.endpoint, 'params': {}, 'session': filter_dict(dict(session), config.params_filters), 'cgi_data': filter_dict(cgi_data, config.params_filters), 'context': context } # Add query params params = filter_dict(_request.args.to_dict(flat=False), config.params_filters) params.update( filter_dict(_request.form.to_dict(flat=False), config.params_filters)) payload['params'] = params default_payload['request'].update(payload) return default_payload
def test_filter_dict_with_nested_dict(): data = {'foo': 'bar', 'bar': 'baz', 'nested': {'password': '******'}} expected = { 'foo': 'bar', 'bar': 'baz', 'nested': { 'password': '******' } } filter_keys = ['password'] assert filter_dict(data, filter_keys) == expected
def generate_payload(self, config, context): """ Generate payload by checking Flask request object. :param context: current context. :param config: honeybadger configuration. :return: a dict with the generated payload. """ from flask import current_app, session, request as _request current_view = current_app.view_functions[_request.endpoint] if hasattr(current_view, 'view_class'): component = '.'.join((current_view.__module__, current_view.view_class.__name__)) else: component = current_view.__module__ cgi_data = { k: v for k, v in iteritems(_request.headers) } cgi_data.update({ 'REQUEST_METHOD': _request.method }) payload = { 'url': _request.base_url, 'component': component, 'action': _request.endpoint, 'params': {}, 'session': filter_dict(dict(session), config.params_filters), 'cgi_data': cgi_data, 'context': context } # Add query params params = filter_dict(dict(_request.args), config.params_filters) params.update(filter_dict(dict(_request.form), config.params_filters)) payload['params'] = params return payload
def f_wrapped(*args, **kw): try: ret = f(*args, **kw) except Exception as e: hb.notify( e, context={ 'func': f.__name__, 'args': args, 'kwargs': filter_dict(kw, settings.HB_PARAM_FILTERS) } ) raise e return ret
def _as_context(scope: dict) -> dict: ctx = {} if scope.get("type") in ("http", "websocket"): ctx["method"] = scope.get("method") ctx["headers"] = headers = _get_headers(scope) ctx["query_string"] = _get_query(scope) ctx["url"] = _get_url(scope, "http" if scope["type"] == "http" else "ws", headers.get("host")) body = _get_body(scope) if body is not None: ctx["body"] = body ctx["client"] = scope.get( "client") # pii info can be filtered from hb config. # TODO: should we look at "endpoint"? return utils.filter_dict(ctx, honeybadger.config.params_filters)
def generate_payload(self, default_payload, config, context): return utils.filter_dict(default_payload, honeybadger.config.params_filters)
def test_filter_dict(): data = {'foo': 'bar', 'bar': 'baz'} expected = {'foo': '[FILTERED]', 'bar': 'baz'} filter_keys = ['foo'] assert filter_dict(data, filter_keys) == expected