Merge lp:~nataliabidart/desktopcouch/no-hard-coded-consumer into lp:desktopcouch

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 178
Merged at revision: 176
Proposed branch: lp:~nataliabidart/desktopcouch/no-hard-coded-consumer
Merge into: lp:desktopcouch
Diff against target: 112 lines (+23/-56)
1 file modified
desktopcouch/replication_services/ubuntuone.py (+23/-56)
To merge this branch: bzr merge lp:~nataliabidart/desktopcouch/no-hard-coded-consumer
Reviewer Review Type Date Requested Status
Chad Miller (community) Approve
Review via email: mp+36792@code.launchpad.net

Commit message

* Replication for Ubuntu One needs to get credentials from Ubuntu SSO (LP: #649320).

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) wrote :

no-hard-coded-consumer$ PYTHONPATH=`pwd` bin/desktopcouch-service
WARNING:root:Starting up personal couchdb.
Removing stale, deceptive pid file.
Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file:///home/cmiller/.local/share/desktop-couch/couchdb.html
DEBUG:root:starting dbus main loop
INFO:root:Connecting to http://localhost:57539/.
INFO:root:Connecting to http://localhost:57539/.
DEBUG:root:found 1 self_identity records
INFO:LocationAdvertisement:starting advertising _couchdb_location._tcp on port 57539
DEBUG:replication:started replicating
INFO:root:Connecting to http://localhost:57539/.
DEBUG:replication:replication of discovered hosts finished
INFO:root:Connecting to http://localhost:57539/.
DEBUG:root:static pairings are [('fd98a23e-4fb3-410c-9146-4dee15d40d05', 'ubuntuone', True, True)]
DEBUG:replication:Looking up prefix for service 'ubuntuone'
DEBUG:replication:Looking up prefix for service 'ubuntuone'
ERROR:root:Could not get access token from sso.
Traceback (most recent call last):
  File "/home/cmiller/work/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication_services/ubuntuone.py", line 86, in __str__
    consumer = oauth.OAuthConsumer(oauth_data['consumer_key'],
TypeError: 'NoneType' object is unsubscriptable
replication 2010-09-27 17:16:27,321 - Could not get access token from sso.
Traceback (most recent call last):
  File "/home/cmiller/work/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication_services/ubuntuone.py", line 86, in __str__
    consumer = oauth.OAuthConsumer(oauth_data['consumer_key'],
TypeError: 'NoneType' object is unsubscriptable
WARNING:replication:Can't reach service ubuntuone. No access token.
replication 2010-09-27 17:16:27,323 - Can't reach service ubuntuone. No access token.
DEBUG:replication:finished replicating
DEBUG:root:starting replicator main loop
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 576, in msg_reply_handler
    reply_handler(*message.get_args_list(**get_args_opts))
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 391, in _introspect_reply_handler
    self._introspect_execute_queue()
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 378, in _introspect_execute_queue
    proxy_method(*args, **keywords)
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 132, in __call__
    **keywords)
TypeError: call_async() got an unexpected keyword argument 'bus_interface'
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 576, in msg_reply_handler
    reply_handler(*message.get_args_list(**get_args_opts))
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 391, in _introspect_reply_handler
    self._introspect_execute_queue()
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 378, in _introspect_execute_queue
    proxy_method(*args, **keywords)
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 132, in __call__
    **keywords)
TypeError: call_async() got an unexpected keyword argument 'bus_interface'

review: Needs Fixing
Revision history for this message
Eric Casteleijn (thisfred) wrote :

I get a different error on lucid, but that may be because desktopcouch trunk is not meant to work there:

