mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-30 01:46:37 +08:00
阶段性提交
This commit is contained in:
@@ -22,7 +22,7 @@ func NewLogDAO() *LogDAO {
|
||||
var SharedLogDAO = NewLogDAO()
|
||||
|
||||
// 创建管理员日志
|
||||
func (this *LogDAO) CreateAdminLog(adminId int, level string, description string, action string, ip string) error {
|
||||
func (this *LogDAO) CreateAdminLog(adminId int64, level string, description string, action string, ip string) error {
|
||||
op := NewLogOperator()
|
||||
op.AdminId, op.Level, op.Description, op.Action, op.Ip = adminId, level, description, action, ip
|
||||
op.Type = LogTypeAdmin
|
||||
|
||||
@@ -72,6 +72,7 @@ func (this *NodeDAO) CreateNode(name string, clusterId int) (nodeId int, err err
|
||||
op.NodeId = rands.HexString(32)
|
||||
op.Secret = rands.String(32)
|
||||
op.ClusterId = clusterId
|
||||
op.IsOn = 1
|
||||
op.State = NodeStateEnabled
|
||||
_, err = this.Save(op)
|
||||
if err != nil {
|
||||
@@ -102,8 +103,8 @@ func (this *NodeDAO) CountAllEnabledNodes() (int64, error) {
|
||||
func (this *NodeDAO) ListEnabledNodes(offset int64, size int64) (result []*Node, err error) {
|
||||
_, err = this.Query().
|
||||
State(NodeStateEnabled).
|
||||
Offset(int(offset)).
|
||||
Limit(int(size)).
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,15 +37,16 @@ func (this *NodeGrantDAO) EnableNodeGrant(id uint32) (rowsAffected int64, err er
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *NodeGrantDAO) DisableNodeGrant(id uint32) (rowsAffected int64, err error) {
|
||||
return this.Query().
|
||||
func (this *NodeGrantDAO) DisableNodeGrant(id int64) (err error) {
|
||||
_, err = this.Query().
|
||||
Pk(id).
|
||||
Set("state", NodeGrantStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *NodeGrantDAO) FindEnabledNodeGrant(id uint32) (*NodeGrant, error) {
|
||||
func (this *NodeGrantDAO) FindEnabledNodeGrant(id int64) (*NodeGrant, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", NodeGrantStateEnabled).
|
||||
@@ -62,3 +65,78 @@ func (this *NodeGrantDAO) FindNodeGrantName(id uint32) (string, error) {
|
||||
FindCol("")
|
||||
return name.(string), err
|
||||
}
|
||||
|
||||
// 创建认证信息
|
||||
func (this *NodeGrantDAO) CreateGrant(name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
|
||||
op := NewNodeGrantOperator()
|
||||
op.Name = name
|
||||
op.Method = method
|
||||
|
||||
switch method {
|
||||
case "user":
|
||||
op.Username = username
|
||||
op.Password = password
|
||||
op.Su = false // TODO 需要做到前端可以配置
|
||||
case "privateKey":
|
||||
op.PrivateKey = privateKey
|
||||
}
|
||||
op.Description = description
|
||||
op.NodeId = nodeId
|
||||
op.State = NodeGrantStateEnabled
|
||||
_, err = this.Save(op)
|
||||
return types.Int64(op.Id), err
|
||||
}
|
||||
|
||||
// 修改认证信息
|
||||
func (this *NodeGrantDAO) UpdateGrant(grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
|
||||
if grantId <= 0 {
|
||||
return errors.New("invalid grantId")
|
||||
}
|
||||
|
||||
op := NewNodeGrantOperator()
|
||||
op.Id = grantId
|
||||
op.Name = name
|
||||
op.Method = method
|
||||
|
||||
switch method {
|
||||
case "user":
|
||||
op.Username = username
|
||||
op.Password = password
|
||||
op.Su = false // TODO 需要做到前端可以配置
|
||||
case "privateKey":
|
||||
op.PrivateKey = privateKey
|
||||
}
|
||||
op.Description = description
|
||||
op.NodeId = nodeId
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 计算所有认证信息数量
|
||||
func (this *NodeGrantDAO) CountAllEnabledGrants() (int64, error) {
|
||||
return this.Query().
|
||||
State(NodeGrantStateEnabled).
|
||||
Count()
|
||||
}
|
||||
|
||||
// 列出单页的认证信息
|
||||
func (this *NodeGrantDAO) ListEnabledGrants(offset int64, size int64) (result []*NodeGrant, err error) {
|
||||
_, err = this.Query().
|
||||
State(NodeGrantStateEnabled).
|
||||
Offset(offset).
|
||||
Size(size).
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 列出所有的认证信息
|
||||
func (this *NodeGrantDAO) FindAllEnabledGrants() (result []*NodeGrant, err error) {
|
||||
_, err = this.Query().
|
||||
State(NodeGrantStateEnabled).
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package models
|
||||
type NodeGrant struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
Name string `field:"name"` // 名称
|
||||
Method string `field:"method"` // 登录方式
|
||||
Username string `field:"username"` // 用户名
|
||||
Password string `field:"password"` // 密码
|
||||
Su uint8 `field:"su"` // 是否需要su
|
||||
@@ -16,6 +17,7 @@ type NodeGrant struct {
|
||||
type NodeGrantOperator struct {
|
||||
Id interface{} // ID
|
||||
Name interface{} // 名称
|
||||
Method interface{} // 登录方式
|
||||
Username interface{} // 用户名
|
||||
Password interface{} // 密码
|
||||
Su interface{} // 是否需要su
|
||||
|
||||
@@ -3,6 +3,7 @@ package models
|
||||
// 节点
|
||||
type Node struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
NodeId string `field:"nodeId"` // 节点ID
|
||||
Secret string `field:"secret"` // 密钥
|
||||
Name string `field:"name"` // 节点名
|
||||
@@ -17,6 +18,7 @@ type Node struct {
|
||||
|
||||
type NodeOperator struct {
|
||||
Id interface{} // ID
|
||||
IsOn interface{} // 是否启用
|
||||
NodeId interface{} // 节点ID
|
||||
Secret interface{} // 密钥
|
||||
Name interface{} // 节点名
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -53,3 +55,67 @@ func (this *ServerDAO) FindEnabledServer(id uint32) (*Server, error) {
|
||||
}
|
||||
return result.(*Server), err
|
||||
}
|
||||
|
||||
// 创建服务
|
||||
func (this *ServerDAO) CreateServer(adminId int64, userId int64, clusterId int64, configJSON string, includeNodesJSON string, excludeNodesJSON string) (serverId int64, err error) {
|
||||
op := NewServerOperator()
|
||||
op.UserId = userId
|
||||
op.AdminId = adminId
|
||||
op.ClusterId = clusterId
|
||||
if len(configJSON) > 0 {
|
||||
op.Config = configJSON
|
||||
}
|
||||
if len(includeNodesJSON) > 0 {
|
||||
op.IncludeNodes = includeNodesJSON
|
||||
}
|
||||
if len(excludeNodesJSON) > 0 {
|
||||
op.ExcludeNodes = excludeNodesJSON
|
||||
}
|
||||
op.GroupIds = "[]"
|
||||
op.Version = 1
|
||||
op.IsOn = 1
|
||||
op.State = ServerStateEnabled
|
||||
_, err = this.Save(op)
|
||||
return types.Int64(op.Id), err
|
||||
}
|
||||
|
||||
// 修改服务
|
||||
func (this *ServerDAO) UpdateServer(serverId int64, clusterId int64, configJSON string, includeNodesJSON string, excludeNodesJSON string) error {
|
||||
if serverId <= 0 {
|
||||
return errors.New("serverId should not be smaller than 0")
|
||||
}
|
||||
op := NewServerOperator()
|
||||
op.Id = serverId
|
||||
op.ClusterId = clusterId
|
||||
if len(configJSON) > 0 {
|
||||
op.Config = configJSON
|
||||
}
|
||||
if len(includeNodesJSON) > 0 {
|
||||
op.IncludeNodes = includeNodesJSON
|
||||
}
|
||||
if len(excludeNodesJSON) > 0 {
|
||||
op.ExcludeNodes = excludeNodesJSON
|
||||
}
|
||||
op.Version = dbs.SQL("version=version+1")
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 计算所有可用服务数量
|
||||
func (this *ServerDAO) CountAllEnabledServers() (int64, error) {
|
||||
return this.Query().
|
||||
State(ServerStateEnabled).
|
||||
Count()
|
||||
}
|
||||
|
||||
// 列出单页的服务
|
||||
func (this *ServerDAO) ListEnabledServers(offset int64, size int64) (result []*Server, err error) {
|
||||
_, err = this.Query().
|
||||
State(ServerStateEnabled).
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package models
|
||||
// 服务
|
||||
type Server struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
GroupIds string `field:"groupIds"` // 分组ID列表
|
||||
Config string `field:"config"` // 服务配置,自动生成
|
||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||
IncludeNodes string `field:"includeNodes"` // 部署条件
|
||||
ExcludeNodes string `field:"excludeNodes"` // 节点排除条件
|
||||
Version uint32 `field:"version"` // 版本号
|
||||
@@ -16,10 +18,12 @@ type Server struct {
|
||||
|
||||
type ServerOperator struct {
|
||||
Id interface{} // ID
|
||||
IsOn interface{} // 是否启用
|
||||
UserId interface{} // 用户ID
|
||||
AdminId interface{} // 管理员ID
|
||||
GroupIds interface{} // 分组ID列表
|
||||
Config interface{} // 服务配置,自动生成
|
||||
ClusterId interface{} // 集群ID
|
||||
IncludeNodes interface{} // 部署条件
|
||||
ExcludeNodes interface{} // 节点排除条件
|
||||
Version interface{} // 版本号
|
||||
|
||||
Reference in New Issue
Block a user