Move the cli RPC authorization_headers code into rpc_client_lib.
Make autotest_lib.server.frontend use it for RPC authentication.
Signed-off-by: Gregory Smith <gps@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4231 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/rpc_client_lib.py b/frontend/afe/rpc_client_lib.py
index 1707e04..58268e3 100644
--- a/frontend/afe/rpc_client_lib.py
+++ b/frontend/afe/rpc_client_lib.py
@@ -1,11 +1,35 @@
-"""\
-This module provides a get_proxy() function, which should be used to access
-the afe RPC server.
+"""
+This module provides utility functions useful when writing clients for the RPC
+server.
"""
__author__ = 'showard@google.com (Steve Howard)'
+import getpass, os
from json_rpc import proxy
+from autotest_lib.client.common_lib import utils
+
def get_proxy(*args, **kwargs):
+ """Use this to access the AFE or TKO RPC interfaces."""
return proxy.ServiceProxy(*args, **kwargs)
+
+
+def _base_authorization_headers(username, server):
+ """
+ Don't call this directly, call authorization_headers().
+ This implementation may be overridden by site code.
+
+ @returns A dictionary of authorization headers to pass in to get_proxy().
+ """
+ if not username:
+ if 'AUTOTEST_USER' in os.environ:
+ username = os.environ['AUTOTEST_USER']
+ else:
+ username = getpass.getuser()
+ return {'AUTHORIZATION' : username}
+
+
+authorization_headers = utils.import_site_function(
+ __file__, 'autotest_lib.frontend.afe.site_rpc_client_lib',
+ 'authorization_headers', _base_authorization_headers)