OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 server = 'www-googleapis-test.sandbox.google.com' | 21 server = 'www-googleapis-test.sandbox.google.com' |
22 url = 'http://' + server + '/chromoting/v1/@me/hosts' | 22 url = 'http://' + server + '/chromoting/v1/@me/hosts' |
23 | 23 |
24 settings_filepath = os.path.join(os.path.expanduser('~'), | 24 settings_filepath = os.path.join(os.path.expanduser('~'), |
25 '.ChromotingConfig.json') | 25 '.ChromotingConfig.json') |
26 | 26 |
27 print "Email:", | 27 print "Email:", |
28 email = raw_input() | 28 email = raw_input() |
29 password = getpass.getpass("Password: ") | 29 password = getpass.getpass("Password: ") |
30 | 30 |
31 xapi_auth = gaia_auth.GaiaAuthenticator('xapi') | 31 xapi_auth = gaia_auth.GaiaAuthenticator('chromoting') |
32 xapi_token = xapi_auth.authenticate(email, password) | 32 xapi_token = xapi_auth.authenticate(email, password) |
33 | 33 |
34 host_id = str(uuid.uuid1()) | 34 host_id = str(uuid.uuid1()) |
35 print "HostId:", host_id | 35 print "HostId:", host_id |
36 host_name = socket.gethostname() | 36 host_name = socket.gethostname() |
37 print "HostName:", host_name | 37 print "HostName:", host_name |
38 | 38 |
39 print "Generating RSA key pair...", | 39 print "Generating RSA key pair...", |
40 (private_key, public_key) = keygen.generateRSAKeyPair() | 40 (private_key, public_key) = keygen.generateRSAKeyPair() |
41 print "Done" | 41 print "Done" |
42 | 42 |
43 params = ('{"data":{' + \ | 43 params = ('{"data":{' + \ |
44 '"host_id": "%(host_id)s",' + \ | 44 '"hostId": "%(hostId)s",' + \ |
45 '"host_name": "%(host_name)s",' + \ | 45 '"hostName": "%(hostName)s",' + \ |
46 '"public_key": "%(public_key)s"}}') % \ | 46 '"publicKey": "%(publicKey)s"}}') % \ |
47 {'host_id': host_id, 'host_name': host_name, | 47 {'hostId': host_id, 'hostName': host_name, |
48 'public_key': public_key} | 48 'publicKey': public_key} |
49 headers = {"Authorization": "GoogleLogin auth=" + xapi_token, | 49 headers = {"Authorization": "GoogleLogin auth=" + xapi_token, |
50 "Content-Type": "application/json" } | 50 "Content-Type": "application/json" } |
51 request = urllib2.Request(url, params, headers) | 51 request = urllib2.Request(url, params, headers) |
52 | 52 |
53 opener = urllib2.OpenerDirector() | 53 opener = urllib2.OpenerDirector() |
54 opener.add_handler(urllib2.HTTPDefaultErrorHandler()) | 54 opener.add_handler(urllib2.HTTPDefaultErrorHandler()) |
55 | 55 |
56 print | 56 print |
57 print "Registering host with directory service..." | 57 print "Registering host with directory service..." |
58 try: | 58 try: |
(...skipping 16 matching lines...) Expand all Loading... |
75 settings_file.write('{\n'); | 75 settings_file.write('{\n'); |
76 settings_file.write(' "xmpp_login" : "' + email + '",\n') | 76 settings_file.write(' "xmpp_login" : "' + email + '",\n') |
77 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n') | 77 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n') |
78 settings_file.write(' "host_id" : "' + host_id + '",\n') | 78 settings_file.write(' "host_id" : "' + host_id + '",\n') |
79 settings_file.write(' "host_name" : "' + host_name + '",\n') | 79 settings_file.write(' "host_name" : "' + host_name + '",\n') |
80 settings_file.write(' "private_key" : "' + private_key + '",\n') | 80 settings_file.write(' "private_key" : "' + private_key + '",\n') |
81 settings_file.write('}\n') | 81 settings_file.write('}\n') |
82 settings_file.close() | 82 settings_file.close() |
83 | 83 |
84 print 'Configuration saved in', settings_filepath | 84 print 'Configuration saved in', settings_filepath |
OLD | NEW |