42 lines
1001 B
Go
42 lines
1001 B
Go
package handlers
|
|
|
|
import (
|
|
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/grpcsrv/commander"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
type AgentsGroup struct {
|
|
*Handlers
|
|
cmder *commander.Commander
|
|
}
|
|
|
|
func NewAgentsGroup(h *Handlers, cmder *commander.Commander) AgentsGroup {
|
|
return AgentsGroup{Handlers: h, cmder: cmder}
|
|
}
|
|
|
|
type AgentInfo struct {
|
|
Token string `json:"token"`
|
|
Label string `json:"label"`
|
|
Services []string `json:"services"`
|
|
}
|
|
|
|
// @Summary Get connected agents
|
|
// @Description Returns a list of all agents currently connected via gRPC streaming
|
|
// @Tags agents
|
|
// @Produce json
|
|
// @Success 200 {array} AgentInfo
|
|
// @Router /agents [get]
|
|
func (ag *AgentsGroup) List(c *gin.Context) {
|
|
agents := make([]AgentInfo, 0)
|
|
// iterate over the commander's agents map
|
|
for _, agent := range ag.cmder.Agents() {
|
|
agents = append(agents, AgentInfo{
|
|
Token: agent.Token,
|
|
Label: agent.Label,
|
|
Services: agent.Services,
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, agents)
|
|
}
|