mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
83a11ead2b
- Introduced OperationSetting component for managing agent configurations. - Updated settings page to include a new tab for operation settings. - Implemented functionality to fetch and update agent parameters such as heartbeat interval, sync interval, and auto-update settings. docs: enhance deployment documentation for agent installation - Added detailed instructions for agent installation using a script. - Included examples for using discovery and agent tokens. - Updated sections on global discovery tokens and agent auto-update features. docs: revise design and development guidelines for V3 - Updated design document to reflect the current state and goals for V3. - Clarified development guidelines to focus on operational experience improvements. ci: add GitHub Actions workflow for agent releases - Created a new workflow to automate the release of agent binaries on GitHub. - Configured the workflow to build binaries for multiple platforms and publish them as releases. feat: implement self-update mechanism for agent - Added updater module to handle checking for and applying updates from GitHub releases. - Implemented logic to restart the agent after a successful update. chore: create install script for agent deployment - Developed a bash script to facilitate the installation of the ATSFlare agent. - The script supports automatic configuration and systemd service creation.
152 lines
3.1 KiB
Go
152 lines
3.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"atsflare/model"
|
|
"atsflare/service"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AgentRegister(c *gin.Context) {
|
|
var payload service.AgentNodePayload
|
|
if err := json.NewDecoder(c.Request.Body).Decode(&payload); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"success": false,
|
|
"message": "无效的参数",
|
|
})
|
|
return
|
|
}
|
|
var (
|
|
result *service.AgentRegistrationResponse
|
|
err error
|
|
)
|
|
if authNode, ok := c.Get("agent_node"); ok {
|
|
result, err = service.RegisterNodeWithAgentToken(authNode.(*model.Node), payload)
|
|
} else {
|
|
result, err = service.RegisterNodeWithDiscovery(payload)
|
|
}
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": result,
|
|
})
|
|
}
|
|
|
|
func AgentHeartbeat(c *gin.Context) {
|
|
var payload service.AgentNodePayload
|
|
if err := json.NewDecoder(c.Request.Body).Decode(&payload); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"success": false,
|
|
"message": "无效的参数",
|
|
})
|
|
return
|
|
}
|
|
authNode, ok := c.Get("agent_node")
|
|
if !ok {
|
|
c.JSON(http.StatusUnauthorized, gin.H{
|
|
"success": false,
|
|
"message": "无权进行此操作,Agent Token 无效",
|
|
})
|
|
return
|
|
}
|
|
node, err := service.HeartbeatNode(authNode.(*model.Node), payload)
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": node.Node,
|
|
"agent_settings": node.AgentSettings,
|
|
})
|
|
}
|
|
|
|
func AgentGetActiveConfig(c *gin.Context) {
|
|
config, err := service.GetActiveConfigForAgent()
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": "当前没有激活版本",
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": config,
|
|
})
|
|
}
|
|
|
|
func AgentReportApplyLog(c *gin.Context) {
|
|
var payload service.ApplyLogPayload
|
|
if err := json.NewDecoder(c.Request.Body).Decode(&payload); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"success": false,
|
|
"message": "无效的参数",
|
|
})
|
|
return
|
|
}
|
|
authNode, ok := c.Get("agent_node")
|
|
if ok {
|
|
payload.NodeID = authNode.(*model.Node).NodeID
|
|
}
|
|
log, err := service.ReportApplyLog(payload)
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": log,
|
|
})
|
|
}
|
|
|
|
func GetNodes(c *gin.Context) {
|
|
nodes, err := service.ListNodeViews()
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": nodes,
|
|
})
|
|
}
|
|
|
|
func GetApplyLogs(c *gin.Context) {
|
|
logs, err := service.ListApplyLogs(c.Query("node_id"))
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": false,
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"success": true,
|
|
"message": "",
|
|
"data": logs,
|
|
})
|
|
}
|