[SSH认证]记录创建的管理员ID

This commit is contained in:
刘祥超
2020-11-27 10:02:46 +08:00
parent 83be53eac0
commit 1284280f9f
4 changed files with 12 additions and 3 deletions

View File

@@ -73,8 +73,9 @@ func (this *NodeGrantDAO) FindNodeGrantName(id uint32) (string, error) {
}
// 创建认证信息
func (this *NodeGrantDAO) CreateGrant(name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
func (this *NodeGrantDAO) CreateGrant(adminId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
op := NewNodeGrantOperator()
op.AdminId = adminId
op.Name = name
op.Method = method

View File

@@ -3,6 +3,7 @@ package models
// 节点授权
type NodeGrant struct {
Id uint32 `field:"id"` // ID
AdminId uint32 `field:"adminId"` // 管理员ID
Name string `field:"name"` // 名称
Method string `field:"method"` // 登录方式
Username string `field:"username"` // 用户名
@@ -17,6 +18,7 @@ type NodeGrant struct {
type NodeGrantOperator struct {
Id interface{} // ID
AdminId interface{} // 管理员ID
Name interface{} // 名称
Method interface{} // 登录方式
Username interface{} // 用户名

View File

@@ -13,12 +13,12 @@ type NodeGrantService struct {
}
func (this *NodeGrantService) CreateNodeGrant(ctx context.Context, req *pb.CreateNodeGrantRequest) (*pb.CreateNodeGrantResponse, error) {
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
adminId, err := this.ValidateAdmin(ctx, 0)
if err != nil {
return nil, err
}
grantId, err := models.SharedNodeGrantDAO.CreateGrant(req.Name, req.Method, req.Username, req.Password, req.PrivateKey, req.Description, req.NodeId)
grantId, err := models.SharedNodeGrantDAO.CreateGrant(adminId, req.Name, req.Method, req.Username, req.Password, req.PrivateKey, req.Description, req.NodeId)
if err != nil {
return nil, err
}

View File

@@ -81,5 +81,11 @@ func upgradeV0_0_3(db *dbs.DB) error {
return err
}
// 升级edgeNodeGrants
_, err = db.Exec("UPDATE edgeNodeGrants SET adminId=? WHERE adminId=0", adminId)
if err != nil {
return err
}
return nil
}