Merge lp:~blr/launchpadlib/auth-token-script into lp:launchpadlib

Proposed by Kit Randel
Status: Rejected
Rejected by: Colin Watson
Proposed branch: lp:~blr/launchpadlib/auth-token-script
Merge into: lp:launchpadlib
Diff against target: 101 lines (+56/-7)
2 files modified
setup.py (+3/-0)
src/launchpadlib/bin/launchpad-request-token (+53/-7)
To merge this branch: bzr merge lp:~blr/launchpadlib/auth-token-script
Reviewer Review Type Date Requested Status
LAZR Developers Pending
Review via email: mp+301600@code.launchpad.net

Commit message

* Teach launchpad-request-token to also generate access tokens.
* Install launchpad-request-token.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

launchpadlib has moved to git (https://code.launchpad.net/launchpadlib/+git). Sorry for not reviewing this in a timely fashion; if this is still relevant, then please update your branch and re-propose it against the git repository.

Unmerged revisions

157. By Kit Randel

Whitespace

156. By Kit Randel

Correct usage.

155. By Kit Randel

Call print func.

154. By Kit Randel

Remove unused import.

153. By Kit Randel

Install launchpad-request-token script.

152. By Kit Randel

Teach launchpad-request-token to also generate access tokens.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'setup.py'
--- setup.py 2014-07-04 14:55:48 +0000
+++ setup.py 2016-07-31 23:28:12 +0000
@@ -76,5 +76,8 @@
76 "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",76 "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
77 "Operating System :: OS Independent",77 "Operating System :: OS Independent",
78 "Programming Language :: Python"],78 "Programming Language :: Python"],
79 scripts=[
80 'src/launchpadlib/bin/launchpad-request-token',
81 ],
79 test_suite='launchpadlib.tests',82 test_suite='launchpadlib.tests',
80 )83 )
8184
=== modified file 'src/launchpadlib/bin/launchpad-request-token'
--- src/launchpadlib/bin/launchpad-request-token 2009-10-27 15:58:44 +0000
+++ src/launchpadlib/bin/launchpad-request-token 2016-07-31 23:28:12 +0000
@@ -1,6 +1,6 @@
1#!/usr/bin/python1#!/usr/bin/env python
22
3# Copyright 2009 Canonical Ltd.3# Copyright 2016 Canonical Ltd.
44
5# This file is part of launchpadlib.5# This file is part of launchpadlib.
6#6#
@@ -25,10 +25,46 @@
25__metaclass__ = type25__metaclass__ = type
2626
27from optparse import OptionParser27from optparse import OptionParser
28import time
29
28from launchpadlib.apps import RequestTokenApp30from launchpadlib.apps import RequestTokenApp
31from launchpadlib.credentials import Credentials
32from launchpadlib.uris import lookup_service_root
33from lazr.restfulclient.errors import HTTPError
34
35
36def print_local_settings(web_root, key, token, secret):
37 """Print access token settings in YAML format."""
38 print("\nAn access token has been generated with the following settings:"
39 "\n\n"
40 "LP_API_URL = '{api_url}'\n"
41 "LP_API_CONSUMER_KEY = '{key}'\n"
42 "LP_API_TOKEN = '{token}'\n"
43 "LP_API_TOKEN_SECRET = '{secret}'").format(
44 api_url=lookup_service_root(web_root),
45 key=key,
46 token=token,
47 secret=secret)
48
49
50def create_access_token(consumer_name, web_root, context=None):
51 credentials = Credentials(consumer_name)
52 authorise_url = credentials.get_request_token(
53 web_root=web_root, context=context)
54 print('\nPlease ensure you are logged in and visit {} to '
55 'authorise this request...'.format(authorise_url))
56 while True:
57 try:
58 credentials.exchange_request_token_for_access_token(
59 web_root=web_root)
60 return credentials.access_token
61 except HTTPError:
62 time.sleep(0.5)
63
2964
30parser = OptionParser()65parser = OptionParser()
31parser.usage = "%prog CONSUMER_NAME [-r SITE NAME] [-c CONTEXT]"66parser.usage = ("%prog CONSUMER_NAME [-s SITE NAME]"
67 "[-c CONTEXT] [--generate-access-token]")
32parser.add_option("-s", "--site", dest="web_root",68parser.add_option("-s", "--site", dest="web_root",
33 help=("The name of the Launchpad site to ask for a request "69 help=("The name of the Launchpad site to ask for a request "
34 "token (default: %default). This can also be the "70 "token (default: %default). This can also be the "
@@ -36,13 +72,23 @@
36 metavar="SITE", default="staging")72 metavar="SITE", default="staging")
37parser.add_option("-c", "--context", dest="context",73parser.add_option("-c", "--context", dest="context",
38 help="Restrict the token to a specific context "74 help="Restrict the token to a specific context "
39 "(example: firefox)", metavar="CONTEXT", default="")75 "(example: firefox)", metavar="CONTEXT", default=None)
76parser.add_option("--generate-access-token", action="store_true",
77 dest="access_token",
78 help="Generate an access token.")
79
4080
41if __name__ == '__main__':81if __name__ == '__main__':
42 (options, args) = parser.parse_args()82 (options, args) = parser.parse_args()
43 if len(args) < 1:83 if len(args) < 1:
44 parser.error("No consumer name supplied")84 parser.error("No consumer name supplied")
45 consumer_name = args[0]85 consumer_name = args[0]
46 app = RequestTokenApp(86 if options.access_token:
47 options.web_root, consumer_name, options.context)87 access_token = create_access_token(
48 print app.run()88 consumer_name, options.web_root, options.context)
89 print_local_settings(options.web_root, consumer_name,
90 access_token.key, access_token.secret)
91 else:
92 app = RequestTokenApp(options.web_root, consumer_name, options.context)
93 request_token = app.run()
94 print(request_token)

Subscribers

People subscribed via source and target branches