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

Side by Side Diff: remoting/tools/register_host.py

Issue 3133014: Added hostdir.py - a simple Chromoting Directory client. (Closed)
Patch Set: - Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « remoting/tools/hostdir.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # register_host.py registers new hosts in chromoting directory. It 7 # register_host.py registers new hosts in chromoting directory. It
8 # asks for username/password and then writes these settings to config file. 8 # asks for username/password and then writes these settings to config file.
9 9
10 import getpass 10 import getpass
(...skipping 14 matching lines...) Expand all
25 server = 'www-googleapis-test.sandbox.google.com' 25 server = 'www-googleapis-test.sandbox.google.com'
26 url = 'http://' + server + '/chromoting/v1/@me/hosts' 26 url = 'http://' + server + '/chromoting/v1/@me/hosts'
27 27
28 settings_filepath = os.path.join(os.path.expanduser('~'), 28 settings_filepath = os.path.join(os.path.expanduser('~'),
29 '.ChromotingConfig.json') 29 '.ChromotingConfig.json')
30 30
31 print "Email:", 31 print "Email:",
32 email = raw_input() 32 email = raw_input()
33 password = getpass.getpass("Password: ") 33 password = getpass.getpass("Password: ")
34 34
35 xapi_auth = gaia_auth.GaiaAuthenticator('chromoting') 35 chromoting_auth = gaia_auth.GaiaAuthenticator('chromoting')
36 xapi_token = xapi_auth.authenticate(email, password) 36 auth_token = chromoting_auth.authenticate(email, password)
37 37
38 host_id = random_uuid() 38 host_id = random_uuid()
39 print "HostId:", host_id 39 print "HostId:", host_id
40 host_name = socket.gethostname() 40 host_name = socket.gethostname()
41 print "HostName:", host_name 41 print "HostName:", host_name
42 42
43 print "Generating RSA key pair...", 43 print "Generating RSA key pair...",
44 (private_key, public_key) = keygen.generateRSAKeyPair() 44 (private_key, public_key) = keygen.generateRSAKeyPair()
45 print "Done" 45 print "Done"
46 46
47 params = ('{"data":{' + \ 47 params = ('{"data":{' + \
48 '"hostId": "%(hostId)s",' + \ 48 '"hostId": "%(hostId)s",' + \
49 '"hostName": "%(hostName)s",' + \ 49 '"hostName": "%(hostName)s",' + \
50 '"publicKey": "%(publicKey)s"}}') % \ 50 '"publicKey": "%(publicKey)s"}}') % \
51 {'hostId': host_id, 'hostName': host_name, 51 {'hostId': host_id, 'hostName': host_name,
52 'publicKey': public_key} 52 'publicKey': public_key}
53 headers = {"Authorization": "GoogleLogin auth=" + xapi_token, 53 headers = {"Authorization": "GoogleLogin auth=" + auth_token,
54 "Content-Type": "application/json" } 54 "Content-Type": "application/json" }
55 request = urllib2.Request(url, params, headers) 55 request = urllib2.Request(url, params, headers)
56 56
57 opener = urllib2.OpenerDirector() 57 opener = urllib2.OpenerDirector()
58 opener.add_handler(urllib2.HTTPDefaultErrorHandler()) 58 opener.add_handler(urllib2.HTTPDefaultErrorHandler())
59 59
60 print 60 print
61 print "Registering host with directory service..." 61 print "Registering host with directory service..."
62 try: 62 try:
63 res = urllib2.urlopen(request) 63 res = urllib2.urlopen(request)
(...skipping 15 matching lines...) Expand all
79 settings_file.write('{\n'); 79 settings_file.write('{\n');
80 settings_file.write(' "xmpp_login" : "' + email + '",\n') 80 settings_file.write(' "xmpp_login" : "' + email + '",\n')
81 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n') 81 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n')
82 settings_file.write(' "host_id" : "' + host_id + '",\n') 82 settings_file.write(' "host_id" : "' + host_id + '",\n')
83 settings_file.write(' "host_name" : "' + host_name + '",\n') 83 settings_file.write(' "host_name" : "' + host_name + '",\n')
84 settings_file.write(' "private_key" : "' + private_key + '",\n') 84 settings_file.write(' "private_key" : "' + private_key + '",\n')
85 settings_file.write('}\n') 85 settings_file.write('}\n')
86 settings_file.close() 86 settings_file.close()
87 87
88 print 'Configuration saved in', settings_filepath 88 print 'Configuration saved in', settings_filepath
OLDNEW
« no previous file with comments | « remoting/tools/hostdir.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698