mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 23:00:25 +08:00
SSH认证列表可以使用关键词搜索,返回内容增加用户名
This commit is contained in:
@@ -34,7 +34,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableNodeGrant 启用条目
|
||||||
func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -42,7 +42,7 @@ func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected i
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableNodeGrant 禁用条目
|
||||||
func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -51,7 +51,7 @@ func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledNodeGrant 查找启用中的条目
|
||||||
func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant, error) {
|
func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -63,7 +63,7 @@ func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant
|
|||||||
return result.(*NodeGrant), err
|
return result.(*NodeGrant), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindNodeGrantName 根据主键查找名称
|
||||||
func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, error) {
|
func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, error) {
|
||||||
name, err := this.Query(tx).
|
name, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -72,7 +72,7 @@ func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, erro
|
|||||||
return name.(string), err
|
return name.(string), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建认证信息
|
// CreateGrant 创建认证信息
|
||||||
func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
|
func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
|
||||||
op := NewNodeGrantOperator()
|
op := NewNodeGrantOperator()
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
@@ -94,7 +94,7 @@ func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, me
|
|||||||
return types.Int64(op.Id), err
|
return types.Int64(op.Id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改认证信息
|
// UpdateGrant 修改认证信息
|
||||||
func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
|
func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
|
||||||
if grantId <= 0 {
|
if grantId <= 0 {
|
||||||
return errors.New("invalid grantId")
|
return errors.New("invalid grantId")
|
||||||
@@ -119,17 +119,26 @@ func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, me
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有认证信息数量
|
// CountAllEnabledGrants 计算所有认证信息数量
|
||||||
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx) (int64, error) {
|
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
return this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled)
|
||||||
Count()
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的认证信息
|
// ListEnabledGrants 列出单页的认证信息
|
||||||
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64) (result []*NodeGrant, err error) {
|
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, keyword string, offset int64, size int64) (result []*NodeGrant, err error) {
|
||||||
_, err = this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled)
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Size(size).
|
Size(size).
|
||||||
DescPk().
|
DescPk().
|
||||||
@@ -138,7 +147,7 @@ func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有的认证信息
|
// FindAllEnabledGrants 列出所有的认证信息
|
||||||
func (this *NodeGrantDAO) FindAllEnabledGrants(tx *dbs.Tx) (result []*NodeGrant, err error) {
|
func (this *NodeGrantDAO) FindAllEnabledGrants(tx *dbs.Tx) (result []*NodeGrant, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled).
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
count, err := models.SharedNodeGrantDAO.CountAllEnabledGrants(tx)
|
count, err := models.SharedNodeGrantDAO.CountAllEnabledGrants(tx, req.Keyword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb
|
|||||||
|
|
||||||
tx := this.NullTx()
|
tx := this.NullTx()
|
||||||
|
|
||||||
grants, err := models.SharedNodeGrantDAO.ListEnabledGrants(tx, req.Offset, req.Size)
|
grants, err := models.SharedNodeGrantDAO.ListEnabledGrants(tx, req.Keyword, req.Offset, req.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -99,6 +99,7 @@ func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb
|
|||||||
Id: int64(grant.Id),
|
Id: int64(grant.Id),
|
||||||
Name: grant.Name,
|
Name: grant.Name,
|
||||||
Method: grant.Method,
|
Method: grant.Method,
|
||||||
|
Username: grant.Username,
|
||||||
Password: grant.Password,
|
Password: grant.Password,
|
||||||
Su: grant.Su == 1,
|
Su: grant.Su == 1,
|
||||||
PrivateKey: grant.PrivateKey,
|
PrivateKey: grant.PrivateKey,
|
||||||
@@ -126,6 +127,7 @@ func (this *NodeGrantService) FindAllEnabledNodeGrants(ctx context.Context, req
|
|||||||
Id: int64(grant.Id),
|
Id: int64(grant.Id),
|
||||||
Name: grant.Name,
|
Name: grant.Name,
|
||||||
Method: grant.Method,
|
Method: grant.Method,
|
||||||
|
Username: grant.Username,
|
||||||
Password: grant.Password,
|
Password: grant.Password,
|
||||||
Su: grant.Su == 1,
|
Su: grant.Su == 1,
|
||||||
PrivateKey: grant.PrivateKey,
|
PrivateKey: grant.PrivateKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user