This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
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 {
|
||||
@@ -22,5 +28,14 @@ type AgentInfo struct {
|
||||
// @Success 200 {array} AgentInfo
|
||||
// @Router /agents [get]
|
||||
func (ag *AgentsGroup) List(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Agents list"})
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user