mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
fix(gateway): validate multiplex adapter config by platform
This commit is contained in:
parent
bd44ef8645
commit
64746b4bd3
7 changed files with 97 additions and 20 deletions
|
|
@ -41,13 +41,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def check_ha_requirements() -> bool:
|
||||
"""Check if Home Assistant runtime dependencies are available."""
|
||||
return bool(AIOHTTP_AVAILABLE)
|
||||
return AIOHTTP_AVAILABLE
|
||||
|
||||
|
||||
def validate_ha_config(config: PlatformConfig) -> bool:
|
||||
"""Accept either a scoped config token or an env-provided HASS_TOKEN."""
|
||||
token = getattr(config, "token", None) or os.getenv("HASS_TOKEN", "")
|
||||
return bool(str(token or "").strip())
|
||||
"""Return True when Home Assistant has enough credential config to connect."""
|
||||
token = (getattr(config, "token", None) or os.getenv("HASS_TOKEN", "")).strip()
|
||||
return bool(token)
|
||||
|
||||
|
||||
class HomeAssistantAdapter(BasePlatformAdapter):
|
||||
|
|
|
|||
|
|
@ -51,15 +51,7 @@ _RECONNECT_JITTER = 0.2
|
|||
|
||||
|
||||
def check_mattermost_requirements() -> bool:
|
||||
"""Return True if the Mattermost adapter can be used."""
|
||||
token = os.getenv("MATTERMOST_TOKEN", "")
|
||||
url = os.getenv("MATTERMOST_URL", "")
|
||||
if not token:
|
||||
logger.debug("Mattermost: MATTERMOST_TOKEN not set")
|
||||
return False
|
||||
if not url:
|
||||
logger.warning("Mattermost: MATTERMOST_URL not set")
|
||||
return False
|
||||
"""Return True if the Mattermost adapter runtime dependency is available."""
|
||||
try:
|
||||
import aiohttp # noqa: F401
|
||||
return True
|
||||
|
|
@ -68,6 +60,20 @@ def check_mattermost_requirements() -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def validate_mattermost_config(config: PlatformConfig) -> bool:
|
||||
"""Return True when Mattermost has enough config to connect."""
|
||||
extra = getattr(config, "extra", {}) or {}
|
||||
token = (getattr(config, "token", None) or os.getenv("MATTERMOST_TOKEN", "")).strip()
|
||||
url = (extra.get("url", "") or os.getenv("MATTERMOST_URL", "")).strip()
|
||||
if not token:
|
||||
logger.debug("Mattermost: MATTERMOST_TOKEN not set")
|
||||
return False
|
||||
if not url:
|
||||
logger.warning("Mattermost: MATTERMOST_URL not set")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class MattermostAdapter(BasePlatformAdapter):
|
||||
"""Gateway adapter for Mattermost (self-hosted or cloud)."""
|
||||
|
||||
|
|
@ -1248,6 +1254,7 @@ def register(ctx) -> None:
|
|||
label="Mattermost",
|
||||
adapter_factory=_build_adapter,
|
||||
check_fn=check_mattermost_requirements,
|
||||
validate_config=validate_mattermost_config,
|
||||
is_connected=_is_connected,
|
||||
required_env=["MATTERMOST_URL", "MATTERMOST_TOKEN"],
|
||||
install_hint="pip install aiohttp",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue