Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: anonymized.py

Issue 29817563: #12025 - Add city information to anonymized.py (Closed)
Left Patch Set: Created June 27, 2018, 1:23 p.m.
Right Patch Set: #12025 - Add city information to anonymized.py Created July 2, 2018, 2:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 """Anonymize data in access log lines. 2 """Anonymize data in access log lines.
3 3
4 Read a line from stdin, write it to stdout with the following changes: 4 Read a line from stdin, write it to stdout with the following changes:
5 1. IP (v4 or v6) replaced with a salted hash of the IP and the date 5 1. IP (v4 or v6) replaced with a salted hash of the IP and the date
6 2. Country and city information (extracted from IP) added after the salted hash. 6 2. Country and city information (extracted from IP) added after the salted hash.
7 7
8 If the country or city information is unavailable in the database, '-' is added instead 8 If the country or city information is unavailable in the database,
9 of ISO 3166-1 alpha-2 country/city code (like 'DE'). 9 '-' is added instead of ISO 3166-1 alpha-2 country code (like DE) &
10 city name (like 'Berlin').
10 11
11 Salt and the country/city information database are taken as command line options and 12 Salt and the country/city information database are taken
12 default to environment variables. 13 as command line options and default to environment variables.
13 14
14 Malformed lines are passed on as is, based on the assumption that they don't 15 Malformed lines are passed on as is, based on the assumption that they don't
15 contain sensitive information. Malformed here means the line couldn't be split 16 contain sensitive information. Malformed here means the line couldn't be split
16 on space character. If it could be split, and an error occurs afterwards 17 on space character. If it could be split, and an error occurs afterwards
17 (e.g. while trying to parse out the date), the script will fail and exit in 18 (e.g. while trying to parse out the date), the script will fail and exit in
18 order to bring attention to the fact that something might not be getting 19 order to bring attention to the fact that something might not be getting
19 anonymized. 20 anonymized.
20 """ 21 """
21 22
22 from __future__ import print_function 23 from __future__ import print_function
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 ) 105 )
105 106
106 args = parser.parse_args() 107 args = parser.parse_args()
107 108
108 if args.salt is None or args.country_db is None or args.city_db is None: 109 if args.salt is None or args.country_db is None or args.city_db is None:
109 parser.print_help() 110 parser.print_help()
110 sys.exit(1) 111 sys.exit(1)
111 112
112 main(args.salt, args.country_db, args.city_db) 113 main(args.salt, args.country_db, args.city_db)
113 114
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld