| 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 # Chromoting Directory API client implementation. Used for testing/debugging | 7 # Chromoting Directory API client implementation. Used for testing/debugging |
| 8 # purposes. Requires Python 2.6: json module is not available in earlier | 8 # purposes. Requires Python 2.6: json module is not available in earlier |
| 9 # versions. | 9 # versions. |
| 10 | 10 |
| 11 import os | 11 import os |
| 12 import httplib | 12 import httplib |
| 13 import json | 13 import json |
| 14 import urllib | 14 import urllib |
| 15 import urllib2 | 15 import urllib2 |
| 16 import random | 16 import random |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 DEFAULT_DIRECTORY_SERVER = 'www-googleapis-test.sandbox.google.com' | 19 DEFAULT_DIRECTORY_SERVER = 'www.googleapis.com' |
| 20 | 20 |
| 21 auth_filepath = os.path.join(os.path.expanduser('~'), | 21 auth_filepath = os.path.join(os.path.expanduser('~'), |
| 22 '.chromotingDirectoryAuthToken') | 22 '.chromotingDirectoryAuthToken') |
| 23 | 23 |
| 24 def random_uuid(): | 24 def random_uuid(): |
| 25 return ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x" % | 25 return ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x" % |
| 26 tuple(map(lambda x: random.randrange(0,65536), range(8)))) | 26 tuple(map(lambda x: random.randrange(0,65536), range(8)))) |
| 27 | 27 |
| 28 class Host: | 28 class Host: |
| 29 def __init__(self, parameters=None): | 29 def __init__(self, parameters=None): |
| (...skipping 21 matching lines...) Expand all Loading... |
| 51 Exception.__init__(self, message) | 51 Exception.__init__(self, message) |
| 52 print response | 52 print response |
| 53 self._response = response | 53 self._response = response |
| 54 | 54 |
| 55 class HostDirectory: | 55 class HostDirectory: |
| 56 def __init__(self, username, auth_token, server=DEFAULT_DIRECTORY_SERVER): | 56 def __init__(self, username, auth_token, server=DEFAULT_DIRECTORY_SERVER): |
| 57 self._username = username | 57 self._username = username |
| 58 self._auth_token = auth_token | 58 self._auth_token = auth_token |
| 59 self._base_url = '/chromoting/v1/@me/hosts' | 59 self._base_url = '/chromoting/v1/@me/hosts' |
| 60 | 60 |
| 61 self._http = httplib.HTTPConnection(server) | 61 self._http = httplib.HTTPSConnection(server) |
| 62 self._headers = {"Authorization": "GoogleLogin auth=" + self._auth_token, | 62 self._headers = {"Authorization": "GoogleLogin auth=" + self._auth_token, |
| 63 "Content-Type": "application/json" } | 63 "Content-Type": "application/json" } |
| 64 | 64 |
| 65 def add_host(self, host): | 65 def add_host(self, host): |
| 66 host_json = { 'data': | 66 host_json = { 'data': |
| 67 { 'hostId': host.host_id, | 67 { 'hostId': host.host_id, |
| 68 'hostName': host.host_name, | 68 'hostName': host.host_name, |
| 69 'publicKey': host.public_key, | 69 'publicKey': host.public_key, |
| 70 } | 70 } |
| 71 } | 71 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 raise CommandError("Unknown command: %s" % command); | 218 raise CommandError("Unknown command: %s" % command); |
| 219 | 219 |
| 220 except CommandError as e: | 220 except CommandError as e: |
| 221 sys.stderr.write("%s\n" % e.args[0]) | 221 sys.stderr.write("%s\n" % e.args[0]) |
| 222 return 1 | 222 return 1 |
| 223 | 223 |
| 224 return 0 | 224 return 0 |
| 225 | 225 |
| 226 if __name__ == '__main__': | 226 if __name__ == '__main__': |
| 227 sys.exit(main()) | 227 sys.exit(main()) |
| OLD | NEW |