Skip to content

Commit

Permalink
Lightly server https (#1552)
Browse files Browse the repository at this point in the history
closes lig-5082
- allow to pass ssl certs to lightly-serve to start it in HTTPS mode
  • Loading branch information
japrescott authored Jun 4, 2024
1 parent 7500a0f commit be0de41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lightly/cli/config/lightly-serve.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ input_mount: '' # Path to the input directory.
lightly_mount: '' # Path to the lightly directory.
host: 'localhost' # Hostname for serving the data.
port: 3456 # Port for serving the data.

ssl_cert: '' # Path to the SSL certificate.
ssl_key: '' # Path to the SSL key.

# Disable Hydra log directories.
defaults:
Expand Down
18 changes: 17 additions & 1 deletion lightly/cli/serve_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ssl
import sys
from pathlib import Path

Expand All @@ -19,9 +20,14 @@ def lightly_serve(cfg):
lightly_mount:
Path to the Lightly directory.
host:
Hostname for serving the data (defaults to localhost).
Hostname for serving the data (defaults to localhost). If you want to expose it to the internet or your local network, use '0.0.0.0'.
See our docs on lightly-serve for more information: https://docs.lightly.ai/docs/local-storage#view-the-local-data-securely-over-the-networkvpn
port:
Port for serving the data (defaults to 3456).
ssl_key:
Optional path to the ssl key file.
ssl_cert:
Optional path to the ssl cert file.
Examples:
>>> lightly-serve input_mount=data/ lightly_mount=lightly/ port=3456
Expand Down Expand Up @@ -52,6 +58,16 @@ def lightly_serve(cfg):
host=cfg.host,
port=cfg.port,
)

# setup https/ssl if key or cert are provided
if cfg.ssl_key or cfg.ssl_cert:
httpd.socket = ssl.wrap_socket(
httpd.socket,
keyfile=Path(cfg.ssl_key) if cfg.ssl_key else None,
certfile=Path(cfg.ssl_cert) if cfg.ssl_cert else None,
server_side=True,
)

print(
f"Starting server, listening at '{bcolors.OKBLUE}{httpd.server_name}:{httpd.server_port}{bcolors.ENDC}'"
)
Expand Down

0 comments on commit be0de41

Please sign in to comment.