mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-22 14:30:25 +08:00
实现DNS节点远程安装
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"path/filepath"
|
||||
)
|
||||
@@ -169,6 +170,14 @@ func (this *NSNodeService) CreateNSNode(ctx context.Context, req *pb.CreateNSNod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 增加认证相关
|
||||
if req.NodeLogin != nil {
|
||||
_, err = models.SharedNodeLoginDAO.CreateNodeLogin(tx, nodeconfigs.NodeRoleDNS, nodeId, req.NodeLogin.Name, req.NodeLogin.Type, req.NodeLogin.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.CreateNSNodeResponse{
|
||||
NsNodeId: nodeId,
|
||||
}, nil
|
||||
@@ -220,6 +229,21 @@ func (this *NSNodeService) FindEnabledNSNode(ctx context.Context, req *pb.FindEn
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 认证信息
|
||||
login, err := models.SharedNodeLoginDAO.FindEnabledNodeLoginWithNodeId(tx, nodeconfigs.NodeRoleDNS, req.NsNodeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var respLogin *pb.NodeLogin = nil
|
||||
if login != nil {
|
||||
respLogin = &pb.NodeLogin{
|
||||
Id: int64(login.Id),
|
||||
Name: login.Name,
|
||||
Type: login.Type,
|
||||
Params: []byte(login.Params),
|
||||
}
|
||||
}
|
||||
|
||||
// 安装信息
|
||||
installStatus, err := node.DecodeInstallStatus()
|
||||
if err != nil {
|
||||
@@ -251,6 +275,7 @@ func (this *NSNodeService) FindEnabledNSNode(ctx context.Context, req *pb.FindEn
|
||||
},
|
||||
InstallStatus: installStatusResult,
|
||||
IsOn: node.IsOn == 1,
|
||||
NodeLogin: respLogin,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
@@ -268,6 +293,26 @@ func (this *NSNodeService) UpdateNSNode(ctx context.Context, req *pb.UpdateNSNod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 登录信息
|
||||
if req.NodeLogin == nil {
|
||||
err = models.SharedNodeLoginDAO.DisableNodeLogins(tx, nodeconfigs.NodeRoleDNS, req.NsNodeId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if req.NodeLogin.Id > 0 {
|
||||
err = models.SharedNodeLoginDAO.UpdateNodeLogin(tx, req.NodeLogin.Id, req.NodeLogin.Name, req.NodeLogin.Type, req.NodeLogin.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
_, err = models.SharedNodeLoginDAO.CreateNodeLogin(tx, nodeconfigs.NodeRoleDNS, req.NsNodeId, req.NodeLogin.Name, req.NodeLogin.Type, req.NodeLogin.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -278,8 +323,12 @@ func (this *NSNodeService) InstallNSNode(ctx context.Context, req *pb.InstallNSN
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 需要实现
|
||||
return nil, errors.New("尚未实现此功能")
|
||||
go func() {
|
||||
err = installers.SharedNSNodeQueue().InstallNodeProcess(req.NsNodeId, false)
|
||||
if err != nil {
|
||||
logs.Println("[RPC]install dns node:" + err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
return &pb.InstallNSNodeResponse{}, nil
|
||||
}
|
||||
@@ -446,3 +495,25 @@ func (this *NSNodeService) UpdateNSNodeConnectedAPINodes(ctx context.Context, re
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// UpdateNSNodeLogin 修改节点登录信息
|
||||
func (this *NSNodeService) UpdateNSNodeLogin(ctx context.Context, req *pb.UpdateNSNodeLoginRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
if req.NodeLogin.Id <= 0 {
|
||||
_, err := models.SharedNodeLoginDAO.CreateNodeLogin(tx, nodeconfigs.NodeRoleDNS, req.NsNodeId, req.NodeLogin.Name, req.NodeLogin.Type, req.NodeLogin.Params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = models.SharedNodeLoginDAO.UpdateNodeLogin(tx, req.NodeLogin.Id, req.NodeLogin.Name, req.NodeLogin.Type, req.NodeLogin.Params)
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user