Merge lp:~nataliabidart/ubuntuone-client/careful-logging into lp:ubuntuone-client

Proposed by Natalia Bidart on 2011-08-30
Status: Merged
Approved by: Roberto Alsina on 2011-08-30
Approved revision: 1119
Merged at revision: 1120
Proposed branch: lp:~nataliabidart/ubuntuone-client/careful-logging
Merge into: lp:ubuntuone-client
Diff against target: 92 lines (+25/-8)
2 files modified
ubuntuone/logger.py (+15/-3)
ubuntuone/platform/credentials/__init__.py (+10/-5)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/careful-logging
Reviewer Review Type Date Requested Status
Roberto Alsina (community) 2011-08-30 Approve on 2011-08-30
Review via email: mp+73407@code.launchpad.net

Commit message

- Do not log sensible data in CredentialsMangementTool (LP: #837488).

To post a comment you must log in.
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/logger.py'
2--- ubuntuone/logger.py 2011-08-17 12:41:58 +0000
3+++ ubuntuone/logger.py 2011-08-30 16:22:23 +0000
4@@ -240,9 +240,11 @@
5 return True
6
7
8-def log_call(log_func):
9+def log_call(log_func, with_args=True, with_result=True):
10 """Decorator to add a log entry using 'log_func'.
11
12+ If not 'with_args', do not log arguments. Same apply to 'with_result'.
13+
14 An example of use would be:
15
16 @log_call(logger.debug)
17@@ -257,9 +259,19 @@
18 @functools.wraps(f)
19 def inner(*args, **kwargs):
20 """Call f(*args, **kwargs)."""
21- log_func('%s: args %r, kwargs %r.', f.__name__, args, kwargs)
22+ if with_args:
23+ a, kw = args, kwargs
24+ else:
25+ a, kw = '<hidden args>', '<hidden kwargs>'
26+ log_func('%s: args %r, kwargs %r.', f.__name__, a, kw)
27+
28 res = f(*args, **kwargs)
29- log_func('%s: result %r.', f.__name__, res)
30+
31+ if with_result:
32+ log_func('%s: result %r.', f.__name__, res)
33+ else:
34+ log_func('%s: result %r.', f.__name__, '<hidden result>')
35+
36 return res
37
38 return inner
39
40=== modified file 'ubuntuone/platform/credentials/__init__.py'
41--- ubuntuone/platform/credentials/__init__.py 2011-08-25 12:25:02 +0000
42+++ ubuntuone/platform/credentials/__init__.py 2011-08-30 16:22:23 +0000
43@@ -122,7 +122,8 @@
44 self._proxy = yield source.get_creds_proxy()
45 defer.returnValue(self._proxy)
46
47- @log_call(logger.debug)
48+ # do not log returned credentials
49+ @log_call(logger.debug, with_result=False)
50 @defer.inlineCallbacks
51 def find_credentials(self):
52 """Find credentials for Ubuntu One.
53@@ -199,7 +200,8 @@
54
55 yield d
56
57- @log_call(logger.debug)
58+ # do not log token
59+ @log_call(logger.debug, with_args=False)
60 @defer.inlineCallbacks
61 def store_credentials(self, token):
62 """Store credentials for Ubuntu One.
63@@ -234,7 +236,8 @@
64
65 yield d
66
67- @log_call(logger.debug)
68+ # do not log returned credentials
69+ @log_call(logger.debug, with_result=False)
70 @defer.inlineCallbacks
71 def register(self, window_id=0):
72 """Register to Ubuntu One.
73@@ -281,7 +284,8 @@
74 result = yield d
75 defer.returnValue(result)
76
77- @log_call(logger.debug)
78+ # do not log returned credentials
79+ @log_call(logger.debug, with_result=False)
80 @defer.inlineCallbacks
81 def login(self, window_id=0):
82 """Login to Ubuntu One.
83@@ -329,7 +333,8 @@
84 result = yield d
85 defer.returnValue(result)
86
87- @log_call(logger.debug)
88+ # do not log password nor returned credentials
89+ @log_call(logger.debug, with_args=False, with_result=False)
90 @defer.inlineCallbacks
91 def login_email_password(self, email, password):
92 """Login to Ubuntu One.

Subscribers

People subscribed via source and target branches