blob: 58268e3f6ed213980eb4d36737a9992385aa7a09 [file] [log] [blame]
jamesren1a2914a2010-02-12 00:44:31 +00001"""
2This module provides utility functions useful when writing clients for the RPC
3server.
mblighe8819cd2008-02-15 16:48:40 +00004"""
5
6__author__ = 'showard@google.com (Steve Howard)'
7
jamesren1a2914a2010-02-12 00:44:31 +00008import getpass, os
mblighe8819cd2008-02-15 16:48:40 +00009from json_rpc import proxy
jamesren1a2914a2010-02-12 00:44:31 +000010from autotest_lib.client.common_lib import utils
11
mblighe8819cd2008-02-15 16:48:40 +000012
13def get_proxy(*args, **kwargs):
jamesren1a2914a2010-02-12 00:44:31 +000014 """Use this to access the AFE or TKO RPC interfaces."""
jadmanski0afbb632008-06-06 21:10:57 +000015 return proxy.ServiceProxy(*args, **kwargs)
jamesren1a2914a2010-02-12 00:44:31 +000016
17
18def _base_authorization_headers(username, server):
19 """
20 Don't call this directly, call authorization_headers().
21 This implementation may be overridden by site code.
22
23 @returns A dictionary of authorization headers to pass in to get_proxy().
24 """
25 if not username:
26 if 'AUTOTEST_USER' in os.environ:
27 username = os.environ['AUTOTEST_USER']
28 else:
29 username = getpass.getuser()
30 return {'AUTHORIZATION' : username}
31
32
33authorization_headers = utils.import_site_function(
34 __file__, 'autotest_lib.frontend.afe.site_rpc_client_lib',
35 'authorization_headers', _base_authorization_headers)