Skip to content

Commit

Permalink
fix: sec rule export missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jul 16, 2020
1 parent bea60df commit 3ddcaad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/climc/shell/compute/secgrouprules.go
Expand Up @@ -31,6 +31,8 @@ func init() {
Direction string `help:"filter Direction of rule" choices:"in|out"`
Protocol string `help:"filter Protocol of rule" choices:"any|tcp|udp|icmp"`
Action string `help:"filter Actin of rule" choices:"allow|deny"`
Ports string `help:"filter Ports of rule"`
Ip string `help:"filter cidr of rule"`
}

R(&SecGroupRulesListOptions{}, "secgroup-rule-list", "List all security group", func(s *mcclient.ClientSession, args *SecGroupRulesListOptions) error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/compute/secgroup.go
Expand Up @@ -180,6 +180,10 @@ type SecurityGroupRuleListInput struct {
Action string `json:"action"`
// 以protocol字段过滤安全组规则
Protocol string `json:"protocol"`
// 以ports字段过滤安全组规则
Ports string `json:"ports"`
// 根据ip模糊匹配安全组规则
Ip string `json:"ip"`
}

type SecgroupResourceInput struct {
Expand Down
32 changes: 24 additions & 8 deletions pkg/compute/models/secgrouprules.go
Expand Up @@ -179,13 +179,6 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(
if err != nil {
return nil, errors.Wrap(err, "SSecurityGroupResourceBaseManager.ListItemFilter")
}
/*if defsecgroup := query.Secgroup; len(defsecgroup) > 0 {
if secgroup, _ := SecurityGroupManager.FetchByIdOrName(userCred, defsecgroup); secgroup != nil {
sql = sql.Equals("secgroup_id", secgroup.GetId())
} else {
return nil, httperrors.NewNotFoundError("Security Group %s not found", defsecgroup)
}
}*/
if len(query.Direction) > 0 {
sql = sql.Equals("direction", query.Direction)
}
Expand All @@ -195,7 +188,13 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(
if len(query.Protocol) > 0 {
sql = sql.Equals("protocol", query.Protocol)
}
sql = sql.GroupBy("secgroup_id")
if len(query.Ports) > 0 {
sql = sql.Equals("ports", query.Ports)
}
if len(query.Ip) > 0 {
sql = sql.Like("cidr", "%"+query.Ip+"%")
}

return sql, nil
}

Expand Down Expand Up @@ -519,3 +518,20 @@ func (self *SSecurityGroupRule) GetOwnerId() mcclient.IIdentityProvider {
func (manager *SSecurityGroupRuleManager) ResourceScope() rbacutils.TRbacScope {
return rbacutils.ScopeProject
}

func (manager *SSecurityGroupRuleManager) ListItemExportKeys(ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
keys stringutils2.SSortedStrings,
) (*sqlchemy.SQuery, error) {
var err error
q, err = manager.SResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SResourceBaseManager.ListItemExportKeys")
}
q, err = manager.SSecurityGroupResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
if err != nil {
return nil, errors.Wrap(err, "SSecurityGroupResourceBaseManager.ListItemExportKeys")
}
return q, nil
}

0 comments on commit 3ddcaad

Please sign in to comment.