mirror of https://github.com/nucypher/nucypher.git
handle kwargs based requests
Co-Authored-By: Derek Pierre <derek.pierre@gmail.com> Co-Authored-By: Derek Pierre <derek.pierre@gmail.com>pull/1555/head
parent
abb2cb5ddd
commit
fcb9763959
|
@ -13,7 +13,7 @@ from twisted.logger import Logger
|
|||
|
||||
from nucypher.characters.control.emitters import StdoutEmitter, WebEmitter, JSONRPCStdoutEmitter
|
||||
from nucypher.characters.control.interfaces import CharacterPublicInterface
|
||||
from nucypher.characters.control.specifications.exceptions import MissingField, InvalidInputField, SpecificationError, MethodNotFound
|
||||
from nucypher.characters.control.specifications.exceptions import MissingField, InvalidInputField, SpecificationError
|
||||
from nucypher.cli.processes import JSONRPCLineReceiver
|
||||
from nucypher.utilities.controllers import JSONRPCTestClient
|
||||
|
||||
|
@ -75,7 +75,8 @@ class CharacterControlServer(CharacterControllerBase):
|
|||
|
||||
def set_method(name):
|
||||
|
||||
def wrapper(request=None):
|
||||
def wrapper(request=None, **kwargs):
|
||||
request = request or kwargs
|
||||
return self.handle_request(name, request=request)
|
||||
setattr(self, name, wrapper)
|
||||
|
||||
|
@ -107,6 +108,7 @@ class CharacterControlServer(CharacterControllerBase):
|
|||
def test_client(self):
|
||||
return NotImplemented
|
||||
|
||||
|
||||
class CLIController(CharacterControlServer):
|
||||
|
||||
_emitter_class = StdoutEmitter
|
||||
|
@ -152,7 +154,7 @@ class JSONRPCController(CharacterControlServer):
|
|||
method_name = control_request['method']
|
||||
method_params = control_request.get('params', dict()) # optional
|
||||
if method_name not in self._get_interfaces():
|
||||
raise self.emitter.MethodNotFound('No method called {method_name}')
|
||||
raise self.emitter.MethodNotFound(f'No method called {method_name}')
|
||||
|
||||
return self.call_interface(method_name=method_name,
|
||||
request=method_params,
|
||||
|
@ -265,7 +267,7 @@ class WebController(CharacterControlServer):
|
|||
InvalidInputField,
|
||||
TypeError,
|
||||
JSONDecodeError,
|
||||
MethodNotFound)
|
||||
self.emitter.MethodNotFound)
|
||||
|
||||
try:
|
||||
request_body = control_request.data or dict()
|
||||
|
@ -274,7 +276,7 @@ class WebController(CharacterControlServer):
|
|||
request_body.update(kwargs)
|
||||
|
||||
if method_name not in self._get_interfaces():
|
||||
raise MethodNotFound('No method called {method_name}')
|
||||
raise self.emitter.MethodNotFound(f'No method called {method_name}')
|
||||
|
||||
response = self._perform_action(action=method_name, request=request_body)
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ def null_stream():
|
|||
|
||||
class StdoutEmitter:
|
||||
|
||||
class MethodNotFound(BaseException):
|
||||
"""Cannot find interface method to handle request"""
|
||||
|
||||
transport_serializer = str
|
||||
default_color = 'white'
|
||||
|
||||
|
@ -196,6 +199,10 @@ class JSONRPCStdoutEmitter(StdoutEmitter):
|
|||
|
||||
class WebEmitter:
|
||||
|
||||
class MethodNotFound(BaseException):
|
||||
"""Cannot find interface method to handle request"""
|
||||
|
||||
|
||||
_crash_on_error_default = False
|
||||
transport_serializer = json.dumps
|
||||
_default_sink_callable = Response
|
||||
|
|
|
@ -9,6 +9,3 @@ class InvalidInputField(SpecificationError):
|
|||
|
||||
class InvalidOutputField(SpecificationError):
|
||||
"""Response data does not match the output specification"""
|
||||
|
||||
class MethodNotFound(SpecificationError):
|
||||
"""Response data does not match the output specification"""
|
||||
|
|
|
@ -76,5 +76,6 @@ def _setup_emitter(general_config, policy_encrypting_key):
|
|||
def _create_enrico(emitter, policy_encrypting_key):
|
||||
policy_encrypting_key = UmbralPublicKey.from_bytes(bytes.fromhex(policy_encrypting_key))
|
||||
ENRICO = Enrico(policy_encrypting_key=policy_encrypting_key)
|
||||
ENRICO.controller.emitter = emitter
|
||||
|
||||
return ENRICO
|
||||
|
|
|
@ -168,7 +168,6 @@ def wrap_option(handler, **options):
|
|||
|
||||
|
||||
def process_middleware(mock_networking):
|
||||
print ('process_middleware')
|
||||
from nucypher.network.middleware import RestMiddleware
|
||||
from nucypher.utilities.sandbox.middleware import MockRestMiddleware
|
||||
if mock_networking:
|
||||
|
|
|
@ -250,7 +250,6 @@ def _cli_lifecycle(click_runner,
|
|||
|
||||
encrypt_result = click_runner.invoke(nucypher_cli, enrico_args, catch_exceptions=False, env=envvars)
|
||||
assert encrypt_result.exit_code == 0
|
||||
|
||||
encrypt_result = json.loads(encrypt_result.output)
|
||||
encrypted_message = encrypt_result['result']['message_kit'] # type: str
|
||||
|
||||
|
|
Loading…
Reference in New Issue