1
# Copyright (c) 2012, Canonical Ltd
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Lesser General Public License as published by
5
# the Free Software Foundation, version 3 only.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU Lesser General Public License for more details.
12
# You should have received a copy of the GNU Lesser General Public License
13
# along with this program. If not, see <http://www.gnu.org/licenses/>.
14
# GNU Lesser General Public License version 3 (see the file LICENSE).
17
SESSION_TABLE_NAME = 'django_session'
18
USER_TABLE_NAME = 'auth_user'
21
def _filter_table(query, table, reason):
23
return query.split(" ", 1)[0] + " <%s query redacted>" % reason
27
def filter_session_info(query):
28
return _filter_table(query, SESSION_TABLE_NAME, 'session')
31
def filter_user_info(query):
32
return _filter_table(query, USER_TABLE_NAME, 'user')
35
def _filter_query(report, filter_fn):
36
timeline = report.get('timeline')
40
for event in timeline:
41
start, end, category, detail = event[:4]
42
detail = filter_fn(detail)
43
new_timeline.append((start, end, category, detail) + event[4:])
44
report['timeline'] = new_timeline
47
def filter_session_query(report, context):
48
"""Filter out queries about the session from the timeline."""
49
_filter_query(report, filter_session_info)
52
def filter_user_query(report, context):
53
"""Filter out queries about the user from the timeline."""
54
_filter_query(report, filter_user_info)
57
def install_hooks(config):
58
"""Install on_create hooks in the config to sanitise queries.
60
This should be called after the `oops_timeline` hooks are instaled.
62
:param config: the `oops.Config` to install the hooks in to.
64
config.on_create.append(filter_session_query)
65
config.on_create.append(filter_user_query)