Skip to content

Commit 9599bde

Browse files
eberriganclaude
andauthored
fix: Sanitize URLs to handle prepended dots in subscribe function (#198)
- Add URL sanitization to handle empty subdomains that create leading dots - Handles http://.domain, https://.domain, and .domain cases - Bump client version from 0.0.8a1 to 0.0.8a2 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent f63f7fb commit 9599bde

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/client/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ keywords = ["vm", "docker", "postgres", "tutorial", "AWS"]
2222
name = "lablink-client-service"
2323
readme = "README.md"
2424
requires-python = ">=3.8"
25-
version = "0.0.8a1"
25+
version = "0.0.8a2"
2626

2727
[project.optional-dependencies]
2828
dev = ["twine", "build", "pytest", "ruff", "pytest-cov"]

packages/client/src/lablink_client_service/subscribe.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,21 @@ def subscribe(cfg: Config) -> None:
2525
# Use ALLOCATOR_URL env var if set (supports HTTPS),
2626
# otherwise use host:port with HTTP
2727
allocator_url = os.getenv("ALLOCATOR_URL")
28+
logger.debug(f"Allocator URL from env: {allocator_url}")
2829
if allocator_url:
29-
base_url = allocator_url.rstrip('/')
30+
base_url = allocator_url.rstrip("/")
3031
else:
3132
base_url = f"http://{cfg.allocator.host}:{cfg.allocator.port}"
33+
34+
# Sanitize URL to remove prepended dots
35+
# Handles cases like:
36+
# - http://.lablink.sleap.ai -> http://lablink.sleap.ai
37+
# - https://.lablink.sleap.ai -> https://lablink.sleap.ai
38+
# - .lablink.sleap.ai -> lablink.sleap.ai
39+
base_url = base_url.replace("://.", "://")
40+
if base_url.startswith("."):
41+
base_url = base_url[1:]
42+
3243
url = f"{base_url}/vm_startup"
3344
logger.debug(f"URL: {url}")
3445

@@ -50,8 +61,7 @@ def subscribe(cfg: Config) -> None:
5061
# The allocator uses PostgreSQL LISTEN/NOTIFY to wait for VM
5162
# assignment. Timeout tuple: (connect, read) = (30s, 7 days)
5263
logger.debug(
53-
f"Attempting to connect to allocator "
54-
f"(attempt {retry_count + 1})"
64+
f"Attempting to connect to allocator " f"(attempt {retry_count + 1})"
5565
)
5666
response = requests.post(
5767
url, json={"hostname": hostname}, timeout=(30, 604800)
@@ -78,8 +88,7 @@ def subscribe(cfg: Config) -> None:
7888
break # Server explicitly rejected - don't retry
7989
else:
8090
logger.error(
81-
f"POST request failed with status code: "
82-
f"{response.status_code}"
91+
f"POST request failed with status code: " f"{response.status_code}"
8392
)
8493
# Will retry after delay
8594

0 commit comments

Comments
 (0)