Merge lp:~veebers/ubuntu-community-testing/choose_staging_or_actual_login into lp:ubuntu-community-testing

Proposed by Christopher Lee on 2015-08-18
Status: Merged
Merged at revision: 28
Proposed branch: lp:~veebers/ubuntu-community-testing/choose_staging_or_actual_login
Merge into: lp:ubuntu-community-testing
Diff against target: 92 lines (+31/-10)
2 files modified
tools/upload_results.py (+22/-7)
ubuntu_pt_community/auth/sso.py (+9/-3)
To merge this branch: bzr merge lp:~veebers/ubuntu-community-testing/choose_staging_or_actual_login
Reviewer Review Type Date Requested Status
Ubuntu Testcase Admins 2015-08-18 Pending
Review via email: mp+268286@code.launchpad.net

Commit message

Using actual login server in production (staging otherwise).

Description of the change

Using actual login server in production (staging otherwise).

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 'tools/upload_results.py'
2--- tools/upload_results.py 2015-08-17 08:46:22 +0000
3+++ tools/upload_results.py 2015-08-18 03:47:59 +0000
4@@ -49,10 +49,15 @@
5 '--email',
6 help='Email address to use for logging in. If not provided you will be prompted for it.' # NOQA
7 )
8+ arg_parser.add_argument(
9+ '--staging',
10+ help='If set use staging login server. (Only useful for testing.)',
11+ action='store_true'
12+ )
13 return arg_parser.parse_args()
14
15
16-def attempt_ubuntu_sso_login(email_address, password, otp=None):
17+def attempt_ubuntu_sso_login(email_address, password, staging=False, otp=None):
18 """Obtain OAuth token that can be used to authenticate with transport
19 end-points.
20
21@@ -80,8 +85,9 @@
22 'Accept': 'application/json',
23 }
24
25- # sso_base_url = 'https://login.ubuntu.com/api/v2'
26- sso_base_url = 'https://login.staging.ubuntu.com/api/v2'
27+ sso_base_url = 'https://login.ubuntu.com/api/v2'
28+ if staging:
29+ sso_base_url = 'https://login.staging.ubuntu.com/api/v2'
30 sso_url = '{}/tokens/oauth'.format(sso_base_url)
31
32 response = requests.post(
33@@ -131,21 +137,30 @@
34
35 def get_upload_details():
36 args = parse_args()
37- return (args.file, args.url, args.email)
38+ return (args.file, args.url, args.email, args.staging)
39
40
41 if __name__ == '__main__':
42- file_path, url, email = get_upload_details()
43+ file_path, url, email, use_staging = get_upload_details()
44+
45+ if use_staging:
46+ print("Using staging server")
47+
48 if email is None:
49 email = input('Email address: ')
50
51 password = getpass.getpass('Password: ')
52
53 try:
54- oauth_creds = attempt_ubuntu_sso_login(email, password)
55+ oauth_creds = attempt_ubuntu_sso_login(email, password, use_staging)
56 except TwoFactorRequiredError:
57 otp = input('Your next 2fa code: ').strip()
58- oauth_creds = attempt_ubuntu_sso_login(email, password, otp=otp)
59+ oauth_creds = attempt_ubuntu_sso_login(
60+ email,
61+ password,
62+ use_staging,
63+ otp=otp
64+ )
65 except InvalidCredentialsError:
66 print('ERROR: Invalid credentials')
67
68
69=== modified file 'ubuntu_pt_community/auth/sso.py'
70--- ubuntu_pt_community/auth/sso.py 2015-08-18 00:55:26 +0000
71+++ ubuntu_pt_community/auth/sso.py 2015-08-18 03:47:59 +0000
72@@ -20,11 +20,17 @@
73
74 import json
75 import requests
76+import logging
77+import os
78 from werkzeug.exceptions import Unauthorized
79
80-# SSO_BASE_URL = 'https://login.ubuntu.com/api/v2'
81-# Use the following for SSO staging:
82-SSO_BASE_URL = 'https://login.staging.ubuntu.com/api/v2'
83+logger = logging.getLogger(__name__)
84+
85+# Use staging if we running devel.
86+SSO_BASE_URL = 'https://login.ubuntu.com/api/v2'
87+if os.environ.get('DEPLOY_STAGE', 'production') == 'devel':
88+ # Use the following for SSO staging:
89+ SSO_BASE_URL = 'https://login.staging.ubuntu.com/api/v2'
90
91
92 JSON_HEADERS = {

Subscribers

People subscribed via source and target branches