Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions instana/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
try:
from urllib import parse
except ImportError:
from urlparse import urlparse as parse
import urlparse as parse
import urllib

from .log import logger


Expand Down Expand Up @@ -123,38 +125,42 @@ def strip_secrets(qp, matcher, kwlist):
else:
query = qp

params = parse.parse_qs(query, keep_blank_values=True)
params = parse.parse_qsl(query, keep_blank_values=True)
redacted = ['<redacted>']

if matcher == 'equals-ignore-case':
for keyword in kwlist:
for key in params.keys():
if key.lower() == keyword.lower():
params[key] = redacted
for index, kv in enumerate(params):
if kv[0].lower() == keyword.lower():
params[index] = (kv[0], redacted)
elif matcher == 'equals':
for keyword in kwlist:
if keyword in params:
params[keyword] = redacted
for index, kv in enumerate(params):
if kv[0] == keyword:
params[index] = (kv[0], redacted)
elif matcher == 'contains-ignore-case':
for keyword in kwlist:
for key in params.keys():
if keyword.lower() in key.lower():
params[key] = redacted
for index, kv in enumerate(params):
if keyword.lower() in kv[0].lower():
params[index] = (kv[0], redacted)
elif matcher == 'contains':
for keyword in kwlist:
for key in params.keys():
if keyword in key:
params[key] = redacted
for index, kv in enumerate(params):
if keyword in kv[0]:
params[index] = (kv[0], redacted)
elif matcher == 'regex':
for regexp in kwlist:
for key in params.keys():
if re.match(regexp, key):
params[key] = redacted
for index, kv in enumerate(params):
if re.match(regexp, kv[0]):
params[index] = (kv[0], redacted)
else:
logger.debug("strip_secrets: unknown matcher")
return qp

result = parse.urlencode(params, doseq=True)
if sys.version_info < (3, 0):
result = urllib.urlencode(params, doseq=True)
else:
result = parse.urlencode(params, doseq=True)
query = parse.unquote(result)

if path:
Expand Down
9 changes: 3 additions & 6 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import nose
from distutils.version import LooseVersion

command_line = ['-v']
command_line = [__file__, '--verbose']

if (LooseVersion(sys.version) < LooseVersion('3.5')):
command_line.extend(['-e', 'asynqp'])

print("Nose arguments: %s" % command_line)
result = nose.run(argv=command_line)
result = nose.main(argv=command_line)

if result is True:
exit(0)
else:
exit(-1)
exit(result)