mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
loadbalancers: use httperrors for parameter validation results
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
@@ -33,16 +34,16 @@ func (aclEntry *SLoadbalancerAclEntry) Validate(data *jsonutils.JSONDict) error
|
||||
} else {
|
||||
ip := net.ParseIP(aclEntry.Cidr).To4()
|
||||
if ip == nil {
|
||||
return fmt.Errorf("invalid addr %s", aclEntry.Cidr)
|
||||
return httperrors.NewInputParameterError("invalid addr %s", aclEntry.Cidr)
|
||||
}
|
||||
}
|
||||
if commentLimit := 128; len(aclEntry.Comment) > commentLimit {
|
||||
return fmt.Errorf("comment too long (%d>=%d)",
|
||||
return httperrors.NewInputParameterError("comment too long (%d>=%d)",
|
||||
len(aclEntry.Comment), commentLimit)
|
||||
}
|
||||
for _, r := range aclEntry.Comment {
|
||||
if !unicode.IsPrint(r) {
|
||||
return fmt.Errorf("comment contains non-printable char: %v", r)
|
||||
return httperrors.NewInputParameterError("comment contains non-printable char: %v", r)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -68,7 +69,7 @@ func (aclEntries *SLoadbalancerAclEntries) Validate(data *jsonutils.JSONDict) er
|
||||
}
|
||||
if _, ok := found[aclEntry.Cidr]; ok {
|
||||
// error so that the user has a chance to deal with comments
|
||||
return fmt.Errorf("acl cidr duplicate %s", aclEntry.Cidr)
|
||||
return httperrors.NewInputParameterError("acl cidr duplicate %s", aclEntry.Cidr)
|
||||
}
|
||||
found[aclEntry.Cidr] = true
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (p *SLoadbalancerAgentParamsTelegraf) Validate(data *jsonutils.JSONDict) er
|
||||
if p.InfluxDbOutputUrl != "" {
|
||||
_, err := url.Parse(p.InfluxDbOutputUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
return httperrors.NewInputParameterError("telegraf params: invalid influxdb url: %s", err)
|
||||
}
|
||||
}
|
||||
if p.HaproxyInputInterval <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user