Add rpc to check if authorized to call a rpc: daemon.authorized_call()

This commit is contained in:
Andrew Resch 2010-09-04 12:31:27 -07:00
parent 4b92912577
commit 350d4d7260
2 changed files with 33 additions and 0 deletions

View File

@ -204,3 +204,18 @@ class Daemon(object):
Returns a list of the exported methods. Returns a list of the exported methods.
""" """
return self.rpcserver.get_method_list() return self.rpcserver.get_method_list()
@export(1)
def authorized_call(self, rpc):
"""
Returns True if authorized to call rpc.
:param rpc: a rpc, eg, "core.get_torrents_status"
:type rpc: string
"""
if not rpc in self.get_method_list():
return False
auth_level = self.rpcserver.get_session_auth_level()
return auth_level >= self.rpcserver.get_rpc_auth_level()

View File

@ -443,6 +443,24 @@ class RPCServer(component.Component):
# No connections made yet # No connections made yet
return "" return ""
def get_session_auth_level(self):
"""
Returns the auth level of the user calling the current RPC.
:returns: the auth level
:rtype: int
"""
return self.factory.authorized_sessions[self.get_session_id()][0]
def get_rpc_auth_level(self, rpc):
"""
Returns the auth level requirement for an exported rpc.
:returns: the auth level
:rtype: int
"""
self.factory.methods[rpc]._rpcserver_auth_level
def is_session_valid(self, session_id): def is_session_valid(self, session_id):
""" """
Checks if the session is still valid, eg, if the client is still connected. Checks if the session is still valid, eg, if the client is still connected.