def anonymize_user(doc):
"""Preprocess an event by anonymizing user information."""
ip = doc.pop('ip_address', None)
if ip:
doc.update(get_geoip(ip))
uid = doc.pop('user_id', '')
ua = doc.pop('user_agent', '')
m = hashlib.sha224()
# TODO: include random salt here, that changes once a day.
# m.update(random_salt)
if uid:
m.update(uid.encode('utf-8'))
elif ua:
m.update(ua.encode('utf-8'))
else:
# TODO: add random data?
pass
doc.update(dict(
visitor_id=m.hexdigest()
))
return doc
评论列表
文章目录