Merge lp:~leonardr/lazr.restfulclient/system-wide-consumer into lp:lazr.restfulclient
Status: | Merged |
---|---|
Merged at revision: | 110 |
Proposed branch: | lp:~leonardr/lazr.restfulclient/system-wide-consumer |
Merge into: | lp:lazr.restfulclient |
Diff against target: |
217 lines (+157/-1) 3 files modified
src/lazr/restfulclient/NEWS.txt (+5/-1) src/lazr/restfulclient/authorize/oauth.py (+46/-0) src/lazr/restfulclient/tests/test_oauth.py (+106/-0) |
To merge this branch: | bzr merge lp:~leonardr/lazr.restfulclient/system-wide-consumer |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Edwin Grubbs (community) | code | Approve | |
Review via email: mp+39552@code.launchpad.net |
Description of the change
This branch introduces the SystemWideConsumer class. With a normal OAuth consumer, you specify the consumer key (the name of your application). With the SystemWideConsumer, the consumer key is automatically derived from your platform (eg. "Ubuntu") and the hostname of your computer. You still specify an "application name", but it's only present in the User-Agent. It's not used in OAuth.
The purpose of this mighty consumer is to integrate an entire desktop with a web service, rather than having to integrate each application individually. The KEY_FORMAT happens to be the format that Launchpad recognizes as a system-wide consumer key, but the code is generic--it (or a simple subclass) could work for any lazr.restful service, whether or not it specifically recognizes system-wide keys.
If KEY_FORMAT bothers you because of its Launchpad-
Hi Leonard,
This is a nice branch. I just have one concern listed below.
-Edwin
>=== modified file 'src/lazr/ restfulclient/ authorize/ oauth.py' restfulclient/ authorize/ oauth.py 2010-10-28 15:49:09 +0000 restfulclient/ authorize/ oauth.py 2010-10-28 20:57:14 +0000 mer(Consumer) : eConsumer, self).__init__( linux_distribut ion()
>--- src/lazr/
>+++ src/lazr/
>@@ -73,6 +76,49 @@
> self.context = context
>
>
>+class SystemWideConsu
>+ """A consumer associated with the logged-in user rather than an app.
>+
>+ This can be used to share a single OAuth token among multiple
>+ desktop applications. The OAuth consumer key will be derived from
>+ system information (platform and hostname).
>+ """
>+ KEY_FORMAT = "System-wide: %s (%s)"
>+
>+ def __init__(self, application_name, secret=''):
>+ """Constructor.
>+
>+ :param application_name: An application name. This will be
>+ used in the User-Agent header.
>+ :param secret: The OAuth consumer secret. Don't use this. It's
>+ a misfeature, and lazr.restful doesn't expect it.
>+ """
>+ super(SystemWid
>+ self.consumer_key, secret, application_name)
>+
>+ @property
>+ def consumer_key(self):
>+ """The system-wide OAuth consumer key for this computer.
>+
>+ This key identifies the platform and the computer's
>+ hostname. It does not identify the active user.
>+ """
>+ try:
>+ distname, version, release_id = platform.
>+ except Exception, e:
>+ # This can happen in pre-2.6 versions of Python.
>+ try:
>+ distname, version, release_id = platform.dist()
There appears to be an annoying bug in some versions of python where platform.dist() will randomly get its data from either /etc/debian_version or /etc/lsb-release. Since lsb-release has the more accurate info, it might be worthwhile to use "/usr/bin/ lsb_release -si" when that executable exists.
http:// bugs.python. org/issue9514
>+ except Exception, e: ion() or gethostname( ))
>+ # This should never happen--non-Linux platforms return
>+ # empty strings from linux_distribut
>+ # dist()--but just in case.
>+ distname = ''
>+ if distname == '':
>+ distname = platform.system() # (eg. "Windows")
>+ return self.KEY_FORMAT % (distname, socket.
>+
>+