mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-29 01:06:36 +08:00
实现DNS节点远程安装
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
// 节点授权
|
||||
// NodeGrant 节点授权
|
||||
type NodeGrant struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
@@ -12,6 +12,7 @@ type NodeGrant struct {
|
||||
PrivateKey string `field:"privateKey"` // 密钥
|
||||
Description string `field:"description"` // 备注
|
||||
NodeId uint32 `field:"nodeId"` // 专有节点
|
||||
Role string `field:"role"` // 角色
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
}
|
||||
@@ -27,6 +28,7 @@ type NodeGrantOperator struct {
|
||||
PrivateKey interface{} // 密钥
|
||||
Description interface{} // 备注
|
||||
NodeId interface{} // 专有节点
|
||||
Role interface{} // 角色
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -36,7 +37,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableNodeLogin 启用条目
|
||||
func (this *NodeLoginDAO) EnableNodeLogin(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -44,16 +45,16 @@ func (this *NodeLoginDAO) EnableNodeLogin(tx *dbs.Tx, id uint32) (rowsAffected i
|
||||
Update()
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *NodeLoginDAO) DisableNodeLogin(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||
// DisableNodeLogin 禁用条目
|
||||
func (this *NodeLoginDAO) DisableNodeLogin(tx *dbs.Tx, loginId int64) (rowsAffected int64, err error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
Pk(loginId).
|
||||
Set("state", NodeLoginStateDisabled).
|
||||
Update()
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *NodeLoginDAO) FindEnabledNodeLogin(tx *dbs.Tx, id uint32) (*NodeLogin, error) {
|
||||
// FindEnabledNodeLogin 查找启用中的条目
|
||||
func (this *NodeLoginDAO) FindEnabledNodeLogin(tx *dbs.Tx, id int64) (*NodeLogin, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Attr("state", NodeLoginStateEnabled).
|
||||
@@ -64,7 +65,7 @@ func (this *NodeLoginDAO) FindEnabledNodeLogin(tx *dbs.Tx, id uint32) (*NodeLogi
|
||||
return result.(*NodeLogin), err
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
// FindNodeLoginName 根据主键查找名称
|
||||
func (this *NodeLoginDAO) FindNodeLoginName(tx *dbs.Tx, id uint32) (string, error) {
|
||||
name, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -73,9 +74,14 @@ func (this *NodeLoginDAO) FindNodeLoginName(tx *dbs.Tx, id uint32) (string, erro
|
||||
return name.(string), err
|
||||
}
|
||||
|
||||
// 创建认证
|
||||
func (this *NodeLoginDAO) CreateNodeLogin(tx *dbs.Tx, nodeId int64, name string, loginType string, paramsJSON []byte) (loginId int64, err error) {
|
||||
// CreateNodeLogin 创建认证
|
||||
func (this *NodeLoginDAO) CreateNodeLogin(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64, name string, loginType string, paramsJSON []byte) (loginId int64, err error) {
|
||||
if len(role) == 0 {
|
||||
role = nodeconfigs.NodeRoleNode
|
||||
}
|
||||
|
||||
login := NewNodeLoginOperator()
|
||||
login.Role = role
|
||||
login.NodeId = nodeId
|
||||
login.Name = name
|
||||
login.Type = loginType
|
||||
@@ -85,7 +91,7 @@ func (this *NodeLoginDAO) CreateNodeLogin(tx *dbs.Tx, nodeId int64, name string,
|
||||
return types.Int64(login.Id), err
|
||||
}
|
||||
|
||||
// 修改认证
|
||||
// UpdateNodeLogin 修改认证
|
||||
func (this *NodeLoginDAO) UpdateNodeLogin(tx *dbs.Tx, loginId int64, name string, loginType string, paramsJSON []byte) error {
|
||||
if loginId <= 0 {
|
||||
return errors.New("invalid loginId")
|
||||
@@ -99,9 +105,13 @@ func (this *NodeLoginDAO) UpdateNodeLogin(tx *dbs.Tx, loginId int64, name string
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找认证
|
||||
func (this *NodeLoginDAO) FindEnabledNodeLoginWithNodeId(tx *dbs.Tx, nodeId int64) (*NodeLogin, error) {
|
||||
// FindEnabledNodeLoginWithNodeId 查找认证
|
||||
func (this *NodeLoginDAO) FindEnabledNodeLoginWithNodeId(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) (*NodeLogin, error) {
|
||||
if len(role) == 0 {
|
||||
role = nodeconfigs.NodeRoleNode
|
||||
}
|
||||
one, err := this.Query(tx).
|
||||
Attr("role", role).
|
||||
Attr("nodeId", nodeId).
|
||||
State(NodeLoginStateEnabled).
|
||||
Find()
|
||||
@@ -114,9 +124,13 @@ func (this *NodeLoginDAO) FindEnabledNodeLoginWithNodeId(tx *dbs.Tx, nodeId int6
|
||||
return one.(*NodeLogin), nil
|
||||
}
|
||||
|
||||
// 禁用某个节点的认证
|
||||
func (this *NodeLoginDAO) DisableNodeLogins(tx *dbs.Tx, nodeId int64) error {
|
||||
// DisableNodeLogins 禁用某个节点的认证
|
||||
func (this *NodeLoginDAO) DisableNodeLogins(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64) error {
|
||||
if len(role) == 0 {
|
||||
role = nodeconfigs.NodeRoleNode
|
||||
}
|
||||
_, err := this.Query(tx).
|
||||
Attr("role", role).
|
||||
Attr("nodeId", nodeId).
|
||||
Set("state", NodeLoginStateDisabled).
|
||||
Update()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package models
|
||||
|
||||
//
|
||||
// NodeLogin 节点登录信息
|
||||
type NodeLogin struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||
Role string `field:"role"` // 角色
|
||||
Name string `field:"name"` // 名称
|
||||
Type string `field:"type"` // 类型:ssh,agent
|
||||
Params string `field:"params"` // 配置参数
|
||||
@@ -13,6 +14,7 @@ type NodeLogin struct {
|
||||
type NodeLoginOperator struct {
|
||||
Id interface{} // ID
|
||||
NodeId interface{} // 节点ID
|
||||
Role interface{} // 角色
|
||||
Name interface{} // 名称
|
||||
Type interface{} // 类型:ssh,agent
|
||||
Params interface{} // 配置参数
|
||||
|
||||
@@ -161,6 +161,14 @@ func (this *NSClusterDAO) FindClusterAccessLog(tx *dbs.Tx, clusterId int64) ([]b
|
||||
return []byte(accessLog), err
|
||||
}
|
||||
|
||||
// FindClusterGrantId 查找集群的认证ID
|
||||
func (this *NSClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
Pk(clusterId).
|
||||
Result("grantId").
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更改
|
||||
func (this *NSClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||
return SharedNodeTaskDAO.CreateClusterTask(tx, nodeconfigs.NodeRoleDNS, clusterId, NSNodeTaskTypeConfigChanged)
|
||||
|
||||
@@ -8,6 +8,7 @@ type NSCluster struct {
|
||||
InstallDir string `field:"installDir"` // 安装目录
|
||||
State uint8 `field:"state"` // 状态
|
||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||
GrantId uint32 `field:"grantId"` // 授权ID
|
||||
}
|
||||
|
||||
type NSClusterOperator struct {
|
||||
@@ -17,6 +18,7 @@ type NSClusterOperator struct {
|
||||
InstallDir interface{} // 安装目录
|
||||
State interface{} // 状态
|
||||
AccessLog interface{} // 访问日志配置
|
||||
GrantId interface{} // 授权ID
|
||||
}
|
||||
|
||||
func NewNSClusterOperator() *NSClusterOperator {
|
||||
|
||||
@@ -521,6 +521,27 @@ func (this *NSNodeDAO) FindAllNodeIdsMatch(tx *dbs.Tx, clusterId int64, includeS
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateNodeInstallStatus 修改节点的安装状态
|
||||
func (this *NSNodeDAO) UpdateNodeInstallStatus(tx *dbs.Tx, nodeId int64, status *NodeInstallStatus) error {
|
||||
if status == nil {
|
||||
_, err := this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Set("installStatus", "null").
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := json.Marshal(status)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = this.Query(tx).
|
||||
Pk(nodeId).
|
||||
Set("installStatus", string(data)).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *NSNodeDAO) NotifyUpdate(tx *dbs.Tx, nodeId int64) error {
|
||||
// TODO 先什么都不做
|
||||
|
||||
Reference in New Issue
Block a user