Index: apply_issue.py |
diff --git a/apply_issue.py b/apply_issue.py |
index 2b7b334f51eb6f4bd4683341bb07824f2e412c78..41e133baa083b58e197da1dff879acee7133fee3 100755 |
--- a/apply_issue.py |
+++ b/apply_issue.py |
@@ -18,6 +18,7 @@ import urllib2 |
import breakpad # pylint: disable=W0611 |
import annotated_gclient |
+import auth |
import checkout |
import fix_encoding |
import gclient_utils |
@@ -56,13 +57,10 @@ def main(): |
help='File containing the email address to access rietveld. ' |
'If not specified, anonymous access will be used.') |
parser.add_option( |
- '-w', '--password', |
- help='Password for email addressed. Use - to read password from stdin. ' |
- 'if -k is provided, this is the private key file password.') |
- parser.add_option( |
'-k', '--private-key-file', |
help='Path to file containing a private key in p12 format for OAuth2 ' |
- 'authentication. Use -w to provide the decrypting password, if any.') |
+ 'authentication with "notasecret" password (as generated by Google ' |
+ 'Cloud Console).') |
parser.add_option( |
'-i', '--issue', type='int', help='Rietveld issue number') |
parser.add_option( |
@@ -92,13 +90,14 @@ def main(): |
help='Don\'t patch specified file(s).') |
parser.add_option('-d', '--ignore_deps', action='store_true', |
help='Don\'t run gclient sync on DEPS changes.') |
+ |
+ auth.add_auth_options(parser) |
options, args = parser.parse_args() |
+ auth_config = auth.extract_auth_config_from_options(options) |
if options.whitelist and options.blacklist: |
parser.error('Cannot specify both --whitelist and --blacklist') |
- if options.password and options.private_key_file: |
- parser.error('-k and -w options are incompatible') |
if options.email and options.email_file: |
parser.error('-e and -E options are incompatible') |
@@ -121,10 +120,6 @@ def main(): |
options.revision_mapping = json.loads(options.revision_mapping) |
- if options.password == '-': |
- print('Reading password') |
- options.password = sys.stdin.readline().strip() |
- |
# read email if needed |
if options.email_file: |
if not os.path.exists(options.email_file): |
@@ -138,11 +133,11 @@ def main(): |
# OAuth2 authentication |
obj = rietveld.JwtOAuth2Rietveld(options.server, |
options.email, |
- options.private_key_file, |
- private_key_password=options.password) |
+ options.private_key_file) |
properties = obj.get_issue_properties(options.issue, False) |
else: |
- obj = rietveld.Rietveld(options.server, '', None) |
+ # Passing None as auth_config disables authentication. |
+ obj = rietveld.Rietveld(options.server, None) |
properties = None |
# Bad except clauses order (HTTPError is an ancestor class of |
# ClientLoginError) |
@@ -156,26 +151,16 @@ def main(): |
exit('FAIL: Login detected -- is issue private?') |
# TODO(maruel): A few 'Invalid username or password.' are printed first, |
# we should get rid of those. |
- except rietveld.upload.ClientLoginError, e: |
+ except rietveld.upload.ClientLoginError as e: |
# Fine, we'll do proper authentication. |
pass |
if properties is None: |
- if options.email is not None: |
- obj = rietveld.Rietveld(options.server, options.email, options.password) |
- try: |
- properties = obj.get_issue_properties(options.issue, False) |
- except rietveld.upload.ClientLoginError, e: |
- if sys.stdout.closed: |
- print('Accessing the issue requires proper credentials.') |
- return 1 |
- else: |
- print('Accessing the issue requires login.') |
- obj = rietveld.Rietveld(options.server, None, None) |
- try: |
- properties = obj.get_issue_properties(options.issue, False) |
- except rietveld.upload.ClientLoginError, e: |
- print('Accessing the issue requires proper credentials.') |
- return 1 |
+ obj = rietveld.Rietveld(options.server, auth_config, options.email) |
+ try: |
+ properties = obj.get_issue_properties(options.issue, False) |
+ except rietveld.upload.ClientLoginError as e: |
+ print('Accessing the issue requires proper credentials.') |
+ return 1 |
if not options.patchset: |
options.patchset = properties['patchsets'][-1] |
@@ -184,7 +169,7 @@ def main(): |
print('Downloading the patch.') |
try: |
patchset = obj.get_patch(options.issue, options.patchset) |
- except urllib2.HTTPError, e: |
+ except urllib2.HTTPError as e: |
print( |
'Failed to fetch the patch for issue %d, patchset %d.\n' |
'Try visiting %s/%d') % ( |
@@ -222,7 +207,7 @@ def main(): |
print('\nApplying the patch.') |
try: |
scm_obj.apply_patch(patchset, verbose=True) |
- except checkout.PatchApplicationFailed, e: |
+ except checkout.PatchApplicationFailed as e: |
print(str(e)) |
print('CWD=%s' % os.getcwd()) |
print('Checkout path=%s' % scm_obj.project_path) |