blob: 2dd3e1763a928b8ea133d7055410eb4325a38af0 [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
mblighb68405d2010-03-11 18:32:39 +000013class AuthError(Exception):
14 pass
15
16
mblighe8819cd2008-02-15 16:48:40 +000017def get_proxy(*args, **kwargs):
jamesren1a2914a2010-02-12 00:44:31 +000018 """Use this to access the AFE or TKO RPC interfaces."""
jadmanski0afbb632008-06-06 21:10:57 +000019 return proxy.ServiceProxy(*args, **kwargs)
jamesren1a2914a2010-02-12 00:44:31 +000020
21
22def _base_authorization_headers(username, server):
23 """
24 Don't call this directly, call authorization_headers().
25 This implementation may be overridden by site code.
26
27 @returns A dictionary of authorization headers to pass in to get_proxy().
28 """
29 if not username:
30 if 'AUTOTEST_USER' in os.environ:
31 username = os.environ['AUTOTEST_USER']
32 else:
33 username = getpass.getuser()
34 return {'AUTHORIZATION' : username}
35
36
37authorization_headers = utils.import_site_function(
38 __file__, 'autotest_lib.frontend.afe.site_rpc_client_lib',
39 'authorization_headers', _base_authorization_headers)