Files
wehub-resource-sync 75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:11:07 +08:00

59 lines
1.7 KiB
Go

package verification_agents
import (
"net/http"
"github.com/gin-gonic/gin"
)
type AgentFacingController struct {
agentService *AgentService
}
func (c *AgentFacingController) RegisterRoutes(router *gin.RouterGroup) {
g := router.Group("/agent/verification/:agentId")
g.Use(c.agentService.RequireAgentAuth())
g.POST("/heartbeat", c.Heartbeat)
}
// Heartbeat
// @Summary Verification agent heartbeat
// @Description Called periodically by a verification agent to report capacity and refresh last-seen.
// @Description Authentication uses the agent's raw token (NOT a user JWT) — the same token returned at create/rotate.
// @Tags verification-agents
// @Accept json
// @Produce json
// @Param agentId path string true "Agent UUID"
// @Param Authorization header string true "Bearer <agent-token>"
// @Param request body HeartbeatRequest true "Capacity report"
// @Success 200 {object} HeartbeatResponse
// @Failure 400 {object} map[string]string
// @Failure 401 {object} map[string]string
// @Failure 429 {object} map[string]string
// @Router /agent/verification/{agentId}/heartbeat [post]
func (c *AgentFacingController) Heartbeat(ctx *gin.Context) {
agent, ok := GetAgentFromContext(ctx)
if !ok {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "agent missing from context"})
return
}
var request HeartbeatRequest
if err := ctx.ShouldBindJSON(&request); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
seenAt, abortVerificationIDs, err := c.agentService.Heartbeat(agent, &request)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
ctx.JSON(http.StatusOK, HeartbeatResponse{
LastSeenAt: seenAt,
AbortVerificationIDs: abortVerificationIDs,
})
}