Archived
实现DNS节点远程安装
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user