refactor(ws/heartbeat): accept agent_key or UUID via cache-aware resolver

All 7 heartbeat handlers (get/set/toggle/test/logs/checklistGet/checklistSet)
now accept either a UUID or an agent_key for params.agentId. Behavior
additive — existing UUID-only clients keep working.

Adds HeartbeatMethods.SetAgentRouter setter wired from cmd/gateway_methods.go
so the fast path avoids a DB roundtrip for cached agents. Preserves the
literal "invalid agentId" error string (no i18n key change).

Phase 3 of agent identity hardening.
This commit is contained in:
viettranx committed 2026-04-11 21:22:23 +07:00
1 parent 6c17aad8d7
commit 84babc1c3c
2 files changed
+21 -8

No files matched your search

+6 -1
View File
@@ -43,10 +43,15 @@ func registerAllMethods(server *gateway.Server, agents *agent.Router, sessStore
// Phase 2: Heartbeat
heartbeatMethods := methods.NewHeartbeatMethods(heartbeatStore, msgBus)
// Wire cache-aware resolver (Phase 3): accepts agent_key or UUID input
// without a DB roundtrip on the hot path when the agent is router-cached.
heartbeatMethods.SetAgentRouter(agents)
heartbeatMethods.Register(router)
// Phase 2: Config permissions
methods.NewConfigPermissionsMethods(configPermStore, agentStore).Register(router)
cfgPerms := methods.NewConfigPermissionsMethods(configPermStore, agentStore)
cfgPerms.SetAgentRouter(agents)
cfgPerms.Register(router)
// Phase 2: Pairing (store created externally, shared with channel manager).
// OnApprove callback is set later by the caller after channel manager is created.