Skip to content

Commit

Permalink
Allow to start on non-localhost without TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed May 10, 2024
1 parent 0146e2a commit c8b0290
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions renumics/spotlight/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def cli_dtype_callback(
@click.option(
"--ssl-keyfile-password", type=str, default=None, help="SSL keyfile password"
)
@click.option(
"--no-ssl",
is_flag=True,
default=False,
help="Do not require SSL sertificate and keyfile when starting on non-localhost.",
)
@click.option("-v", "--verbose", is_flag=True)
@click.version_option(spotlight.__version__)
def main(
Expand All @@ -142,6 +148,7 @@ def main(
ssl_keyfile: Optional[str],
ssl_certfile: Optional[str],
ssl_keyfile_password: Optional[str],
no_ssl: bool,
verbose: bool,
) -> None:
"""
Expand Down Expand Up @@ -171,4 +178,5 @@ def main(
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
ssl_keyfile_password=ssl_keyfile_password,
no_ssl=no_ssl,
)
3 changes: 2 additions & 1 deletion renumics/spotlight/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
ssl_keyfile: Optional[str] = None,
ssl_certfile: Optional[str] = None,
ssl_keyfile_password: Optional[str] = None,
no_ssl: bool = False,
) -> None:
self.process = None

Expand All @@ -80,7 +81,7 @@ def __init__(
self._app_config = AppConfig()

self._host = host
if self._host not in ("127.0.0.1", "localhost"):
if self._host not in ("127.0.0.1", "localhost") and not no_ssl:
if ssl_certfile is None:
raise MissingTLSCertificate(
"Starting Spotlight on non-localhost without TLS certificate is insecure. Please provide TLS certificate and key."
Expand Down
10 changes: 9 additions & 1 deletion renumics/spotlight/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Viewer:
_ssl_keyfile: Optional[str]
_ssl_certfile: Optional[str]
_ssl_keyfile_password: Optional[str]
_no_ssl: bool
_server: Optional[Server]
_df: Optional[pd.DataFrame]

Expand All @@ -142,12 +143,14 @@ def __init__(
ssl_keyfile: Optional[str] = None,
ssl_certfile: Optional[str] = None,
ssl_keyfile_password: Optional[str] = None,
no_ssl: bool = False,
) -> None:
self._host = host
self._requested_port = port
self._ssl_keyfile = ssl_keyfile
self._ssl_certfile = ssl_certfile
self._ssl_keyfile_password = ssl_keyfile_password
self._no_ssl = no_ssl
self._server = None
self._df = None

Expand Down Expand Up @@ -233,6 +236,7 @@ def show(
self._ssl_keyfile,
self._ssl_certfile,
self._ssl_keyfile_password,
self._no_ssl,
)
self._server.start(config)

Expand Down Expand Up @@ -406,6 +410,7 @@ def show(
ssl_keyfile: Optional[str] = None,
ssl_certfile: Optional[str] = None,
ssl_keyfile_password: Optional[str] = None,
no_ssl: bool = False,
) -> Viewer:
"""
Start a new Spotlight viewer.
Expand Down Expand Up @@ -435,6 +440,7 @@ def show(
ssl_keyfile: Optional SSL key file.
ssl_certfile: Optional SSL certificate file.
ssl_certfile: Optional SSL keyfile password.
no_ssl: Do not require SSL sertificate and keyfile when starting on non-localhost.
"""

viewer = None
Expand All @@ -445,7 +451,9 @@ def show(
viewer = _VIEWERS[index]
break
if not viewer:
viewer = Viewer(host, port, ssl_keyfile, ssl_certfile, ssl_keyfile_password)
viewer = Viewer(
host, port, ssl_keyfile, ssl_certfile, ssl_keyfile_password, no_ssl
)

viewer.show(
dataset,
Expand Down

0 comments on commit c8b0290

Please sign in to comment.