1""" 2This module provides utility functions useful when writing clients for the RPC 3server. 4""" 5 6__author__ = 'showard@google.com (Steve Howard)' 7 8import getpass, os 9from json_rpc import proxy 10from autotest_lib.client.common_lib import utils 11 12 13class AuthError(Exception): 14 pass 15 16 17def get_proxy(*args, **kwargs): 18 """Use this to access the AFE or TKO RPC interfaces.""" 19 return proxy.ServiceProxy(*args, **kwargs) 20 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) 40