Skip to content

Commit 05c2955

Browse files
committed
SSH认证列表可以使用关键词搜索,返回内容增加用户名
1 parent f0ffa48 commit 05c2955

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

internal/db/models/node_grant_dao.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ func init() {
3434
})
3535
}
3636

37-
// 启用条目
37+
// EnableNodeGrant 启用条目
3838
func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
3939
return this.Query(tx).
4040
Pk(id).
4141
Set("state", NodeGrantStateEnabled).
4242
Update()
4343
}
4444

45-
// 禁用条目
45+
// DisableNodeGrant 禁用条目
4646
func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
4747
_, err = this.Query(tx).
4848
Pk(id).
@@ -51,7 +51,7 @@ func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
5151
return err
5252
}
5353

54-
// 查找启用中的条目
54+
// FindEnabledNodeGrant 查找启用中的条目
5555
func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant, error) {
5656
result, err := this.Query(tx).
5757
Pk(id).
@@ -63,7 +63,7 @@ func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant
6363
return result.(*NodeGrant), err
6464
}
6565

66-
// 根据主键查找名称
66+
// FindNodeGrantName 根据主键查找名称
6767
func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, error) {
6868
name, err := this.Query(tx).
6969
Pk(id).
@@ -72,7 +72,7 @@ func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, erro
7272
return name.(string), err
7373
}
7474

75-
// 创建认证信息
75+
// CreateGrant 创建认证信息
7676
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) {
7777
op := NewNodeGrantOperator()
7878
op.AdminId = adminId
@@ -94,7 +94,7 @@ func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, me
9494
return types.Int64(op.Id), err
9595
}
9696

97-
// 修改认证信息
97+
// UpdateGrant 修改认证信息
9898
func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
9999
if grantId <= 0 {
100100
return errors.New("invalid grantId")
@@ -119,17 +119,26 @@ func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, me
119119
return err
120120
}
121121

122-
// 计算所有认证信息数量
123-
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx) (int64, error) {
124-
return this.Query(tx).
125-
State(NodeGrantStateEnabled).
126-
Count()
122+
// CountAllEnabledGrants 计算所有认证信息数量
123+
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx, keyword string) (int64, error) {
124+
query := this.Query(tx).
125+
State(NodeGrantStateEnabled)
126+
if len(keyword) > 0 {
127+
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
128+
Param("keyword", "%"+keyword+"%")
129+
}
130+
return query.Count()
127131
}
128132

129-
// 列出单页的认证信息
130-
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64) (result []*NodeGrant, err error) {
131-
_, err = this.Query(tx).
132-
State(NodeGrantStateEnabled).
133+
// ListEnabledGrants 列出单页的认证信息
134+
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, keyword string, offset int64, size int64) (result []*NodeGrant, err error) {
135+
query := this.Query(tx).
136+
State(NodeGrantStateEnabled)
137+
if len(keyword) > 0 {
138+
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
139+
Param("keyword", "%"+keyword+"%")
140+
}
141+
_, err = query.
133142
Offset(offset).
134143
Size(size).
135144
DescPk().
@@ -138,7 +147,7 @@ func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64
138147
return
139148
}
140149

141-
// 列出所有的认证信息
150+
// FindAllEnabledGrants 列出所有的认证信息
142151
func (this *NodeGrantDAO) FindAllEnabledGrants(tx *dbs.Tx) (result []*NodeGrant, err error) {
143152
_, err = this.Query(tx).
144153
State(NodeGrantStateEnabled).

internal/rpc/services/service_node_grant.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req
7373

7474
tx := this.NullTx()
7575

76-
count, err := models.SharedNodeGrantDAO.CountAllEnabledGrants(tx)
76+
count, err := models.SharedNodeGrantDAO.CountAllEnabledGrants(tx, req.Keyword)
7777
if err != nil {
7878
return nil, err
7979
}
@@ -89,7 +89,7 @@ func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb
8989

9090
tx := this.NullTx()
9191

92-
grants, err := models.SharedNodeGrantDAO.ListEnabledGrants(tx, req.Offset, req.Size)
92+
grants, err := models.SharedNodeGrantDAO.ListEnabledGrants(tx, req.Keyword, req.Offset, req.Size)
9393
if err != nil {
9494
return nil, err
9595
}
@@ -99,6 +99,7 @@ func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb
9999
Id: int64(grant.Id),
100100
Name: grant.Name,
101101
Method: grant.Method,
102+
Username: grant.Username,
102103
Password: grant.Password,
103104
Su: grant.Su == 1,
104105
PrivateKey: grant.PrivateKey,
@@ -126,6 +127,7 @@ func (this *NodeGrantService) FindAllEnabledNodeGrants(ctx context.Context, req
126127
Id: int64(grant.Id),
127128
Name: grant.Name,
128129
Method: grant.Method,
130+
Username: grant.Username,
129131
Password: grant.Password,
130132
Su: grant.Su == 1,
131133
PrivateKey: grant.PrivateKey,

0 commit comments

Comments
 (0)