Merge lp:~mandel/ubuntuone-client/provide_credentials_management into lp:ubuntuone-client
- provide_credentials_management
- Merge into trunk
Proposed by
Manuel de la Peña
Status: | Merged |
---|---|
Approved by: | Roberto Alsina |
Approved revision: | 995 |
Merged at revision: | 984 |
Proposed branch: | lp:~mandel/ubuntuone-client/provide_credentials_management |
Merge into: | lp:ubuntuone-client |
Prerequisite: | lp:~mandel/ubuntuone-client/pass_main_to_ipc_root |
Diff against target: |
1019 lines (+702/-230) 8 files modified
po/POTFILES.in (+1/-0) tests/platform/linux/test_credentials.py (+4/-5) tests/platform/windows/test_credentials.py (+155/-0) tests/test_credentials.py (+99/-0) ubuntuone/credentials.py (+255/-0) ubuntuone/platform/linux/__init__.py (+1/-1) ubuntuone/platform/linux/credentials.py (+56/-224) ubuntuone/platform/windows/credentials.py (+131/-0) |
To merge this branch: | bzr merge lp:~mandel/ubuntuone-client/provide_credentials_management |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Shane Fagan (community) | Approve | ||
Review via email: mp+59743@code.launchpad.net |
Commit message
This branch fixed the issue where windows does not have credential management code. This branch does the following:
* Refactor the CredentialsMana
* Implemented the CredentialsMana
Description of the change
This branch fixed the issue where windows does not have credential management code. This branch does the following:
* Refactor the CredentialsMana
* Implemented the CredentialsMana
This branch might break control panel (to be confirmed) and has to be tested in both platforms (windows/linux)
On Linux:
$ ./autogen
$ make check
On Windows:
python C:\Python27\
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'po/POTFILES.in' | |||
2 | --- po/POTFILES.in 2011-02-21 23:16:03 +0000 | |||
3 | +++ po/POTFILES.in 2011-05-03 09:17:06 +0000 | |||
4 | @@ -1,6 +1,7 @@ | |||
5 | 1 | ubuntuone/clientdefs.py.in | 1 | ubuntuone/clientdefs.py.in |
6 | 2 | ubuntuone/status/aggregator.py | 2 | ubuntuone/status/aggregator.py |
7 | 3 | ubuntuone/platform/linux/credentials.py | 3 | ubuntuone/platform/linux/credentials.py |
8 | 4 | ubuntuone/platform/windows/credentials.py | ||
9 | 4 | data/emblem-ubuntuone-downloading.icon.in | 5 | data/emblem-ubuntuone-downloading.icon.in |
10 | 5 | data/emblem-ubuntuone-unsynchronized.icon.in | 6 | data/emblem-ubuntuone-unsynchronized.icon.in |
11 | 6 | data/emblem-ubuntuone-uploading.icon.in | 7 | data/emblem-ubuntuone-uploading.icon.in |
12 | 7 | 8 | ||
13 | === modified file 'tests/platform/linux/test_credentials.py' | |||
14 | --- tests/platform/linux/test_credentials.py 2011-02-15 20:32:42 +0000 | |||
15 | +++ tests/platform/linux/test_credentials.py 2011-05-03 09:17:06 +0000 | |||
16 | @@ -25,12 +25,11 @@ | |||
17 | 25 | from ubuntuone.devtools.handlers import MementoHandler | 25 | from ubuntuone.devtools.handlers import MementoHandler |
18 | 26 | 26 | ||
19 | 27 | from ubuntuone.platform.linux.credentials import (dbus, logger, logging, | 27 | from ubuntuone.platform.linux.credentials import (dbus, logger, logging, |
25 | 28 | CredentialsManagement, CredentialsManagementTool, CredentialsError, | 28 | CredentialsManagement, ubuntu_sso, DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH, |
26 | 29 | ubuntu_sso, | 29 | DBUS_CREDENTIALS_IFACE, APP_NAME, HELP_TEXT_KEY, DESCRIPTION, |
27 | 30 | DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH, DBUS_CREDENTIALS_IFACE, | 30 | TC_URL_KEY, TC_URL, PING_URL_KEY, PING_URL, TIMEOUT_INTERVAL, |
23 | 31 | APP_NAME, HELP_TEXT_KEY, DESCRIPTION, TC_URL_KEY, TC_URL, | ||
24 | 32 | PING_URL_KEY, PING_URL, TIMEOUT_INTERVAL, | ||
28 | 33 | ) | 31 | ) |
29 | 32 | from ubuntuone.credentials import CredentialsManagementTool, CredentialsError | ||
30 | 34 | 33 | ||
31 | 35 | FAKED_CREDENTIALS = { | 34 | FAKED_CREDENTIALS = { |
32 | 36 | 'consumer_key': 'faked_consumer_key', | 35 | 'consumer_key': 'faked_consumer_key', |
33 | 37 | 36 | ||
34 | === added file 'tests/platform/windows/test_credentials.py' | |||
35 | --- tests/platform/windows/test_credentials.py 1970-01-01 00:00:00 +0000 | |||
36 | +++ tests/platform/windows/test_credentials.py 2011-05-03 09:17:06 +0000 | |||
37 | @@ -0,0 +1,155 @@ | |||
38 | 1 | #!/usr/bin/env python | ||
39 | 2 | # -*- coding: utf-8 -*- | ||
40 | 3 | # Author: Manuel de la Pena <manuel@canonical.com> | ||
41 | 4 | # | ||
42 | 5 | # Copyright 2011 Canonical Ltd. | ||
43 | 6 | # | ||
44 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
45 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
46 | 9 | # by the Free Software Foundation. | ||
47 | 10 | # | ||
48 | 11 | # This program is distributed in the hope that it will be useful, but | ||
49 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
50 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
51 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
52 | 15 | # | ||
53 | 16 | # You should have received a copy of the GNU General Public License along | ||
54 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
55 | 18 | """Tests for the credentials management on Windows.""" | ||
56 | 19 | |||
57 | 20 | from mocker import MockerTestCase | ||
58 | 21 | |||
59 | 22 | from ubuntu_sso.credentials import HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY | ||
60 | 23 | from ubuntuone.platform.windows.credentials import ( | ||
61 | 24 | CredentialsManagement, | ||
62 | 25 | APP_NAME, | ||
63 | 26 | DESCRIPTION, | ||
64 | 27 | PING_URL, | ||
65 | 28 | TC_URL) | ||
66 | 29 | |||
67 | 30 | |||
68 | 31 | class TestCredentialsManagement(MockerTestCase): | ||
69 | 32 | """Test that the credentials management is correctly used.""" | ||
70 | 33 | |||
71 | 34 | def setUp(self): | ||
72 | 35 | """Set the different tests.""" | ||
73 | 36 | super(TestCredentialsManagement, self).setUp() | ||
74 | 37 | self.proxy = self.mocker.mock() | ||
75 | 38 | self.management = CredentialsManagement(self.proxy) | ||
76 | 39 | |||
77 | 40 | def test_find_credentials(self): | ||
78 | 41 | """Ensure we do ask corectly for the credentials.""" | ||
79 | 42 | reply_handler = lambda: None | ||
80 | 43 | error_handler = lambda: None | ||
81 | 44 | self.proxy.find_credentials(APP_NAME, {}, reply_handler=reply_handler, | ||
82 | 45 | error_handler=error_handler) | ||
83 | 46 | self.mocker.replay() | ||
84 | 47 | self.management.find_credentials(reply_handler=reply_handler, | ||
85 | 48 | error_handler=error_handler) | ||
86 | 49 | |||
87 | 50 | def test_clear_credentials(self): | ||
88 | 51 | """Ensure we do clear the credentials.""" | ||
89 | 52 | reply_handler = lambda: None | ||
90 | 53 | error_handler = lambda: None | ||
91 | 54 | self.proxy.clear_credentials(APP_NAME, {}, reply_handler=reply_handler, | ||
92 | 55 | error_handler=error_handler) | ||
93 | 56 | self.mocker.replay() | ||
94 | 57 | self.management.clear_credentials(reply_handler=reply_handler, | ||
95 | 58 | error_handler=error_handler) | ||
96 | 59 | |||
97 | 60 | def test_store_credentials(self): | ||
98 | 61 | """Store the token for Ubuntu One application.""" | ||
99 | 62 | credentials = 'creds' | ||
100 | 63 | reply_handler = lambda: None | ||
101 | 64 | error_handler = lambda: None | ||
102 | 65 | self.proxy.store_credentials(APP_NAME, credentials, | ||
103 | 66 | reply_handler=reply_handler, error_handler=error_handler) | ||
104 | 67 | self.mocker.replay() | ||
105 | 68 | self.management.store_credentials(credentials, | ||
106 | 69 | reply_handler=reply_handler, error_handler=error_handler) | ||
107 | 70 | |||
108 | 71 | def test_register(self): | ||
109 | 72 | """Get credentials if found else prompt to register to Ubuntu One.""" | ||
110 | 73 | reply_handler = lambda: None | ||
111 | 74 | error_handler = lambda: None | ||
112 | 75 | args = dict(test='test', args='args') | ||
113 | 76 | extra_params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL, | ||
114 | 77 | PING_URL_KEY: PING_URL} | ||
115 | 78 | extra_params.update(args) | ||
116 | 79 | self.proxy.register(APP_NAME, extra_params, | ||
117 | 80 | reply_handler=reply_handler, error_handler=error_handler) | ||
118 | 81 | self.mocker.replay() | ||
119 | 82 | self.management.register(args, reply_handler, error_handler) | ||
120 | 83 | |||
121 | 84 | def test_login(self): | ||
122 | 85 | """Get credentials if found else prompt to login to Ubuntu One.""" | ||
123 | 86 | reply_handler = lambda: None | ||
124 | 87 | error_handler = lambda: None | ||
125 | 88 | args = dict(test='test', args='args') | ||
126 | 89 | extra_params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL, | ||
127 | 90 | PING_URL_KEY: PING_URL} | ||
128 | 91 | extra_params.update(args) | ||
129 | 92 | self.proxy.login(APP_NAME, extra_params, | ||
130 | 93 | reply_handler=reply_handler, error_handler=error_handler) | ||
131 | 94 | self.mocker.replay() | ||
132 | 95 | self.management.login(args, reply_handler, error_handler) | ||
133 | 96 | |||
134 | 97 | def test_register_to_credentials_stored(self): | ||
135 | 98 | """Register to the CredentialsStored dbus signal.""" | ||
136 | 99 | callback = lambda: None | ||
137 | 100 | self.proxy.on_credentials_stored_cb = callback | ||
138 | 101 | self.proxy.on_credentials_stored_cb | ||
139 | 102 | self.mocker.result(callback) | ||
140 | 103 | self.mocker.replay() | ||
141 | 104 | self.assertIs(callback, | ||
142 | 105 | self.management.register_to_credentials_stored(callback)) | ||
143 | 106 | |||
144 | 107 | def test_register_to_credentials_cleared(self): | ||
145 | 108 | """Register to the CredentialsCleared dbus signal.""" | ||
146 | 109 | callback = lambda: None | ||
147 | 110 | self.proxy.on_credentials_cleared_cb = callback | ||
148 | 111 | self.proxy.on_credentials_cleared_cb | ||
149 | 112 | self.mocker.result(callback) | ||
150 | 113 | self.mocker.replay() | ||
151 | 114 | self.assertIs(callback, | ||
152 | 115 | self.management.register_to_credentials_cleared(callback)) | ||
153 | 116 | |||
154 | 117 | def test_register_to_credentials_found(self): | ||
155 | 118 | """Register to the CredentialsFound dbus signal.""" | ||
156 | 119 | callback = lambda: None | ||
157 | 120 | self.proxy.on_credentials_found_cb = callback | ||
158 | 121 | self.proxy.on_credentials_found_cb | ||
159 | 122 | self.mocker.result(callback) | ||
160 | 123 | self.mocker.replay() | ||
161 | 124 | self.assertIs(callback, | ||
162 | 125 | self.management.register_to_credentials_found(callback)) | ||
163 | 126 | |||
164 | 127 | def test_register_to_credentials_not_found(self): | ||
165 | 128 | """Register to the CredentialsFound dbus signal.""" | ||
166 | 129 | callback = lambda: None | ||
167 | 130 | self.proxy.on_credentials_not_found_cb = callback | ||
168 | 131 | self.proxy.on_credentials_not_found_cb | ||
169 | 132 | self.mocker.result(callback) | ||
170 | 133 | self.mocker.replay() | ||
171 | 134 | self.assertIs(callback, | ||
172 | 135 | self.management.register_to_credentials_not_found(callback)) | ||
173 | 136 | |||
174 | 137 | def test_register_to_authorization_denied(self): | ||
175 | 138 | """Register to the AuthorizationDenied dbus signal.""" | ||
176 | 139 | callback = lambda: None | ||
177 | 140 | self.proxy.on_authorization_denied_cb = callback | ||
178 | 141 | self.proxy.on_authorization_denied_cb | ||
179 | 142 | self.mocker.result(callback) | ||
180 | 143 | self.mocker.replay() | ||
181 | 144 | self.assertIs(callback, | ||
182 | 145 | self.management.register_to_authorization_denied(callback)) | ||
183 | 146 | |||
184 | 147 | def test_register_to_credentials_error(self): | ||
185 | 148 | """Register to the CredentialsError dbus signal.""" | ||
186 | 149 | callback = lambda: None | ||
187 | 150 | self.proxy.on_credentials_error_cb = callback | ||
188 | 151 | self.proxy.on_credentials_error_cb | ||
189 | 152 | self.mocker.result(callback) | ||
190 | 153 | self.mocker.replay() | ||
191 | 154 | self.assertIs(callback, | ||
192 | 155 | self.management.register_to_credentials_error(callback)) | ||
193 | 0 | 156 | ||
194 | === added file 'tests/test_credentials.py' | |||
195 | --- tests/test_credentials.py 1970-01-01 00:00:00 +0000 | |||
196 | +++ tests/test_credentials.py 2011-05-03 09:17:06 +0000 | |||
197 | @@ -0,0 +1,99 @@ | |||
198 | 1 | #!/usr/bin/env python | ||
199 | 2 | # -*- coding: utf-8 -*- | ||
200 | 3 | # | ||
201 | 4 | # Author: Manuel de la Pena<manuel@canonical.com> | ||
202 | 5 | # | ||
203 | 6 | # Copyright 2011 Canonical Ltd. | ||
204 | 7 | # | ||
205 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
206 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
207 | 10 | # by the Free Software Foundation. | ||
208 | 11 | # | ||
209 | 12 | # This program is distributed in the hope that it will be useful, but | ||
210 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
211 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
212 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
213 | 16 | # | ||
214 | 17 | # You should have received a copy of the GNU General Public License along | ||
215 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
216 | 19 | """Platform independent tests for the credentials management.""" | ||
217 | 20 | |||
218 | 21 | from mocker import MockerTestCase, MATCH | ||
219 | 22 | |||
220 | 23 | from ubuntuone.credentials import CredentialsManagementTool | ||
221 | 24 | |||
222 | 25 | |||
223 | 26 | class TestCredentialsManagementTool(MockerTestCase): | ||
224 | 27 | """Test the crendentials management tool mocking the proxy.""" | ||
225 | 28 | |||
226 | 29 | def setUp(self): | ||
227 | 30 | """Set the diff tests.""" | ||
228 | 31 | super(TestCredentialsManagementTool, self).setUp() | ||
229 | 32 | self.get_cred_proxy = self.mocker.replace( | ||
230 | 33 | 'ubuntuone.platform.get_creds_proxy') | ||
231 | 34 | self.proxy = self.mocker.mock() | ||
232 | 35 | self.management_tool = CredentialsManagementTool() | ||
233 | 36 | |||
234 | 37 | def test_find_credentials(self): | ||
235 | 38 | """Test that we do ask for the credentials correctly.""" | ||
236 | 39 | signals = ['creds_found', 'creds_not_found', 'creds_erro'] | ||
237 | 40 | self.get_cred_proxy() | ||
238 | 41 | self.mocker.result(self.proxy) | ||
239 | 42 | self.proxy.register_to_credentials_found(MATCH(callable)) | ||
240 | 43 | self.mocker.result(signals[0]) | ||
241 | 44 | self.proxy.register_to_credentials_not_found(MATCH(callable)) | ||
242 | 45 | self.mocker.result(signals[1]) | ||
243 | 46 | self.proxy.register_to_credentials_error(MATCH(callable)) | ||
244 | 47 | self.mocker.result(signals[2]) | ||
245 | 48 | self.proxy.find_credentials(reply_handler=MATCH(callable), | ||
246 | 49 | error_handler=MATCH(callable)) | ||
247 | 50 | self.mocker.replay() | ||
248 | 51 | return self.management_tool.find_credentials() | ||
249 | 52 | |||
250 | 53 | def test_clear_credentials(self): | ||
251 | 54 | """Test that we clear the credentials correctly.""" | ||
252 | 55 | signals = ['creds_cleared', 'creds_error'] | ||
253 | 56 | self.get_cred_proxy() | ||
254 | 57 | self.mocker.result(self.proxy) | ||
255 | 58 | self.proxy.register_to_credentials_cleared(MATCH(callable)) | ||
256 | 59 | self.mocker.result(signals[0]) | ||
257 | 60 | self.proxy.register_to_credentials_error(MATCH(callable)) | ||
258 | 61 | self.mocker.result(signals[1]) | ||
259 | 62 | self.proxy.clear_credentials(reply_handler=MATCH(callable), | ||
260 | 63 | error_handler=MATCH(callable)) | ||
261 | 64 | self.mocker.replay() | ||
262 | 65 | return self.management_tool.clear_credentials() | ||
263 | 66 | |||
264 | 67 | def test_store_credentials(self): | ||
265 | 68 | """Test that we store the credentials correctly.""" | ||
266 | 69 | token = 'token' | ||
267 | 70 | signals = ['creds_stored','creds_error'] | ||
268 | 71 | self.get_cred_proxy() | ||
269 | 72 | self.mocker.result(self.proxy) | ||
270 | 73 | self.proxy.register_to_credentials_stored(MATCH(callable)) | ||
271 | 74 | self.mocker.result(signals[0]) | ||
272 | 75 | self.proxy.register_to_credentials_error(MATCH(callable)) | ||
273 | 76 | self.mocker.result(signals[1]) | ||
274 | 77 | self.proxy.store_credentials(token, reply_handler=MATCH(callable), | ||
275 | 78 | error_handler=MATCH(callable)) | ||
276 | 79 | self.mocker.replay() | ||
277 | 80 | return self.management_tool.store_credentials(token) | ||
278 | 81 | |||
279 | 82 | def test_register(self): | ||
280 | 83 | """Test that we correctly register.""" | ||
281 | 84 | window_id = 10 | ||
282 | 85 | window_id_dict = dict(window_id=str(window_id)) | ||
283 | 86 | signals = ['creds_found', 'creds_denied', 'creds_error'] | ||
284 | 87 | self.get_cred_proxy() | ||
285 | 88 | self.mocker.result(self.proxy) | ||
286 | 89 | self.proxy.register_to_credentials_found(MATCH(callable)) | ||
287 | 90 | self.mocker.result(signals[0]) | ||
288 | 91 | self.proxy.register_to_authorization_denied(MATCH(callable)) | ||
289 | 92 | self.mocker.result(signals[1]) | ||
290 | 93 | self.proxy.register_to_credentials_error(MATCH(callable)) | ||
291 | 94 | self.mocker.result(signals[2]) | ||
292 | 95 | self.proxy.register(window_id_dict, reply_handler=MATCH(callable), | ||
293 | 96 | error_handler=MATCH(callable)) | ||
294 | 97 | self.mocker.replay() | ||
295 | 98 | return self.management_tool.register(window_id=window_id) | ||
296 | 99 | |||
297 | 0 | 100 | ||
298 | === added file 'ubuntuone/credentials.py' | |||
299 | --- ubuntuone/credentials.py 1970-01-01 00:00:00 +0000 | |||
300 | +++ ubuntuone/credentials.py 2011-05-03 09:17:06 +0000 | |||
301 | @@ -0,0 +1,255 @@ | |||
302 | 1 | #!/usr/bin/env python | ||
303 | 2 | # -*- coding: utf-8 -*- | ||
304 | 3 | # | ||
305 | 4 | # Author: Natalia B. Bidart <natalia.bidart@canonical.com> | ||
306 | 5 | # Author: Manuel de la Pena<manuel@canonical.com> | ||
307 | 6 | # | ||
308 | 7 | # Copyright 2011 Canonical Ltd. | ||
309 | 8 | # | ||
310 | 9 | # This program is free software: you can redistribute it and/or modify it | ||
311 | 10 | # under the terms of the GNU General Public License version 3, as published | ||
312 | 11 | # by the Free Software Foundation. | ||
313 | 12 | # | ||
314 | 13 | # This program is distributed in the hope that it will be useful, but | ||
315 | 14 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
316 | 15 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
317 | 16 | # PURPOSE. See the GNU General Public License for more details. | ||
318 | 17 | # | ||
319 | 18 | # You should have received a copy of the GNU General Public License along | ||
320 | 19 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
321 | 20 | """Common code for the credentials management.""" | ||
322 | 21 | |||
323 | 22 | import os | ||
324 | 23 | |||
325 | 24 | from twisted.internet import defer | ||
326 | 25 | |||
327 | 26 | from ubuntuone.logger import (basic_formatter, logging, | ||
328 | 27 | CustomRotatingFileHandler, LOGFOLDER) | ||
329 | 28 | from ubuntuone.platform import get_creds_proxy | ||
330 | 29 | |||
331 | 30 | LOG_LEVEL = logging.DEBUG | ||
332 | 31 | path = os.path.join(LOGFOLDER, 'credentials.log') | ||
333 | 32 | MAIN_HANDLER = CustomRotatingFileHandler(path) | ||
334 | 33 | MAIN_HANDLER.setFormatter(basic_formatter) | ||
335 | 34 | MAIN_HANDLER.setLevel(LOG_LEVEL) | ||
336 | 35 | |||
337 | 36 | logger = logging.getLogger("ubuntuone.credentials") | ||
338 | 37 | logger.setLevel(LOG_LEVEL) | ||
339 | 38 | logger.addHandler(MAIN_HANDLER) | ||
340 | 39 | |||
341 | 40 | |||
342 | 41 | class CredentialsError(Exception): | ||
343 | 42 | """A general exception when hadling credentilas.""" | ||
344 | 43 | |||
345 | 44 | |||
346 | 45 | class CredentialsManagementTool(object): | ||
347 | 46 | """Wrapper to CredentialsManagement. | ||
348 | 47 | |||
349 | 48 | The goal of this class is to abstract the caller from calling the DBus | ||
350 | 49 | service implemented in the class CredentialsManagement. | ||
351 | 50 | |||
352 | 51 | """ | ||
353 | 52 | |||
354 | 53 | def __init__(self): | ||
355 | 54 | self._cleanup_signals = [] | ||
356 | 55 | |||
357 | 56 | def cleanup(self, _): | ||
358 | 57 | """Disconnect all the DBus signals.""" | ||
359 | 58 | for sig in self._cleanup_signals: | ||
360 | 59 | logger.debug('cleanup: removing signal match %r', sig) | ||
361 | 60 | sig.remove() | ||
362 | 61 | |||
363 | 62 | return _ | ||
364 | 63 | |||
365 | 64 | @defer.inlineCallbacks | ||
366 | 65 | def find_credentials(self): | ||
367 | 66 | """Find credentials for Ubuntu One. | ||
368 | 67 | |||
369 | 68 | Return a deferred that, when fired, will return the credentials for | ||
370 | 69 | Ubuntu One for the current logged in user. | ||
371 | 70 | |||
372 | 71 | The credentials is a dictionary with both string keys and values. The | ||
373 | 72 | dictionary may be either empty if there are no credentials for the | ||
374 | 73 | user, or will hold five items as follow: | ||
375 | 74 | |||
376 | 75 | - "name" | ||
377 | 76 | - "token" | ||
378 | 77 | - "token_secret" | ||
379 | 78 | - "consumer_key" | ||
380 | 79 | - "consumer_secret" | ||
381 | 80 | |||
382 | 81 | """ | ||
383 | 82 | d = defer.Deferred() | ||
384 | 83 | d.addBoth(self.cleanup) | ||
385 | 84 | |||
386 | 85 | proxy = get_creds_proxy() | ||
387 | 86 | |||
388 | 87 | sig = proxy.register_to_credentials_found(d.callback) | ||
389 | 88 | self._cleanup_signals.append(sig) | ||
390 | 89 | |||
391 | 90 | sig = proxy.register_to_credentials_not_found(lambda: d.callback({})) | ||
392 | 91 | self._cleanup_signals.append(sig) | ||
393 | 92 | |||
394 | 93 | sig = proxy.register_to_credentials_error( | ||
395 | 94 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
396 | 95 | self._cleanup_signals.append(sig) | ||
397 | 96 | |||
398 | 97 | done = defer.Deferred() | ||
399 | 98 | proxy.find_credentials(reply_handler=lambda: done.callback(None), | ||
400 | 99 | error_handler=lambda *a: done.errback(a)) | ||
401 | 100 | |||
402 | 101 | yield done | ||
403 | 102 | |||
404 | 103 | result = yield d | ||
405 | 104 | defer.returnValue(result) | ||
406 | 105 | |||
407 | 106 | @defer.inlineCallbacks | ||
408 | 107 | def clear_credentials(self): | ||
409 | 108 | """Clear credentials for Ubuntu One. | ||
410 | 109 | |||
411 | 110 | Return a deferred that, when fired, will return no result but will | ||
412 | 111 | indicate that the Ubuntu One credentials for the current user were | ||
413 | 112 | removed from the local keyring. | ||
414 | 113 | |||
415 | 114 | """ | ||
416 | 115 | d = defer.Deferred() | ||
417 | 116 | d.addBoth(self.cleanup) | ||
418 | 117 | |||
419 | 118 | proxy = get_creds_proxy() | ||
420 | 119 | sig = proxy.register_to_credentials_cleared(lambda: d.callback(None)) | ||
421 | 120 | self._cleanup_signals.append(sig) | ||
422 | 121 | |||
423 | 122 | sig = proxy.register_to_credentials_error( | ||
424 | 123 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
425 | 124 | self._cleanup_signals.append(sig) | ||
426 | 125 | |||
427 | 126 | done = defer.Deferred() | ||
428 | 127 | proxy.clear_credentials(reply_handler=lambda: done.callback(None), | ||
429 | 128 | error_handler=lambda *a: done.errback(a)) | ||
430 | 129 | |||
431 | 130 | yield done | ||
432 | 131 | |||
433 | 132 | yield d | ||
434 | 133 | |||
435 | 134 | @defer.inlineCallbacks | ||
436 | 135 | def store_credentials(self, token): | ||
437 | 136 | """Store credentials for Ubuntu One. | ||
438 | 137 | |||
439 | 138 | The parameter 'token' should be a dictionary that matches the | ||
440 | 139 | description of the result of 'find_credentials'. | ||
441 | 140 | |||
442 | 141 | Return a deferred that, when fired, will return no result but will | ||
443 | 142 | indicate that 'token' was stored in the local keyring as the new Ubuntu | ||
444 | 143 | One credentials for the current user. | ||
445 | 144 | |||
446 | 145 | """ | ||
447 | 146 | d = defer.Deferred() | ||
448 | 147 | d.addBoth(self.cleanup) | ||
449 | 148 | |||
450 | 149 | proxy = get_creds_proxy() | ||
451 | 150 | sig = proxy.register_to_credentials_stored(lambda: d.callback(None)) | ||
452 | 151 | self._cleanup_signals.append(sig) | ||
453 | 152 | |||
454 | 153 | sig = proxy.register_to_credentials_error( | ||
455 | 154 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
456 | 155 | self._cleanup_signals.append(sig) | ||
457 | 156 | |||
458 | 157 | done = defer.Deferred() | ||
459 | 158 | proxy.store_credentials(token, | ||
460 | 159 | reply_handler=lambda: done.callback(None), | ||
461 | 160 | error_handler=lambda *a: done.errback(a)) | ||
462 | 161 | |||
463 | 162 | yield done | ||
464 | 163 | |||
465 | 164 | yield d | ||
466 | 165 | |||
467 | 166 | @defer.inlineCallbacks | ||
468 | 167 | def register(self, window_id=0): | ||
469 | 168 | """Register to Ubuntu One. | ||
470 | 169 | |||
471 | 170 | Return a deferred that, when fired, will return the credentials for | ||
472 | 171 | Ubuntu One for the current logged in user. | ||
473 | 172 | |||
474 | 173 | If there are no credentials for the current user, a GTK UI will be | ||
475 | 174 | opened to invite the user to register to Ubuntu One. This UI provides | ||
476 | 175 | options to either register (main screen) or login (secondary screen). | ||
477 | 176 | |||
478 | 177 | You can pass an optional 'window_id' parameter that will be used by the | ||
479 | 178 | GTK UI to be set transient for it. | ||
480 | 179 | |||
481 | 180 | The returned credentials will be either a non-empty dictionary like the | ||
482 | 181 | one described in 'find_credentials', or None. The latter indicates that | ||
483 | 182 | there were no credentials for the user in the local keyring and that | ||
484 | 183 | the user refused to register to Ubuntu One. | ||
485 | 184 | |||
486 | 185 | """ | ||
487 | 186 | d = defer.Deferred() | ||
488 | 187 | d.addBoth(self.cleanup) | ||
489 | 188 | |||
490 | 189 | proxy = get_creds_proxy() | ||
491 | 190 | |||
492 | 191 | sig = proxy.register_to_credentials_found(d.callback) | ||
493 | 192 | self._cleanup_signals.append(sig) | ||
494 | 193 | |||
495 | 194 | sig = proxy.register_to_authorization_denied(lambda: d.callback(None)) | ||
496 | 195 | self._cleanup_signals.append(sig) | ||
497 | 196 | |||
498 | 197 | sig = proxy.register_to_credentials_error( | ||
499 | 198 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
500 | 199 | self._cleanup_signals.append(sig) | ||
501 | 200 | |||
502 | 201 | done = defer.Deferred() | ||
503 | 202 | proxy.register({'window_id': str(window_id)}, | ||
504 | 203 | reply_handler=lambda: done.callback(None), | ||
505 | 204 | error_handler=lambda *a: done.errback(a)) | ||
506 | 205 | |||
507 | 206 | yield done | ||
508 | 207 | |||
509 | 208 | result = yield d | ||
510 | 209 | defer.returnValue(result) | ||
511 | 210 | |||
512 | 211 | @defer.inlineCallbacks | ||
513 | 212 | def login(self, window_id=0): | ||
514 | 213 | """Login to Ubuntu One. | ||
515 | 214 | |||
516 | 215 | Return a deferred that, when fired, will return the credentials for | ||
517 | 216 | Ubuntu One for the current logged in user. | ||
518 | 217 | |||
519 | 218 | If there are no credentials for the current user, a GTK UI will be | ||
520 | 219 | opened to invite the user to login to Ubuntu One. This UI provides | ||
521 | 220 | options to either login (main screen) or retrieve password (secondary | ||
522 | 221 | screen). | ||
523 | 222 | |||
524 | 223 | You can pass an optional 'window_id' parameter that will be used by the | ||
525 | 224 | GTK UI to be set transient for it. | ||
526 | 225 | |||
527 | 226 | The returned credentials will be either a non-empty dictionary like the | ||
528 | 227 | one described in 'find_credentials', or None. The latter indicates that | ||
529 | 228 | there were no credentials for the user in the local keyring and that | ||
530 | 229 | the user refused to login to Ubuntu One. | ||
531 | 230 | |||
532 | 231 | """ | ||
533 | 232 | d = defer.Deferred() | ||
534 | 233 | d.addBoth(self.cleanup) | ||
535 | 234 | |||
536 | 235 | proxy = get_creds_proxy() | ||
537 | 236 | |||
538 | 237 | sig = proxy.register_to_credentials_found(d.callback) | ||
539 | 238 | self._cleanup_signals.append(sig) | ||
540 | 239 | |||
541 | 240 | sig = proxy.register_to_authorization_denied(lambda: d.callback(None)) | ||
542 | 241 | self._cleanup_signals.append(sig) | ||
543 | 242 | |||
544 | 243 | sig = proxy.register_to_credentials_error( | ||
545 | 244 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
546 | 245 | self._cleanup_signals.append(sig) | ||
547 | 246 | |||
548 | 247 | done = defer.Deferred() | ||
549 | 248 | proxy.login({'window_id': str(window_id)}, | ||
550 | 249 | reply_handler=lambda: done.callback(None), | ||
551 | 250 | error_handler=lambda *a: done.errback(a)) | ||
552 | 251 | |||
553 | 252 | yield done | ||
554 | 253 | |||
555 | 254 | result = yield d | ||
556 | 255 | defer.returnValue(result) | ||
557 | 0 | 256 | ||
558 | === modified file 'ubuntuone/platform/linux/__init__.py' | |||
559 | --- ubuntuone/platform/linux/__init__.py 2011-03-30 16:17:37 +0000 | |||
560 | +++ ubuntuone/platform/linux/__init__.py 2011-05-03 09:17:06 +0000 | |||
561 | @@ -51,7 +51,7 @@ | |||
562 | 51 | get_udf_path, | 51 | get_udf_path, |
563 | 52 | VMMetadataUpgraderMixIn | 52 | VMMetadataUpgraderMixIn |
564 | 53 | ) | 53 | ) |
566 | 54 | from ubuntuone.platform.linux.credentials import CredentialsManagement | 54 | from ubuntuone.platform.linux.credentials import get_creds_proxy |
567 | 55 | from ubuntuone.platform.linux.logger import setup_filesystem_logging, get_filesystem_logger | 55 | from ubuntuone.platform.linux.logger import setup_filesystem_logging, get_filesystem_logger |
568 | 56 | from ubuntuone.platform.linux.filesystem_notifications import FilesystemMonitor | 56 | from ubuntuone.platform.linux.filesystem_notifications import FilesystemMonitor |
569 | 57 | from ubuntuone.platform.linux.notification import Notification | 57 | from ubuntuone.platform.linux.notification import Notification |
570 | 58 | 58 | ||
571 | === modified file 'ubuntuone/platform/linux/credentials.py' | |||
572 | --- ubuntuone/platform/linux/credentials.py 2011-02-24 14:07:32 +0000 | |||
573 | +++ ubuntuone/platform/linux/credentials.py 2011-05-03 09:17:06 +0000 | |||
574 | @@ -15,7 +15,6 @@ | |||
575 | 15 | # | 15 | # |
576 | 16 | # You should have received a copy of the GNU General Public License along | 16 | # You should have received a copy of the GNU General Public License along |
577 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
578 | 18 | |||
579 | 19 | """Ubuntu One credentials management dbus service.""" | 18 | """Ubuntu One credentials management dbus service.""" |
580 | 20 | 19 | ||
581 | 21 | import os | 20 | import os |
582 | @@ -24,7 +23,6 @@ | |||
583 | 24 | import gettext | 23 | import gettext |
584 | 25 | import ubuntu_sso | 24 | import ubuntu_sso |
585 | 26 | 25 | ||
586 | 27 | from twisted.internet import defer | ||
587 | 28 | from ubuntu_sso.credentials import HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY | 26 | from ubuntu_sso.credentials import HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY |
588 | 29 | 27 | ||
589 | 30 | from ubuntuone.logger import (basic_formatter, logging, | 28 | from ubuntuone.logger import (basic_formatter, logging, |
590 | @@ -238,237 +236,71 @@ | |||
591 | 238 | reply_handler=reply_handler, error_handler=error_handler) | 236 | reply_handler=reply_handler, error_handler=error_handler) |
592 | 239 | 237 | ||
593 | 240 | 238 | ||
604 | 241 | class CredentialsError(Exception): | 239 | class CredentialsManagementProxy(object): |
605 | 242 | """A general exception when hadling credentilas.""" | 240 | """Proxy that allows to work with the dbus api. |
606 | 243 | 241 | ||
607 | 244 | 242 | This proxy has been added to hide the exact details of | |
608 | 245 | class CredentialsManagementTool(object): | 243 | how the signals are connected. This allows the reuse of |
609 | 246 | """Wrapper to CredentialsManagement. | 244 | the CredentialsManagementTool in diff platforms. |
600 | 247 | |||
601 | 248 | The goal of this class is to abstract the caller from calling the DBus | ||
602 | 249 | service implemented in the class CredentialsManagement. | ||
603 | 250 | |||
610 | 251 | """ | 245 | """ |
611 | 252 | 246 | ||
612 | 253 | def __init__(self): | 247 | def __init__(self): |
617 | 254 | self._cleanup_signals = [] | 248 | """Create a new instance.""" |
614 | 255 | |||
615 | 256 | def _get_creds_proxy(self): | ||
616 | 257 | """Get the CredentialsManagement dbus proxy.""" | ||
618 | 258 | bus = dbus.SessionBus() | 249 | bus = dbus.SessionBus() |
619 | 259 | try: | 250 | try: |
620 | 260 | obj = bus.get_object(DBUS_BUS_NAME, | 251 | obj = bus.get_object(DBUS_BUS_NAME, |
621 | 261 | DBUS_CREDENTIALS_PATH, | 252 | DBUS_CREDENTIALS_PATH, |
622 | 262 | follow_name_owner_changes=True) | 253 | follow_name_owner_changes=True) |
624 | 263 | proxy = dbus.Interface(obj, DBUS_CREDENTIALS_IFACE) | 254 | self.proxy = dbus.Interface(obj, DBUS_CREDENTIALS_IFACE) |
625 | 264 | except: | 255 | except: |
626 | 265 | logger.exception('get_creds_proxy:') | 256 | logger.exception('get_creds_proxy:') |
627 | 266 | raise | 257 | raise |
628 | 267 | 258 | ||
836 | 268 | return proxy | 259 | def find_credentials(self, *args, **kwargs): |
837 | 269 | 260 | """Relay the find_credentials method.""" | |
838 | 270 | def cleanup(self, _): | 261 | return self.proxy.find_credentials(*args, **kwargs) |
839 | 271 | """Disconnect all the DBus signals.""" | 262 | |
840 | 272 | for sig in self._cleanup_signals: | 263 | def clear_credentials(self, *args, **kwargs): |
841 | 273 | logger.debug('cleanup: removing signal match %r', sig) | 264 | """Relay the clear_credentials method.""" |
842 | 274 | sig.remove() | 265 | return self.proxy.clear_credentials(*args, **kwargs) |
843 | 275 | 266 | ||
844 | 276 | return _ | 267 | def store_credentials(self, *args, **kwargs): |
845 | 277 | 268 | """Relay the store_credentials method.""" | |
846 | 278 | @defer.inlineCallbacks | 269 | return self.proxy.store_credentials(*args, **kwargs) |
847 | 279 | def find_credentials(self): | 270 | |
848 | 280 | """Find credentials for Ubuntu One. | 271 | def register(self, *args, **kwargs): |
849 | 281 | 272 | """Relay the register method.""" | |
850 | 282 | Return a deferred that, when fired, will return the credentials for | 273 | return self.proxy.register(*args, **kwargs) |
851 | 283 | Ubuntu One for the current logged in user. | 274 | |
852 | 284 | 275 | def login(self, *args, **kwargs): | |
853 | 285 | The credentials is a dictionary with both string keys and values. The | 276 | """Relay the login method.""" |
854 | 286 | dictionary may be either empty if there are no credentials for the | 277 | return self.proxy.login(*args, **kwargs) |
855 | 287 | user, or will hold five items as follow: | 278 | |
856 | 288 | 279 | def register_to_credentials_stored(self, callback): | |
857 | 289 | - "name" | 280 | """Register to the CredentialsStored dbus signal.""" |
858 | 290 | - "token" | 281 | return self.proxy.connect_to_signal('CredentialsStored', callback) |
859 | 291 | - "token_secret" | 282 | |
860 | 292 | - "consumer_key" | 283 | def register_to_credentials_cleared(self, callback): |
861 | 293 | - "consumer_secret" | 284 | """Register to the CredentialsCleared dbus signal.""" |
862 | 294 | 285 | return self.proxy.connect_to_signal('CredentialsCleared', callback) | |
863 | 295 | """ | 286 | |
864 | 296 | d = defer.Deferred() | 287 | def register_to_credentials_found(self, callback): |
865 | 297 | d.addBoth(self.cleanup) | 288 | """Register to the CredentialsFound dbus signal.""" |
866 | 298 | 289 | return self.proxy.connect_to_signal('CredentialsFound', callback) | |
867 | 299 | proxy = self._get_creds_proxy() | 290 | |
868 | 300 | 291 | def register_to_credentials_not_found(self, callback): | |
869 | 301 | sig = proxy.connect_to_signal('CredentialsFound', d.callback) | 292 | """Register to the CredentialsFound dbus signal.""" |
870 | 302 | self._cleanup_signals.append(sig) | 293 | return self.proxy.connect_to_signal('CredentialsNotFound', callback) |
871 | 303 | 294 | ||
872 | 304 | sig = proxy.connect_to_signal('CredentialsNotFound', | 295 | def register_to_authorization_denied(self, callback): |
873 | 305 | lambda: d.callback({})) | 296 | """Register to the AuthorizationDenied dbus signal.""" |
874 | 306 | self._cleanup_signals.append(sig) | 297 | return self.proxy.connect_to_signal('AuthorizationDenied', callback) |
875 | 307 | 298 | ||
876 | 308 | sig = proxy.connect_to_signal('CredentialsError', | 299 | def register_to_credentials_error(self, callback): |
877 | 309 | lambda error_dict: d.errback(CredentialsError(error_dict))) | 300 | """Register to the CredentialsError dbus signal.""" |
878 | 310 | self._cleanup_signals.append(sig) | 301 | return self.proxy.connect_to_signal('CredentialsError', callback) |
879 | 311 | 302 | ||
880 | 312 | done = defer.Deferred() | 303 | |
881 | 313 | proxy.find_credentials(reply_handler=lambda: done.callback(None), | 304 | def get_creds_proxy(): |
882 | 314 | error_handler=lambda *a: done.errback(a)) | 305 | """Get the CredentialsManagement dbus proxy.""" |
883 | 315 | 306 | return CredentialsManagementProxy() | |
677 | 316 | yield done | ||
678 | 317 | |||
679 | 318 | result = yield d | ||
680 | 319 | defer.returnValue(result) | ||
681 | 320 | |||
682 | 321 | @defer.inlineCallbacks | ||
683 | 322 | def clear_credentials(self): | ||
684 | 323 | """Clear credentials for Ubuntu One. | ||
685 | 324 | |||
686 | 325 | Return a deferred that, when fired, will return no result but will | ||
687 | 326 | indicate that the Ubuntu One credentials for the current user were | ||
688 | 327 | removed from the local keyring. | ||
689 | 328 | |||
690 | 329 | """ | ||
691 | 330 | d = defer.Deferred() | ||
692 | 331 | d.addBoth(self.cleanup) | ||
693 | 332 | |||
694 | 333 | proxy = self._get_creds_proxy() | ||
695 | 334 | sig = proxy.connect_to_signal('CredentialsCleared', | ||
696 | 335 | lambda: d.callback(None)) | ||
697 | 336 | self._cleanup_signals.append(sig) | ||
698 | 337 | |||
699 | 338 | sig = proxy.connect_to_signal('CredentialsError', | ||
700 | 339 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
701 | 340 | self._cleanup_signals.append(sig) | ||
702 | 341 | |||
703 | 342 | done = defer.Deferred() | ||
704 | 343 | proxy.clear_credentials(reply_handler=lambda: done.callback(None), | ||
705 | 344 | error_handler=lambda *a: done.errback(a)) | ||
706 | 345 | |||
707 | 346 | yield done | ||
708 | 347 | |||
709 | 348 | yield d | ||
710 | 349 | |||
711 | 350 | @defer.inlineCallbacks | ||
712 | 351 | def store_credentials(self, token): | ||
713 | 352 | """Store credentials for Ubuntu One. | ||
714 | 353 | |||
715 | 354 | The parameter 'token' should be a dictionary that matches the | ||
716 | 355 | description of the result of 'find_credentials'. | ||
717 | 356 | |||
718 | 357 | Return a deferred that, when fired, will return no result but will | ||
719 | 358 | indicate that 'token' was stored in the local keyring as the new Ubuntu | ||
720 | 359 | One credentials for the current user. | ||
721 | 360 | |||
722 | 361 | """ | ||
723 | 362 | d = defer.Deferred() | ||
724 | 363 | d.addBoth(self.cleanup) | ||
725 | 364 | |||
726 | 365 | proxy = self._get_creds_proxy() | ||
727 | 366 | sig = proxy.connect_to_signal('CredentialsStored', | ||
728 | 367 | lambda: d.callback(None)) | ||
729 | 368 | self._cleanup_signals.append(sig) | ||
730 | 369 | |||
731 | 370 | sig = proxy.connect_to_signal('CredentialsError', | ||
732 | 371 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
733 | 372 | self._cleanup_signals.append(sig) | ||
734 | 373 | |||
735 | 374 | done = defer.Deferred() | ||
736 | 375 | proxy.store_credentials(token, | ||
737 | 376 | reply_handler=lambda: done.callback(None), | ||
738 | 377 | error_handler=lambda *a: done.errback(a)) | ||
739 | 378 | |||
740 | 379 | yield done | ||
741 | 380 | |||
742 | 381 | yield d | ||
743 | 382 | |||
744 | 383 | @defer.inlineCallbacks | ||
745 | 384 | def register(self, window_id=0): | ||
746 | 385 | """Register to Ubuntu One. | ||
747 | 386 | |||
748 | 387 | Return a deferred that, when fired, will return the credentials for | ||
749 | 388 | Ubuntu One for the current logged in user. | ||
750 | 389 | |||
751 | 390 | If there are no credentials for the current user, a GTK UI will be | ||
752 | 391 | opened to invite the user to register to Ubuntu One. This UI provides | ||
753 | 392 | options to either register (main screen) or login (secondary screen). | ||
754 | 393 | |||
755 | 394 | You can pass an optional 'window_id' parameter that will be used by the | ||
756 | 395 | GTK UI to be set transient for it. | ||
757 | 396 | |||
758 | 397 | The returned credentials will be either a non-empty dictionary like the | ||
759 | 398 | one described in 'find_credentials', or None. The latter indicates that | ||
760 | 399 | there were no credentials for the user in the local keyring and that | ||
761 | 400 | the user refused to register to Ubuntu One. | ||
762 | 401 | |||
763 | 402 | """ | ||
764 | 403 | d = defer.Deferred() | ||
765 | 404 | d.addBoth(self.cleanup) | ||
766 | 405 | |||
767 | 406 | proxy = self._get_creds_proxy() | ||
768 | 407 | |||
769 | 408 | sig = proxy.connect_to_signal('CredentialsFound', d.callback) | ||
770 | 409 | self._cleanup_signals.append(sig) | ||
771 | 410 | |||
772 | 411 | sig = proxy.connect_to_signal('AuthorizationDenied', | ||
773 | 412 | lambda: d.callback(None)) | ||
774 | 413 | self._cleanup_signals.append(sig) | ||
775 | 414 | |||
776 | 415 | sig = proxy.connect_to_signal('CredentialsError', | ||
777 | 416 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
778 | 417 | self._cleanup_signals.append(sig) | ||
779 | 418 | |||
780 | 419 | done = defer.Deferred() | ||
781 | 420 | proxy.register({'window_id': str(window_id)}, | ||
782 | 421 | reply_handler=lambda: done.callback(None), | ||
783 | 422 | error_handler=lambda *a: done.errback(a)) | ||
784 | 423 | |||
785 | 424 | yield done | ||
786 | 425 | |||
787 | 426 | result = yield d | ||
788 | 427 | defer.returnValue(result) | ||
789 | 428 | |||
790 | 429 | @defer.inlineCallbacks | ||
791 | 430 | def login(self, window_id=0): | ||
792 | 431 | """Login to Ubuntu One. | ||
793 | 432 | |||
794 | 433 | Return a deferred that, when fired, will return the credentials for | ||
795 | 434 | Ubuntu One for the current logged in user. | ||
796 | 435 | |||
797 | 436 | If there are no credentials for the current user, a GTK UI will be | ||
798 | 437 | opened to invite the user to login to Ubuntu One. This UI provides | ||
799 | 438 | options to either login (main screen) or retrieve password (secondary | ||
800 | 439 | screen). | ||
801 | 440 | |||
802 | 441 | You can pass an optional 'window_id' parameter that will be used by the | ||
803 | 442 | GTK UI to be set transient for it. | ||
804 | 443 | |||
805 | 444 | The returned credentials will be either a non-empty dictionary like the | ||
806 | 445 | one described in 'find_credentials', or None. The latter indicates that | ||
807 | 446 | there were no credentials for the user in the local keyring and that | ||
808 | 447 | the user refused to login to Ubuntu One. | ||
809 | 448 | |||
810 | 449 | """ | ||
811 | 450 | d = defer.Deferred() | ||
812 | 451 | d.addBoth(self.cleanup) | ||
813 | 452 | |||
814 | 453 | proxy = self._get_creds_proxy() | ||
815 | 454 | |||
816 | 455 | sig = proxy.connect_to_signal('CredentialsFound', d.callback) | ||
817 | 456 | self._cleanup_signals.append(sig) | ||
818 | 457 | |||
819 | 458 | sig = proxy.connect_to_signal('AuthorizationDenied', | ||
820 | 459 | lambda: d.callback(None)) | ||
821 | 460 | self._cleanup_signals.append(sig) | ||
822 | 461 | |||
823 | 462 | sig = proxy.connect_to_signal('CredentialsError', | ||
824 | 463 | lambda error_dict: d.errback(CredentialsError(error_dict))) | ||
825 | 464 | self._cleanup_signals.append(sig) | ||
826 | 465 | |||
827 | 466 | done = defer.Deferred() | ||
828 | 467 | proxy.login({'window_id': str(window_id)}, | ||
829 | 468 | reply_handler=lambda: done.callback(None), | ||
830 | 469 | error_handler=lambda *a: done.errback(a)) | ||
831 | 470 | |||
832 | 471 | yield done | ||
833 | 472 | |||
834 | 473 | result = yield d | ||
835 | 474 | defer.returnValue(result) | ||
884 | 475 | 307 | ||
885 | === added file 'ubuntuone/platform/windows/credentials.py' | |||
886 | --- ubuntuone/platform/windows/credentials.py 1970-01-01 00:00:00 +0000 | |||
887 | +++ ubuntuone/platform/windows/credentials.py 2011-05-03 09:17:06 +0000 | |||
888 | @@ -0,0 +1,131 @@ | |||
889 | 1 | #!/usr/bin/env python | ||
890 | 2 | # -*- coding: utf-8 -*- | ||
891 | 3 | # | ||
892 | 4 | # Author: Manuel de la Pena<manuel@canonical.com> | ||
893 | 5 | # | ||
894 | 6 | # Copyright 2011 Canonical Ltd. | ||
895 | 7 | # | ||
896 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
897 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
898 | 10 | # by the Free Software Foundation. | ||
899 | 11 | # | ||
900 | 12 | # This program is distributed in the hope that it will be useful, but | ||
901 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
902 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
903 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
904 | 16 | # | ||
905 | 17 | # You should have received a copy of the GNU General Public License along | ||
906 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
907 | 19 | """Ubuntu One credentials management IPC service.""" | ||
908 | 20 | |||
909 | 21 | import os | ||
910 | 22 | |||
911 | 23 | import gettext | ||
912 | 24 | |||
913 | 25 | from ubuntu_sso.main.windows import UbuntuSSOClient | ||
914 | 26 | from ubuntu_sso.credentials import HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY | ||
915 | 27 | from twisted.internet import defer | ||
916 | 28 | |||
917 | 29 | from ubuntuone.logger import (basic_formatter, logging, | ||
918 | 30 | CustomRotatingFileHandler, LOGFOLDER) | ||
919 | 31 | from ubuntuone.clientdefs import GETTEXT_PACKAGE | ||
920 | 32 | |||
921 | 33 | |||
922 | 34 | Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string) | ||
923 | 35 | NO_OP = lambda *args, **kwargs: None | ||
924 | 36 | |||
925 | 37 | LOG_LEVEL = logging.DEBUG | ||
926 | 38 | path = os.path.join(LOGFOLDER, 'credentials.log') | ||
927 | 39 | MAIN_HANDLER = CustomRotatingFileHandler(path) | ||
928 | 40 | MAIN_HANDLER.setFormatter(basic_formatter) | ||
929 | 41 | MAIN_HANDLER.setLevel(LOG_LEVEL) | ||
930 | 42 | |||
931 | 43 | logger = logging.getLogger("ubuntuone.credentials") | ||
932 | 44 | logger.setLevel(LOG_LEVEL) | ||
933 | 45 | logger.addHandler(MAIN_HANDLER) | ||
934 | 46 | |||
935 | 47 | APP_NAME = "Ubuntu One" | ||
936 | 48 | TC_URL = "https://one.ubuntu.com/terms/" | ||
937 | 49 | PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/" | ||
938 | 50 | DESCRIPTION = Q_('Ubuntu One requires an Ubuntu Single Sign On (SSO) account. ' | ||
939 | 51 | 'This process will allow you to create a new account, ' | ||
940 | 52 | 'if you do not yet have one.') | ||
941 | 53 | |||
942 | 54 | |||
943 | 55 | class CredentialsManagement(object): | ||
944 | 56 | """Object that manages Ubuntu One credentials.""" | ||
945 | 57 | |||
946 | 58 | def __init__(self, proxy, *args, **kwargs): | ||
947 | 59 | super(CredentialsManagement, self).__init__(*args, **kwargs) | ||
948 | 60 | self.sso_proxy = proxy | ||
949 | 61 | |||
950 | 62 | def find_credentials(self, reply_handler=NO_OP, error_handler=NO_OP): | ||
951 | 63 | """Ask the Ubuntu One credentials.""" | ||
952 | 64 | self.sso_proxy.find_credentials(APP_NAME, {}, | ||
953 | 65 | reply_handler=reply_handler, error_handler=error_handler) | ||
954 | 66 | |||
955 | 67 | |||
956 | 68 | def clear_credentials(self, reply_handler=NO_OP, error_handler=NO_OP): | ||
957 | 69 | """Clear the Ubuntu One credentials.""" | ||
958 | 70 | self.sso_proxy.clear_credentials(APP_NAME, {}, | ||
959 | 71 | reply_handler=reply_handler, error_handler=error_handler) | ||
960 | 72 | |||
961 | 73 | def store_credentials(self, credentials, | ||
962 | 74 | reply_handler=NO_OP, error_handler=NO_OP): | ||
963 | 75 | """Store the token for Ubuntu One application.""" | ||
964 | 76 | self.sso_proxy.store_credentials(APP_NAME, credentials, | ||
965 | 77 | reply_handler=reply_handler, error_handler=error_handler) | ||
966 | 78 | |||
967 | 79 | def register(self, args, reply_handler=NO_OP, error_handler=NO_OP): | ||
968 | 80 | """Get credentials if found else prompt to register to Ubuntu One.""" | ||
969 | 81 | params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL, | ||
970 | 82 | PING_URL_KEY: PING_URL} | ||
971 | 83 | params.update(args) | ||
972 | 84 | self.sso_proxy.register(APP_NAME, params, | ||
973 | 85 | reply_handler=reply_handler, error_handler=error_handler) | ||
974 | 86 | |||
975 | 87 | def login(self, args, reply_handler=NO_OP, error_handler=NO_OP): | ||
976 | 88 | """Get credentials if found else prompt to login to Ubuntu One.""" | ||
977 | 89 | params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL, | ||
978 | 90 | PING_URL_KEY: PING_URL} | ||
979 | 91 | params.update(args) | ||
980 | 92 | self.sso_proxy.login(APP_NAME, params, | ||
981 | 93 | reply_handler=reply_handler, error_handler=error_handler) | ||
982 | 94 | |||
983 | 95 | def register_to_credentials_stored(self, callback): | ||
984 | 96 | """Register to the CredentialsStored dbus signal.""" | ||
985 | 97 | self.sso_proxy.on_credentials_stored_cb = callback | ||
986 | 98 | return self.sso_proxy.on_credentials_stored_cb | ||
987 | 99 | |||
988 | 100 | def register_to_credentials_cleared(self, callback): | ||
989 | 101 | """Register to the CredentialsCleared dbus signal.""" | ||
990 | 102 | self.sso_proxy.on_credentials_cleared_cb = callback | ||
991 | 103 | return self.sso_proxy.on_credentials_cleared_cb | ||
992 | 104 | |||
993 | 105 | def register_to_credentials_found(self, callback): | ||
994 | 106 | """Register to the CredentialsFound dbus signal.""" | ||
995 | 107 | self.sso_proxy.on_credentials_found_cb = callback | ||
996 | 108 | return self.sso_proxy.on_credentials_found_cb | ||
997 | 109 | |||
998 | 110 | def register_to_credentials_not_found(self, callback): | ||
999 | 111 | """Register to the CredentialsFound dbus signal.""" | ||
1000 | 112 | self.sso_proxy.on_credentials_not_found_cb = callback | ||
1001 | 113 | return self.sso_proxy.on_credentials_not_found_cb | ||
1002 | 114 | |||
1003 | 115 | def register_to_authorization_denied(self, callback): | ||
1004 | 116 | """Register to the AuthorizationDenied dbus signal.""" | ||
1005 | 117 | self.sso_proxy.on_authorization_denied_cb = callback | ||
1006 | 118 | return self.sso_proxy.on_authorization_denied_cb | ||
1007 | 119 | |||
1008 | 120 | def register_to_credentials_error(self, callback): | ||
1009 | 121 | """Register to the CredentialsError dbus signal.""" | ||
1010 | 122 | self.sso_proxy.on_credentials_error_cb = callback | ||
1011 | 123 | return self.sso_proxy.on_credentials_error_cb | ||
1012 | 124 | |||
1013 | 125 | |||
1014 | 126 | @defer.inlineCallbacks | ||
1015 | 127 | def get_creds_proxy(): | ||
1016 | 128 | """Get the CredentialsManagement dbus proxy.""" | ||
1017 | 129 | client = UbuntuSSOClient() | ||
1018 | 130 | client = yield client.connect() | ||
1019 | 131 | defer.returnValue(CredentialsManagement(client.cred_management)) |
Passes tests and nothing big pops out in the code