INFO:root:Connecting to http://localhost:36900/.
DEBUG:root:starting dbus main loop
INFO:root:Connecting to http://localhost:36900/.
DEBUG:root:found 1 self_identity records
INFO:LocationAdvertisement:starting advertising _couchdb_location._tcp on port 36900
DEBUG:replication:started replicating
INFO:root:Connecting to http://localhost:36900/.
DEBUG:replication:replication of discovered hosts finished
INFO:root:Connecting to http://localhost:36900/.
DEBUG:root:static pairings are [('5c4829ed-d0ca-4c7e-ac59-68a79626bd44', 'ubuntuone', True, True)]
DEBUG:replication:Looking up prefix for service 'ubuntuone'
ERROR:replication:replication of services aborted
Traceback (most recent call last):
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication.py", line 140, in do_all_replication
    remote_oauth_data = oauth_info_for_service(sn)
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication.py", line 64, in oauth_info_for_service
    return getattr(mod, service_name).get_oauth_data()
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication_services/ubuntuone.py", line 49, in get_oauth_data
    proxy = bus.get_object(ubuntu_sso.DBUS_BUS_NAME,
AttributeError: 'module' object has no attribute 'DBUS_BUS_NAME'
replication 2010-09-27 17:23:26,439 - replication of services aborted
Traceback (most recent call last):
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication.py", line 140, in do_all_replication
    remote_oauth_data = oauth_info_for_service(sn)
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication.py", line 64, in oauth_info_for_service
    return getattr(mod, service_name).get_oauth_data()
  File "/home/eric/canonical/desktopcouch/no-hard-coded-consumer/desktopcouch/replication_services/ubuntuone.py", line 49, in get_oauth_data
    proxy = bus.get_object(ubuntu_sso.DBUS_BUS_NAME,
AttributeError: 'module' object has no attribute 'DBUS_BUS_NAME'

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Errors should be fixed now.

Revision history for this message
Chad Miller (cmiller) wrote :

I removed keys from gnomekeyring/seahorse. I then started desktopcouch-service, and got empty dicts back for tokens. Those were accessed around line 79 of desktopcouch/replication_services/ubuntuone.py for some key. That fails, so stops replication with a message in the log. Not a big deal.

I then started up syncdaemon, and reauthorized myself. I changed my DNS resolver to use prod (instead of staging), and got ServerError: (503, '') .

thisfred still works on the server end.

Revision history for this message
Chad Miller (cmiller) wrote :

Aside from the minor ugliness of the KeyError on lin 79, this looks good to me.

review: Approve
Revision history for this message
dobey (dobey) wrote :
Download full text (51.5 KiB)

The attempt to merge lp:~nataliabidart/desktopcouch/no-hard-coded-consumer into lp:desktopcouch failed. Below is the output from the failed tests.

running build
running build_py
creating build
creating build/lib.linux-i686-2.6
creating build/lib.linux-i686-2.6/desktopcouch
copying desktopcouch/stop_local_couchdb.py -> build/lib.linux-i686-2.6/desktopcouch
copying desktopcouch/start_local_couchdb.py -> build/lib.linux-i686-2.6/desktopcouch
copying desktopcouch/replication.py -> build/lib.linux-i686-2.6/desktopcouch
copying desktopcouch/local_files.py -> build/lib.linux-i686-2.6/desktopcouch
copying desktopcouch/__init__.py -> build/lib.linux-i686-2.6/desktopcouch
creating build/lib.linux-i686-2.6/desktopcouch/tests
copying desktopcouch/tests/test_start_local_couchdb.py -> build/lib.linux-i686-2.6/desktopcouch/tests
copying desktopcouch/tests/test_local_files.py -> build/lib.linux-i686-2.6/desktopcouch/tests
copying desktopcouch/tests/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/tests
copying desktopcouch/tests/test_replication.py -> build/lib.linux-i686-2.6/desktopcouch/tests
creating build/lib.linux-i686-2.6/desktopcouch/tasks
copying desktopcouch/tasks/record.py -> build/lib.linux-i686-2.6/desktopcouch/tasks
copying desktopcouch/tasks/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/tasks
creating build/lib.linux-i686-2.6/desktopcouch/pair
copying desktopcouch/pair/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/pair
creating build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/field_registry.py -> build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/record.py -> build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/server.py -> build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/couchgrid.py -> build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/records
copying desktopcouch/records/server_base.py -> build/lib.linux-i686-2.6/desktopcouch/records
creating build/lib.linux-i686-2.6/desktopcouch/replication_services
copying desktopcouch/replication_services/ubuntuone.py -> build/lib.linux-i686-2.6/desktopcouch/replication_services
copying desktopcouch/replication_services/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/replication_services
copying desktopcouch/replication_services/example.py -> build/lib.linux-i686-2.6/desktopcouch/replication_services
creating build/lib.linux-i686-2.6/desktopcouch/notes
copying desktopcouch/notes/record.py -> build/lib.linux-i686-2.6/desktopcouch/notes
copying desktopcouch/notes/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/notes
creating build/lib.linux-i686-2.6/desktopcouch/bookmarks
copying desktopcouch/bookmarks/record.py -> build/lib.linux-i686-2.6/desktopcouch/bookmarks
copying desktopcouch/bookmarks/__init__.py -> build/lib.linux-i686-2.6/desktopcouch/bookmarks
creating build/lib.linux-i686-2.6/desktopcouch/contacts
copying desktopcouch/contacts/record.py -> build/lib.linux-i686-2.6/desktopcouch/contacts
copying desktopcouch/contacts/view.py -> build/lib.linux-i686-2.6/desktopcouch/contacts
copying desktopcouch/co...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/replication_services/ubuntuone.py'
2--- desktopcouch/replication_services/ubuntuone.py 2010-04-13 02:44:20 +0000
3+++ desktopcouch/replication_services/ubuntuone.py 2010-09-27 21:59:39 +0000
4@@ -1,7 +1,9 @@
5 from oauth import oauth
6 import logging
7 import httplib2
8-import gnomekeyring
9+
10+import dbus
11+import ubuntu_sso
12
13 try:
14 # Python 2.5
15@@ -14,8 +16,6 @@
16 name = "Ubuntu One"
17 description = "The Ubuntu One cloud service"
18
19-oauth_consumer_key = "ubuntuone"
20-oauth_consumer_secret = "hammertime"
21
22 def in_main_thread(function, *args, **kwargs):
23 from twisted.python.threadable import isInIOThread
24@@ -37,50 +37,17 @@
25 if oauth_data is not None:
26 return oauth_data
27
28- try:
29- matches = in_main_thread(gnomekeyring.find_items_sync,
30- gnomekeyring.ITEM_GENERIC_SECRET,
31- {'ubuntuone-realm': "https://ubuntuone.com",
32- 'oauth-consumer-key': oauth_consumer_key})
33- if matches:
34- # parse "a=b&c=d" to {"a":"b","c":"d"}
35- kv_list = [x.split("=", 1) for x in matches[0].secret.split("&")]
36- keys, values = zip(*kv_list)
37- keys = [k.replace("oauth_", "") for k in keys]
38- oauth_data = dict(zip(keys, values))
39- oauth_data.update({
40- "consumer_key": oauth_consumer_key,
41- "consumer_secret": oauth_consumer_secret,
42- })
43- return oauth_data
44- except ImportError, e:
45- logging.info("Can't replicate to Ubuntu One cloud without credentials."
46- " %s", e)
47- except gnomekeyring.NoMatchError:
48- logging.info("This machine hasn't authorized itself to Ubuntu One; "
49- "replication to the cloud isn't possible until it has. See "
50- "'ubuntuone-client-applet'.")
51- except gnomekeyring.NoKeyringDaemonError:
52- logging.error("No keyring daemon found in this session, so we have "
53- "no access to Ubuntu One data.")
54- except gnomekeyring.CancelledError:
55- logging.error("User cancelled the keyring dialog. We have no access.")
56+ bus = dbus.SessionBus()
57+ proxy = bus.get_object(ubuntu_sso.DBUS_BUS_NAME,
58+ ubuntu_sso.DBUS_CRED_PATH,
59+ follow_name_owner_changes=True)
60+ logging.info('get_oauth_data: asking for credentials to Ubuntu SSO. '
61+ 'App name: %s', name)
62+ oauth_data = proxy.find_credentials(name)
63+ logging.info('Got credentials from Ubuntu SSO. Non emtpy credentials? %s',
64+ len(oauth_data) > 0)
65+ return oauth_data
66
67-def get_oauth_token(consumer):
68- """Get the token from the keyring"""
69- try:
70- items = in_main_thread(gnomekeyring.find_items_sync,
71- gnomekeyring.ITEM_GENERIC_SECRET,
72- {'ubuntuone-realm': "https://one.ubuntu.com",
73- 'oauth-consumer-key': consumer.key})
74- except gnomekeyring.NoMatchError:
75- logging.info("No o.u.c key. Maybe there's uo.c key?")
76- items = in_main_thread(gnomekeyring.find_items_sync,
77- gnomekeyring.ITEM_GENERIC_SECRET,
78- {'ubuntuone-realm': "https://ubuntuone.com",
79- 'oauth-consumer-key': consumer.key})
80- if len(items):
81- return oauth.OAuthToken.from_string(items[0].secret)
82
83 def get_oauth_request_header(consumer, access_token, http_url):
84 """Get an oauth request header given the token and the url"""
85@@ -107,17 +74,17 @@
86
87 url = "https://one.ubuntu.com/api/account/"
88 if self.oauth_header is None:
89- consumer = oauth.OAuthConsumer(oauth_consumer_key,
90- oauth_consumer_secret)
91 try:
92- access_token = get_oauth_token(consumer)
93- except gnomekeyring.NoKeyringDaemonError:
94- logging.info("No keyring daemon is running for this session.")
95- raise ValueError("No keyring access")
96- if not access_token:
97- logging.info("Could not get access token from keyring")
98- raise ValueError("No keyring access")
99- self.oauth_header = get_oauth_request_header(
100+ get_oauth_data()
101+ consumer = oauth.OAuthConsumer(oauth_data['consumer_key'],
102+ oauth_data['consumer_secret'])
103+ access_token = oauth.OAuthToken(oauth_data['token'],
104+ oauth_data['token_secret'])
105+ except:
106+ logging.exception("Could not get access token from sso.")
107+ raise ValueError("No access token.")
108+
109+ self.oauth_header = get_oauth_request_header(
110 consumer, access_token, url)
111
112 client = httplib2.Http()

Subscribers

People subscribed via source and target branches