mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
feat: 添加节点管理功能,支持全局 discovery token 生成与旋转,更新节点注册流程
This commit is contained in:
@@ -17,15 +17,15 @@ func AgentRegister(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
discoveryNode, ok := c.Get("discovery_node")
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"success": false,
|
||||
"message": "无权进行此操作,Discovery Token 无效",
|
||||
})
|
||||
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)
|
||||
}
|
||||
result, err := service.RegisterNode(discoveryNode.(*model.Node), payload)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
|
||||
@@ -32,6 +32,38 @@ func CreateNode(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func GetNodeBootstrapToken(c *gin.Context) {
|
||||
bootstrap, err := service.GetNodeBootstrapView()
|
||||
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": bootstrap,
|
||||
})
|
||||
}
|
||||
|
||||
func RotateNodeBootstrapToken(c *gin.Context) {
|
||||
bootstrap, err := service.RotateGlobalDiscoveryToken()
|
||||
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": bootstrap,
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateNode(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
|
||||
Reference in New Issue
Block a user