Skip to content

Commit 8cf5af0

Browse files
committed
Adds configurable hosts for hamilton ui
Settings mini is used by default by the Hamilton UI command. This changes it to enable changing ALLOWED_HOSTS by passing in some environment variables. It then automatically adds a few of them, like the current IP, etc.
1 parent b836e19 commit 8cf5af0

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

ui/backend/server/server/settings_mini.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import logging
12
import os
3+
import socket
24
from pathlib import Path
35

6+
logger = logging.getLogger(__name__)
7+
48

59
def get_from_env(
610
var_name: str, valid_values: list = None, allow_missing: bool = False, default_value: str = None
@@ -34,7 +38,19 @@ def get_from_env(
3438

3539
HAMILTON_AUTH_MODE = "permissive"
3640

37-
ALLOWED_HOSTS = ["localhost", "backend", "0.0.0.0", "127.0.0.1"]
41+
# set up allowed hosts
42+
try:
43+
hostname = socket.gethostname()
44+
local_ip = socket.gethostbyname(hostname)
45+
hosts_to_add = [local_ip, hostname]
46+
except Exception:
47+
logger.warning("Could not get hostname or local IP")
48+
hosts_to_add = []
49+
ALLOWED_HOSTS = ["localhost", "backend", "0.0.0.0", "127.0.0.1", "colab.research.google.com"]
50+
ALLOWED_HOSTS = (
51+
ALLOWED_HOSTS + hosts_to_add + os.environ.get("HAMILTON_ALLOWED_HOSTS", "").split(",")
52+
)
53+
logger.debug(f"ALLOWED_HOSTS: {ALLOWED_HOSTS}")
3854

3955
HAMILTON_BLOB_STORE = "local"
4056

0 commit comments

Comments
 (0)