Merge lp:~leonardr/launchpadlib/bug-712808 into lp:launchpadlib

Proposed by Leonard Richardson
Status: Merged
Approved by: Graham Binns
Approved revision: 115
Merged at revision: 113
Proposed branch: lp:~leonardr/launchpadlib/bug-712808
Merge into: lp:launchpadlib
Diff against target: 131 lines (+42/-37)
3 files modified
src/launchpadlib/NEWS.txt (+7/-0)
src/launchpadlib/__init__.py (+1/-1)
src/launchpadlib/launchpad.py (+34/-36)
To merge this branch: bzr merge lp:~leonardr/launchpadlib/bug-712808
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+48830@code.launchpad.net

Description of the change

This branch fixes bug 712808 by changing launchpadlib's behavior when consumer_name is specified as a string. The previous behavior was to treat consumer_name as an OAuth consumer, but to try to do a desktop-wide integration. This is internally inconsistent--either the "consumer_name" should be treated as an application name and we should perform a desktop-wide integration, or we should try to do an application-specific integration. Since we've already decided to do desktop-wide integration in ordinary cases, I chose to treat a string consumer_name as the application name for a desktop-wide credential.

This code can't be tested normally, but it's easy to test manually, by running this code when you have no active credential on staging.launchpad.net:

Launchpad.get_token_and_login("my-app")

To post a comment you must log in.
lp:~leonardr/launchpadlib/bug-712808 updated
114. By Leonard Richardson

Moved the code to check the credential store into _authorize_token_and_login, so that it's used by all code paths.

Revision history for this message
Leonard Richardson (leonardr) wrote :

I noticed another problem: get_token_and_login() works, and it stores credentials in the keyring, but it doesn't _read_ credentials from the keyring the second time you run the code, because the code to look in the keyring was in login_with(). I moved that code to _authorize_token_and_login, which is called by all code paths, and now get_token_and_login() works just as well as login_with().

lp:~leonardr/launchpadlib/bug-712808 updated
115. By Leonard Richardson

