return error for deprecated functions

This commit is contained in:
Jack Robison 2017-06-02 14:35:51 -04:00
parent cfcc4205ab
commit 363db1073e

View file

@ -87,6 +87,10 @@ class UnknownAPIMethodError(Exception):
pass pass
class DeprecatedAPIMethodError(Exception):
pass
class NotAllowedDuringStartupError(Exception): class NotAllowedDuringStartupError(Exception):
pass pass
@ -335,6 +339,13 @@ class AuthJSONRPCServer(AuthorizedBase):
request, id_ request, id_
) )
return server.NOT_DONE_YET return server.NOT_DONE_YET
except DeprecatedAPIMethodError:
log.warning('API function is deprecated %s', function_name)
self._render_error(
JSONRPCError(None, JSONRPCError.CODE_METHOD_NOT_FOUND),
request, id_
)
return server.NOT_DONE_YET
if args == EMPTY_PARAMS or args == []: if args == EMPTY_PARAMS or args == []:
args_dict = {} args_dict = {}
@ -464,13 +475,7 @@ class AuthJSONRPCServer(AuthorizedBase):
def _check_deprecated(self, function_path): def _check_deprecated(self, function_path):
if function_path in self.deprecated_methods: if function_path in self.deprecated_methods:
deprecated_fn = self.deprecated_methods[function_path] raise DeprecatedAPIMethodError(function_path)
deprecated_function_path = function_path
new_function_path = deprecated_fn._new_command
log.warning("\"%s\" is deprecated, please update to use \"%s\"",
deprecated_function_path, new_function_path)
return new_function_path
return function_path
def _verify_method_is_callable(self, function_path): def _verify_method_is_callable(self, function_path):
if function_path not in self.callable_methods: if function_path not in self.callable_methods:
@ -480,7 +485,7 @@ class AuthJSONRPCServer(AuthorizedBase):
raise NotAllowedDuringStartupError(function_path) raise NotAllowedDuringStartupError(function_path)
def _get_jsonrpc_method(self, function_path): def _get_jsonrpc_method(self, function_path):
function_path = self._check_deprecated(function_path) self._check_deprecated(function_path)
self._verify_method_is_callable(function_path) self._verify_method_is_callable(function_path)
return self.callable_methods.get(function_path) return self.callable_methods.get(function_path)