diff --git a/plugins/clnrest/README.md b/plugins/clnrest/README.md index 52c132c39..c83abd115 100644 --- a/plugins/clnrest/README.md +++ b/plugins/clnrest/README.md @@ -6,11 +6,15 @@ CLNRest is a lightweight Python-based core lightning plugin that transforms RPC Install required packages with `pip install json5 flask flask_restx gunicorn pyln-client` or `pip install -r requirements.txt`. +Note: if you have the older c-lightning-rest plugin, you can use `disable-plugin clnrest.py` to avoid any conflict with this one. Of course, you could use this one instead! + ## Configuration +If `rest-port` is not specified, the plugin will disable itself. + +- --rest-port: Sets the REST server port to listen to (3010 is common) - --rest-protocol: Specifies the REST server protocol. Default is HTTPS. - --rest-host: Defines the REST server host. Default is 127.0.0.1. -- --rest-port: Sets the REST server port to listen to. Default is 3010. - --rest-certs: Defines the path for HTTPS cert & key. Default path is same as RPC file path to utilize gRPC's client certificate. If it is missing at the configured location, new identity (`client.pem` and `client-key.pem`) will be generated. ## Plugin diff --git a/plugins/clnrest/clnrest.py b/plugins/clnrest/clnrest.py index e4afc022b..04159f2ff 100755 --- a/plugins/clnrest/clnrest.py +++ b/plugins/clnrest/clnrest.py @@ -110,7 +110,10 @@ def start_server(): @plugin.init() def init(options, configuration, plugin): - set_config(options) + # We require options before we open a port. + err = set_config(options) + if err: + return {'disable': err} start_server() diff --git a/plugins/clnrest/utilities/rpc_plugin.py b/plugins/clnrest/utilities/rpc_plugin.py index 14433cb89..fb45cf0b8 100644 --- a/plugins/clnrest/utilities/rpc_plugin.py +++ b/plugins/clnrest/utilities/rpc_plugin.py @@ -10,7 +10,7 @@ queue = manager.Queue() plugin.add_option(name="rest-certs", default=os.getcwd(), description="Path for certificates (for https)", opt_type="string", deprecated=False) plugin.add_option(name="rest-protocol", default="https", description="REST server protocol", opt_type="string", deprecated=False) plugin.add_option(name="rest-host", default="127.0.0.1", description="REST server host", opt_type="string", deprecated=False) -plugin.add_option(name="rest-port", default=3010, description="REST server port to listen", opt_type="int", deprecated=False) +plugin.add_option(name="rest-port", default=None, description="REST server port to listen", opt_type="int", deprecated=False) @plugin.subscribe("*") diff --git a/plugins/clnrest/utilities/shared.py b/plugins/clnrest/utilities/shared.py index 90d3fa6a3..875b8720b 100644 --- a/plugins/clnrest/utilities/shared.py +++ b/plugins/clnrest/utilities/shared.py @@ -6,11 +6,14 @@ CERTS_PATH, REST_PROTOCOL, REST_HOST, REST_PORT = "", "", "", "" def set_config(options): + if 'rest-port' not in options: + return "`rest-port` option is not configured" global CERTS_PATH, REST_PROTOCOL, REST_HOST, REST_PORT CERTS_PATH = str(options["rest-certs"]) REST_PROTOCOL = str(options["rest-protocol"]) REST_HOST = str(options["rest-host"]) REST_PORT = int(options["rest-port"]) + return None def call_rpc_method(plugin, rpc_method, payload):