plugins/clnrest: Add rest-cors-origins option for config

This commit is contained in:
ShahanaFarooqui 2023-09-11 21:27:13 -07:00 committed by Rusty Russell
parent 224a5dcbcf
commit 632e7abd05
2 changed files with 8 additions and 2 deletions

View File

@ -7,3 +7,4 @@ plugin.add_option(name="rest-certs", default=os.getcwd(), description="Path for
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=None, description="REST server port to listen", opt_type="int", deprecated=False)
plugin.add_option(name="rest-cors-origins", default="*", description="Cross origin resource sharing origins", opt_type="string", deprecated=False, multi=True)

View File

@ -2,17 +2,22 @@ import json5
import re
import json
CERTS_PATH, REST_PROTOCOL, REST_HOST, REST_PORT = "", "", "", ""
CERTS_PATH, REST_PROTOCOL, REST_HOST, REST_PORT, REST_CORS_ORIGINS = "", "", "", "", []
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
global CERTS_PATH, REST_PROTOCOL, REST_HOST, REST_PORT, REST_CORS_ORIGINS
CERTS_PATH = str(options["rest-certs"])
REST_PROTOCOL = str(options["rest-protocol"])
REST_HOST = str(options["rest-host"])
REST_PORT = int(options["rest-port"])
cors_origins = options["rest-cors-origins"]
REST_CORS_ORIGINS.clear()
for origin in cors_origins:
REST_CORS_ORIGINS.append(str(origin))
return None