mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-04 15:06:37 +08:00
feat: Implement node management features including creation, updating, and deletion
- Added CreateNode, UpdateNode, and DeleteNode functions in the controller for managing nodes. - Introduced NodeInput struct for input validation during node creation and updates. - Enhanced the Node model to include DiscoveryToken and Pending status. - Updated the AgentRegister and AgentHeartbeat functions to utilize the new node management logic. - Refactored the API router to include new routes for node management. - Improved the frontend Node component to support node creation, editing, and deletion with appropriate UI feedback. - Added tests to ensure the new functionality works as expected.
This commit is contained in:
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"gin-template/model"
|
||||
"gin-template/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
@@ -16,7 +17,15 @@ func AgentRegister(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
node, err := service.RegisterNode(payload)
|
||||
discoveryNode, ok := c.Get("discovery_node")
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"success": false,
|
||||
"message": "无权进行此操作,Discovery Token 无效",
|
||||
})
|
||||
return
|
||||
}
|
||||
result, err := service.RegisterNode(discoveryNode.(*model.Node), payload)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
@@ -27,7 +36,7 @@ func AgentRegister(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "",
|
||||
"data": node,
|
||||
"data": result,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,7 +49,15 @@ func AgentHeartbeat(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
node, err := service.HeartbeatNode(payload)
|
||||
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,
|
||||
@@ -80,6 +97,10 @@ func AgentReportApplyLog(c *gin.Context) {
|
||||
})
|
||||
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{
|
||||
|
||||
Reference in New Issue
Block a user