Skip to content

Commit

Permalink
Merge pull request #859 from ioito/hotfix/qx-aws-rule-create
Browse files Browse the repository at this point in the history
fix(aws): optimized aws rule create
  • Loading branch information
ioito authored Apr 8, 2024
2 parents c86e783 + a549a1d commit d732717
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/multicloud/aws/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ func (self *SRegion) CreateSecurityGroupRule(secGrpId string, opts *cloudprovide
if opts.Protocol != secrules.PROTO_ANY {
params["IpPermissions.1.IpProtocol"] = strings.ToLower(opts.Protocol)
}
if len(opts.CIDR) > 0 {
if _, err := netutils.NewIPV6Prefix(opts.CIDR); err == nil {
params["IpPermissions.1.Ipv6Ranges.1.CidrIpv6"] = opts.CIDR
params["IpPermissions.1.Ipv6Ranges.1.Description"] = opts.Desc
} else {
params["IpPermissions.1.IpRanges.1.CidrIp"] = opts.CIDR
params["IpPermissions.1.IpRanges.1.Description"] = opts.Desc
if len(opts.CIDR) == 0 {
opts.CIDR = "0.0.0.0/0"
}
if _, err := netutils.NewIPV6Prefix(opts.CIDR); err == nil {
params["IpPermissions.1.Ipv6Ranges.1.CidrIpv6"] = opts.CIDR
params["IpPermissions.1.Ipv6Ranges.1.Description"] = opts.Desc
} else {
if !strings.Contains(opts.CIDR, "/") {
opts.CIDR = opts.CIDR + "/32"
}
params["IpPermissions.1.IpRanges.1.CidrIp"] = opts.CIDR
params["IpPermissions.1.IpRanges.1.Description"] = opts.Desc
}
start, end := 0, 0
if len(opts.Ports) > 0 {
Expand Down Expand Up @@ -160,7 +164,7 @@ func (self *SRegion) CreateSecurityGroupRule(secGrpId string, opts *cloudprovide
for i := range ret.SecurityGroupRuleSet {
return &ret.SecurityGroupRuleSet[i], nil
}
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "after create")
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "after create %s", jsonutils.Marshal(opts))
}

func (self *SRegion) DeleteSecurityGroupRule(secGrpId string, direction, ruleId string) error {
Expand Down

0 comments on commit d732717

Please sign in to comment.