feat(cloud): add edge host enrollment

This commit is contained in:
2026-07-13 13:54:16 +08:00
parent cd56facbbf
commit e61dcca801
40 changed files with 2302 additions and 48 deletions
+25 -7
View File
@@ -2,7 +2,8 @@ from __future__ import annotations
import os
from collections.abc import Mapping
from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from urllib.parse import urlparse
@@ -13,8 +14,12 @@ class HostAgentConfigurationError(ValueError):
@dataclass(frozen=True)
class HostAgentConfig:
control_plane_url: str
host_id: str
token: str
host_id: str = ""
token: str = field(default="", repr=False)
enrollment_token: str = field(default="", repr=False)
identity_path: Path = Path("tasks/host_identity.json")
enrollment_managed: bool = False
display_name: str | None = None
heartbeat_interval_seconds: float = 30.0
poll_timeout_seconds: float = 20.0
retry_backoff_seconds: float = 1.0
@@ -41,16 +46,29 @@ def load_host_agent_config(
)
host_id = values.get("HOST_AGENT_HOST_ID", "").strip()
if not host_id:
raise HostAgentConfigurationError("HOST_AGENT_HOST_ID is required")
token = values.get("HOST_AGENT_TOKEN", "").strip()
if not token:
raise HostAgentConfigurationError("HOST_AGENT_TOKEN is required")
if bool(host_id) != bool(token):
raise HostAgentConfigurationError(
"HOST_AGENT_HOST_ID and HOST_AGENT_TOKEN must be configured together"
)
enrollment_token = values.get("HOST_AGENT_ENROLLMENT_TOKEN", "").strip()
identity_path = Path(
values.get("HOST_AGENT_IDENTITY_PATH", "tasks/host_identity.json").strip()
)
if not host_id and not enrollment_token and not identity_path.is_file():
raise HostAgentConfigurationError(
"explicit Host credentials, an enrollment token, or existing identity state "
"is required"
)
config = HostAgentConfig(
control_plane_url=control_plane_url,
host_id=host_id,
token=token,
enrollment_token=enrollment_token,
identity_path=identity_path,
enrollment_managed=not bool(host_id),
display_name=values.get("HOST_AGENT_DISPLAY_NAME") or None,
heartbeat_interval_seconds=_positive_float(
values,
"HOST_AGENT_HEARTBEAT_INTERVAL_SECONDS",