mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): vpc create data cird validate
This commit is contained in:
@@ -1566,8 +1566,15 @@ func (self *SAliyunRegionDriver) ValidateCreateVpcData(ctx context.Context, user
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 17 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 17 and 29", self.GetProvider())
|
||||
|
||||
err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "IsInPrivateIpRange")
|
||||
}
|
||||
|
||||
if cidrV.Value.MaskLen > 24 {
|
||||
return input, httperrors.NewInputParameterError("invalid cidr range %s, mask length should less than or equal to 24", cidrV.Value.String())
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -82,8 +83,14 @@ func (self *SCtyunRegionDriver) ValidateCreateVpcData(ctx context.Context, userC
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
|
||||
err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "IsInPrivateIpRange")
|
||||
}
|
||||
|
||||
if cidrV.Value.MaskLen > 24 {
|
||||
return input, httperrors.NewInputParameterError("invalid cidr range %s, mask length should less than or equal to 24", cidrV.Value.String())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -2669,8 +2669,14 @@ func (self *SHuaWeiRegionDriver) ValidateCreateVpcData(ctx context.Context, user
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
|
||||
err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "IsInPrivateIpRange")
|
||||
}
|
||||
|
||||
if cidrV.Value.MaskLen > 24 {
|
||||
return input, httperrors.NewInputParameterError("invalid cidr range %s, mask length should less than or equal to 24", cidrV.Value.String())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -3198,3 +3199,20 @@ func (self *SManagedVirtualizationRegionDriver) RequestElasticcacheSetAutoRenew(
|
||||
|
||||
return ec.SetAutoRenew(autoRenew)
|
||||
}
|
||||
|
||||
func IsInPrivateIpRange(ar netutils.IPV4AddrRange) error {
|
||||
iprs := netutils.GetPrivateIPRanges()
|
||||
match := false
|
||||
for _, ipr := range iprs {
|
||||
if ipr.ContainsRange(ar) {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
return httperrors.NewInputParameterError("invalid cidr range %s", ar.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -725,6 +725,12 @@ func (self *SQcloudRegionDriver) ValidateCreateVpcData(ctx context.Context, user
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
|
||||
err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "IsInPrivateIpRange")
|
||||
}
|
||||
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 28 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 28", self.GetProvider())
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -78,8 +79,13 @@ func (self *SUcloudRegionDriver) ValidateCreateVpcData(ctx context.Context, user
|
||||
if err := cidrV.Validate(jsonutils.Marshal(input).(*jsonutils.JSONDict)); err != nil {
|
||||
return input, err
|
||||
}
|
||||
if cidrV.Value.MaskLen < 16 || cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be between 16 and 29", self.GetProvider())
|
||||
err := IsInPrivateIpRange(cidrV.Value.ToIPRange())
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "IsInPrivateIpRange")
|
||||
}
|
||||
|
||||
if cidrV.Value.MaskLen > 29 {
|
||||
return input, httperrors.NewInputParameterError("%s request the mask range should be less than or equal to 29", self.GetProvider())
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user