Home | History | Annotate | Download | only in afe
      1 """
      2 This module provides utility functions useful when writing clients for the RPC
      3 server.
      4 """
      5 
      6 __author__ = 'showard (at] google.com (Steve Howard)'
      7 
      8 import getpass, os
      9 from json_rpc import proxy
     10 from autotest_lib.client.common_lib import utils
     11 
     12 
     13 class AuthError(Exception):
     14     pass
     15 
     16 
     17 def get_proxy(*args, **kwargs):
     18     """Use this to access the AFE or TKO RPC interfaces."""
     19     return proxy.ServiceProxy(*args, **kwargs)
     20 
     21 
     22 def _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 
     37 authorization_headers = utils.import_site_function(
     38         __file__, 'autotest_lib.frontend.afe.site_rpc_client_lib',
     39         'authorization_headers', _base_authorization_headers)
     40