Ping the RPC api before using the wot CLI
This commit is contained in:
parent
b3eb0caffd
commit
738fa0c361
@ -1,7 +1,10 @@
|
|||||||
import tty
|
import tty
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
import ujson as json
|
||||||
|
import result
|
||||||
import requests
|
import requests
|
||||||
import requests_unixsocket
|
import requests_unixsocket
|
||||||
|
|
||||||
@ -23,10 +26,28 @@ def list_idens():
|
|||||||
print('Listing identities')
|
print('Listing identities')
|
||||||
payload = dict(rpc_payload)
|
payload = dict(rpc_payload)
|
||||||
payload['method'] = 'wot.serialize_identity_set'
|
payload['method'] = 'wot.serialize_identity_set'
|
||||||
payload['params'].clear()
|
del payload['params']
|
||||||
print(onionrplugins.pluginapis.plugin_apis['rpc.rpc_client'](payload).text)
|
print(onionrplugins.pluginapis.plugin_apis['rpc.rpc_client'](json=payload).text)
|
||||||
|
|
||||||
|
|
||||||
|
def ping_api() -> result.Result:
|
||||||
|
payload = dict(rpc_payload)
|
||||||
|
payload['method'] = 'ping'
|
||||||
|
del payload['params']
|
||||||
|
try:
|
||||||
|
_ping_res = onionrplugins.pluginapis.plugin_apis['rpc.rpc_client'](json=payload).text
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
logging.debug(traceback.format_exc())
|
||||||
|
return result.Err('Could not connect to Onionr RPC server. Please ensure the RPC plugin is enabled and the Onionr daemon is running')
|
||||||
|
except:
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
return result.Err('Unknown error occurred while connecting to Onionr RPC server')
|
||||||
|
_ping_res = json.loads(_ping_res)
|
||||||
|
if _ping_res['result'] == 'pong':
|
||||||
|
return result.Ok()
|
||||||
|
else:
|
||||||
|
return result.Err('API not responding. Try restarting Onionr')
|
||||||
|
|
||||||
|
|
||||||
main_menu = {
|
main_menu = {
|
||||||
'l': (list_idens, 'list trusted identities'),
|
'l': (list_idens, 'list trusted identities'),
|
||||||
@ -40,11 +61,17 @@ def main_ui():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logging.error("Web of trust CLI requires RPC plugin to be enabled")
|
logging.error("Web of trust CLI requires RPC plugin to be enabled")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
ping_result: result.Result = ping_api()
|
||||||
|
if not isinstance(ping_result, result.Ok):
|
||||||
|
logging.error(ping_result)
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# move cursor to the beginning
|
# move cursor to the beginning
|
||||||
print('\r', end='')
|
print('\r', end='')
|
||||||
key = sys.stdin.read(1)
|
|
||||||
try:
|
try:
|
||||||
|
key = sys.stdin.read(1)
|
||||||
main_menu[key][0]()
|
main_menu[key][0]()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user