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:
ryan
2026-03-10 15:33:06 +08:00
parent 861d759f97
commit 05e75549d2
16 changed files with 916 additions and 296 deletions
+15 -5
View File
@@ -99,6 +99,9 @@ func SetApiRouter(router *gin.Engine) {
nodeRoute.Use(middleware.AdminAuth())
{
nodeRoute.GET("/", controller.GetNodes)
nodeRoute.POST("/", controller.CreateNode)
nodeRoute.PUT("/:id", controller.UpdateNode)
nodeRoute.DELETE("/:id", controller.DeleteNode)
}
applyLogRoute := apiRouter.Group("/apply-logs")
applyLogRoute.Use(middleware.AdminAuth())
@@ -106,12 +109,19 @@ func SetApiRouter(router *gin.Engine) {
applyLogRoute.GET("/", controller.GetApplyLogs)
}
agentRoute := apiRouter.Group("/agent")
agentRoute.Use(middleware.AgentAuth())
{
agentRoute.POST("/nodes/register", controller.AgentRegister)
agentRoute.POST("/nodes/heartbeat", controller.AgentHeartbeat)
agentRoute.GET("/config-versions/active", controller.AgentGetActiveConfig)
agentRoute.POST("/apply-logs", controller.AgentReportApplyLog)
discoveryRoute := agentRoute.Group("/")
discoveryRoute.Use(middleware.AgentDiscoveryAuth())
{
discoveryRoute.POST("/nodes/register", controller.AgentRegister)
}
authorizedRoute := agentRoute.Group("/")
authorizedRoute.Use(middleware.AgentAuth())
{
authorizedRoute.POST("/nodes/heartbeat", controller.AgentHeartbeat)
authorizedRoute.GET("/config-versions/active", controller.AgentGetActiveConfig)
authorizedRoute.POST("/apply-logs", controller.AgentReportApplyLog)
}
}
}
}