remove authjsonrpc subhandlers. we dont use them

This commit is contained in:
Alex Grintsvayg 2017-01-09 19:34:01 -05:00
parent 05725e0dc9
commit 5c429e15bd
2 changed files with 1 additions and 34 deletions

View file

@ -96,9 +96,5 @@ class InvalidAuthenticationToken(Exception):
pass pass
class SubhandlerError(Exception):
pass
class NegotiationError(Exception): class NegotiationError(Exception):
pass pass

View file

@ -8,7 +8,7 @@ from twisted.internet import defer
from twisted.python.failure import Failure from twisted.python.failure import Failure
from txjsonrpc import jsonrpclib from txjsonrpc import jsonrpclib
from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError, SubhandlerError from lbrynet.core.Error import InvalidAuthenticationToken, InvalidHeaderError
from lbrynet import conf from lbrynet import conf
from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message from lbrynet.lbrynet_daemon.auth.util import APIKey, get_auth_message
from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET
@ -36,7 +36,6 @@ class JSONRPCException(Exception):
class AuthorizedBase(object): class AuthorizedBase(object):
def __init__(self): def __init__(self):
self.authorized_functions = [] self.authorized_functions = []
self.subhandlers = []
self.callable_methods = {} self.callable_methods = {}
for methodname in dir(self): for methodname in dir(self):
@ -45,21 +44,12 @@ class AuthorizedBase(object):
self.callable_methods.update({methodname.split("jsonrpc_")[1]: method}) self.callable_methods.update({methodname.split("jsonrpc_")[1]: method})
if hasattr(method, '_auth_required'): if hasattr(method, '_auth_required'):
self.authorized_functions.append(methodname.split("jsonrpc_")[1]) self.authorized_functions.append(methodname.split("jsonrpc_")[1])
elif not methodname.startswith("__"):
method = getattr(self, methodname)
if hasattr(method, '_subhandler'):
self.subhandlers.append(method)
@staticmethod @staticmethod
def auth_required(f): def auth_required(f):
f._auth_required = True f._auth_required = True
return f return f
@staticmethod
def subhandler(f):
f._subhandler = True
return f
class AuthJSONRPCServer(AuthorizedBase): class AuthJSONRPCServer(AuthorizedBase):
"""Authorized JSONRPC server used as the base class for the LBRY API """Authorized JSONRPC server used as the base class for the LBRY API
@ -71,12 +61,6 @@ class AuthJSONRPCServer(AuthorizedBase):
@AuthJSONRPCServer.auth_required: this requires the client @AuthJSONRPCServer.auth_required: this requires the client
include a valid hmac authentication token in their request include a valid hmac authentication token in their request
@AuthJSONRPCServer.subhandler: include the tagged method in
the processing of requests, to allow inheriting classes to
modify request handling. Tagged methods will be passed the
request object, and return True when finished to indicate
success
Attributes: Attributes:
allowed_during_startup (list): list of api methods that are allowed_during_startup (list): list of api methods that are
callable before the server has finished startup callable before the server has finished startup
@ -86,8 +70,6 @@ class AuthJSONRPCServer(AuthorizedBase):
authorized_functions (list): list of api methods that require authentication authorized_functions (list): list of api methods that require authentication
subhandlers (list): list of subhandlers
callable_methods (dict): dictionary of api_callable_name: method values callable_methods (dict): dictionary of api_callable_name: method values
""" """
@ -159,12 +141,6 @@ class AuthJSONRPCServer(AuthorizedBase):
token = parsed.pop('hmac', None) token = parsed.pop('hmac', None)
version = self._get_jsonrpc_version(parsed.get('jsonrpc'), id_) version = self._get_jsonrpc_version(parsed.get('jsonrpc'), id_)
try:
self._run_subhandlers(request)
except SubhandlerError as err:
self._render_error(err, request, id_, version)
return server.NOT_DONE_YET
reply_with_next_secret = False reply_with_next_secret = False
if self._use_authentication: if self._use_authentication:
if function_name in self.authorized_functions: if function_name in self.authorized_functions:
@ -302,11 +278,6 @@ class AuthJSONRPCServer(AuthorizedBase):
version_for_return = jsonrpclib.VERSION_PRE1 version_for_return = jsonrpclib.VERSION_PRE1
return version_for_return return version_for_return
def _run_subhandlers(self, request):
for handler in self.subhandlers:
if not handler(request):
raise SubhandlerError("Subhandler error processing request: %s", request)
def _callback_render(self, result, request, id_, version, auth_required=False): def _callback_render(self, result, request, id_, version, auth_required=False):
result_for_return = result if not isinstance(result, dict) else result['result'] result_for_return = result if not isinstance(result, dict) else result['result']