Skip to content

Commit

Permalink
remove authjsonrpc subhandlers. we dont use them
Browse files Browse the repository at this point in the history
  • Loading branch information
lyoshenka committed Jan 10, 2017
1 parent 313e795 commit 21daadb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
4 changes: 0 additions & 4 deletions lbrynet/core/Error.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,5 @@ class InvalidAuthenticationToken(Exception):
pass


class SubhandlerError(Exception):
pass


class NegotiationError(Exception):
pass
31 changes: 1 addition & 30 deletions lbrynet/lbrynet_daemon/auth/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from twisted.python.failure import Failure

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.lbrynet_daemon.auth.util import APIKey, get_auth_message
from lbrynet.lbrynet_daemon.auth.client import LBRY_SECRET
Expand Down Expand Up @@ -36,7 +36,6 @@ def faultString(self):
class AuthorizedBase(object):
def __init__(self):
self.authorized_functions = []
self.subhandlers = []
self.callable_methods = {}

for methodname in dir(self):
Expand All @@ -45,21 +44,12 @@ def __init__(self):
self.callable_methods.update({methodname.split("jsonrpc_")[1]: method})
if hasattr(method, '_auth_required'):
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
def auth_required(f):
f._auth_required = True
return f

@staticmethod
def subhandler(f):
f._subhandler = True
return f


class AuthJSONRPCServer(AuthorizedBase):
"""Authorized JSONRPC server used as the base class for the LBRY API
Expand All @@ -71,12 +61,6 @@ class AuthJSONRPCServer(AuthorizedBase):
@AuthJSONRPCServer.auth_required: this requires the client
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:
allowed_during_startup (list): list of api methods that are
callable before the server has finished startup
Expand All @@ -86,8 +70,6 @@ class AuthJSONRPCServer(AuthorizedBase):
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
"""
Expand Down Expand Up @@ -159,12 +141,6 @@ def expire_session():
token = parsed.pop('hmac', None)
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
if self._use_authentication:
if function_name in self.authorized_functions:
Expand Down Expand Up @@ -302,11 +278,6 @@ def _get_jsonrpc_version(self, version=None, id=None):
version_for_return = jsonrpclib.VERSION_PRE1
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):
result_for_return = result if not isinstance(result, dict) else result['result']

Expand Down

0 comments on commit 21daadb

Please sign in to comment.