Don't overwrite the credentials variable after going through so much trouble to create it.

Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/launchpadlib/NEWS.txt'
--- src/launchpadlib/NEWS.txt 2011-01-18 21:57:09 +0000
+++ src/launchpadlib/NEWS.txt 2011-02-07 20:13:43 +0000
@@ -2,6 +2,13 @@
2NEWS for launchpadlib2NEWS for launchpadlib
3=====================3=====================
44
51.9.5 (2010-02-07)
6==================
7
8- Fixed a bug that prevented the deprecated get_token_and_login code
9 from working, and required that users of get_token_and_login get a
10 new token on every usage.
11
51.9.4 (2010-01-18)121.9.4 (2010-01-18)
6==================13==================
714
815
=== modified file 'src/launchpadlib/__init__.py'
--- src/launchpadlib/__init__.py 2011-01-18 22:33:53 +0000
+++ src/launchpadlib/__init__.py 2011-02-07 20:13:43 +0000
@@ -14,4 +14,4 @@
14# You should have received a copy of the GNU Lesser General Public License14# You should have received a copy of the GNU Lesser General Public License
15# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.15# along with launchpadlib. If not, see <http://www.gnu.org/licenses/>.
1616
17__version__ = '1.9.4'17__version__ = '1.9.5'
1818
=== modified file 'src/launchpadlib/launchpad.py'
--- src/launchpadlib/launchpad.py 2011-01-18 21:57:09 +0000
+++ src/launchpadlib/launchpad.py 2011-02-07 20:13:43 +0000
@@ -31,6 +31,7 @@
31 ScalarValue, # Re-import for client convenience31 ScalarValue, # Re-import for client convenience
32 ServiceRoot,32 ServiceRoot,
33 )33 )
34from lazr.restfulclient.authorize.oauth import SystemWideConsumer
34from lazr.restfulclient._browser import RestfulHttp35from lazr.restfulclient._browser import RestfulHttp
35from launchpadlib.credentials import (36from launchpadlib.credentials import (
36 AccessToken,37 AccessToken,
@@ -309,16 +310,18 @@
309 get_token_and_login() is removed, this code can be streamlined310 get_token_and_login() is removed, this code can be streamlined
310 and moved into its other call site, login_with().311 and moved into its other call site, login_with().
311 """312 """
312
313 if isinstance(consumer_name, Consumer):313 if isinstance(consumer_name, Consumer):
314 # Create the credentials with no Consumer, then set its .consumer314 consumer = consumer_name
315 # property directly.
316 credentials = Credentials(None)
317 credentials.consumer = consumer_name
318 else:315 else:
319 # Have the Credentials constructor create the Consumer316 # Create a system-wide consumer. lazr.restfulclient won't
320 # automatically.317 # do this automatically, but launchpadlib's default is to
321 credentials = Credentials(consumer_name)318 # do a desktop-wide integration.
319 consumer = SystemWideConsumer(consumer_name)
320
321 # Create the credentials with no Consumer, then set its .consumer
322 # property directly.
323 credentials = Credentials(None)
324 credentials.consumer = consumer
322 if authorization_engine is None:325 if authorization_engine is None:
323 authorization_engine = cls.authorization_engine_factory(326 authorization_engine = cls.authorization_engine_factory(
324 service_root, consumer_name, None, allow_access_levels)327 service_root, consumer_name, None, allow_access_levels)
@@ -335,7 +338,24 @@
335 credential_store.credential_save_failed,338 credential_store.credential_save_failed,
336 "credential_store")339 "credential_store")
337340
338 credentials = authorization_engine(credentials, credential_store)341 # Try to get the credentials out of the credential store.
342 cached_credentials = credential_store.load(
343 authorization_engine.unique_consumer_id)
344 if cached_credentials is None:
345 # They're not there. Acquire new credentials using the
346 # authorization engine.
347 credentials = authorization_engine(credentials, credential_store)
348 else:
349 # We acquired credentials. But, the application name
350 # wasn't stored along with the credentials, because in a
351 # desktop integration scenario, a single set of
352 # credentials may be shared by many applications. We need
353 # to set the application name for this specific instance
354 # of the credentials.
355 credentials = cached_credentials
356 credentials.consumer.application_name = (
357 authorization_engine.application_name)
358
339 return cls(credentials, authorization_engine, credential_store,359 return cls(credentials, authorization_engine, credential_store,
340 service_root, cache, timeout, proxy_info, version)360 service_root, cache, timeout, proxy_info, version)
341361
@@ -513,33 +533,11 @@
513 "allow_access_levels", allow_access_levels,533 "allow_access_levels", allow_access_levels,
514 authorization_engine.allow_access_levels)534 authorization_engine.allow_access_levels)
515535
516 credentials = credential_store.load(536 return cls._authorize_token_and_login(
517 authorization_engine.unique_consumer_id)537 authorization_engine.consumer, service_root,
518538 cache_path, timeout, proxy_info, authorization_engine,
519 if credentials is None:539 allow_access_levels, credential_store,
520 # Credentials were not found in the local store. Go540 credential_save_failed, version)
521 # through the authorization process.
522 launchpad = cls._authorize_token_and_login(
523 authorization_engine.consumer, service_root,
524 cache_path, timeout, proxy_info, authorization_engine,
525 allow_access_levels, credential_store,
526 credential_save_failed, version)
527 else:
528 # The application name wasn't stored locally, because in a
529 # desktop integration scenario, a single set of
530 # credentials may be shared by many applications. We need
531 # to set the application name for this specific instance
532 # of the credentials.
533 credentials.consumer.application_name = (
534 authorization_engine.application_name)
535
536 # Credentials were found in the local store. Create a
537 # Launchpad object.
538 launchpad = cls(
539 credentials, authorization_engine, credential_store,
540 service_root=service_root, cache=cache_path, timeout=timeout,
541 proxy_info=proxy_info, version=version)
542 return launchpad
543541
544 @classmethod542 @classmethod
545 def _warn_of_deprecated_login_method(cls, name):543 def _warn_of_deprecated_login_method(cls, name):

Subscribers

People subscribed via source and target branches