From 7bcef03592a9a44b77934a45654198d6ab9fbb32 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Wed, 11 Jan 2023 16:51:11 -0600 Subject: [PATCH] Added setunixsocket and settcpsocket helper commands to RPC plugin --- static-data/official-plugins/rpc/main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/static-data/official-plugins/rpc/main.py b/static-data/official-plugins/rpc/main.py index 9afcc9b7..dd4d7710 100644 --- a/static-data/official-plugins/rpc/main.py +++ b/static-data/official-plugins/rpc/main.py @@ -97,6 +97,27 @@ def _gen_random_loopback(): return f'127.{randbelow(256)}.{randbelow(256)}.{randbelow(256)}' +def on_setunixsocket_cmd(api, data=None): + config.set('rpc.use_sock_file', True, savefile=True) + logging.info('Set RPC to use unix socket') + +def on_settcpsocket_cmd(api, data=None): + config.set('rpc.use_sock_file', False, savefile=True) + address = input('Enter address to bind to (default: random loopback): ').strip() + if not address: + address = _gen_random_loopback() + port = input('Enter port to bind to (default: 0 (random/picked by OS)): ').strip() + if not port: + port = 0 + port = int(port) + config.set('rpc.bind_host', address, savefile=True) + config.set('rpc.bind_port', port, savefile=True) + + logging.info( + 'Set RPC to use TCP socket http://' + + f'{config.get("rpc.bind_host")}:{config.get("rpc.bind_port")}') + + def on_init(api, data=None): bind_config = {} if config.get('rpc.use_sock_file', True, save=True):