Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Unified Diff: bin/cros_gsdcurl.py

Issue 3060043: Making default to LOGNAME work correctly. (Closed) Base URL: ssh://git@chromiumos-git/crosutils.git
Patch Set: fix Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cros_download_latest_image » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/cros_gsdcurl.py
diff --git a/bin/cros_gsdcurl.py b/bin/cros_gsdcurl.py
new file mode 100755
index 0000000000000000000000000000000000000000..e046fe2795e84c20d90940d6f38c3e9606750f41
--- /dev/null
+++ b/bin/cros_gsdcurl.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+import getpass
+import os
+import re
+import subprocess
+import sys
+import tempfile
+import urllib
+
+
+def Authenticate():
+ # Authenticate.
+ default_username = os.environ.get('LOGNAME', '')
jrbarnette 2010/08/04 01:31:40 What's wrong with getpass.getuser()?
+ username = os.environ.get('GSDCURL_USERNAME')
+ if username is None:
+ sys.stderr.write('Username [' + default_username + ']: ')
+ username = raw_input()
+ if username == '':
+ username = default_username + '@google.com'
+ elif '@' not in username:
+ username = username + '@google.com'
+ passwd = os.environ.get('GSDCURL_PASSWORD')
+ if passwd is None:
+ sys.stderr.write('Password: ')
+ passwd = urllib.quote_plus(getpass.getpass(prompt=''))
+ cmd = [
+ 'curl', '--silent', 'https://www.google.com/accounts/ClientLogin',
+ '-d', 'Email=' + username,
+ '-d', 'Passwd=' + passwd,
+ '-d', 'accountType=GOOGLE',
+ '-d', 'source=Google-gsdcurl-ver1',
+ '-d', 'service=cds',
+ ]
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ (p_stdout, _) = p.communicate()
+ assert p.returncode == 0
+ m = re.search('\nAuth=([^\n]+)\n', p_stdout)
+ if not m:
+ sys.stderr.write('BAD LOGIN\n')
+ sys.exit(1)
+ auth = m.group(1)
+ return auth
+
+
+def DoCurl(auth, argv):
+ (_, cookies) = tempfile.mkstemp(prefix='gsdcookie')
+ cmd = [
+ 'curl', '-L',
+ '-b', cookies, '-c', cookies,
+ '--header', 'Authorization: GoogleLogin auth=' + auth,
+ ] + argv[1:]
+ try:
+ p = subprocess.Popen(cmd)
+ return p.wait()
+ finally:
+ os.remove(cookies)
+
+
+def main(argv):
+ auth = Authenticate()
+ return DoCurl(auth, argv)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | cros_download_latest_image » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698