mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8086 from lvyangyang/dns_recordset_fix
fix:/dnsrecordset 增加CNAME检查,dnsrecord update的重复检查
This commit is contained in:
@@ -15,9 +15,14 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -47,7 +52,10 @@ type DnsRecordSetCreateInput struct {
|
||||
type DnsRecordSetUpdateInput struct {
|
||||
apis.EnabledStatusStandaloneResourceBaseUpdateInput
|
||||
|
||||
SDnsRecordSet
|
||||
DnsType string `json:"dns_type"`
|
||||
DnsValue string `json:"dns_value"`
|
||||
TTL *int64 `json:"ttl"`
|
||||
MxPriority *int64 `json:"mx_priority"`
|
||||
|
||||
TrafficPolicies []DnsRecordPolicy
|
||||
}
|
||||
@@ -76,3 +84,29 @@ type DnsRecordDisableInput struct {
|
||||
type DnsRecordSetTrafficPoliciesInput struct {
|
||||
TrafficPolicies []DnsRecordPolicy `json:"traffic_policies"`
|
||||
}
|
||||
|
||||
func (recordset *SDnsRecordSet) ValidateDnsrecordValue() error {
|
||||
domainReg := regexp.MustCompile(`^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$`)
|
||||
switch cloudprovider.TDnsType(recordset.DnsType) {
|
||||
case cloudprovider.DnsTypeMX:
|
||||
if recordset.MxPriority < 1 || recordset.MxPriority > 50 {
|
||||
return httperrors.NewOutOfRangeError("mx_priority range limited to [1,50]")
|
||||
}
|
||||
if !domainReg.MatchString(recordset.DnsValue) {
|
||||
return httperrors.NewInputParameterError("invalid domain %s for MX record", recordset.DnsValue)
|
||||
}
|
||||
case cloudprovider.DnsTypeA:
|
||||
if !regutils.MatchIP4Addr(recordset.DnsValue) {
|
||||
return httperrors.NewInputParameterError("invalid ipv4 %s for A record", recordset.DnsValue)
|
||||
}
|
||||
case cloudprovider.DnsTypeAAAA:
|
||||
if !regutils.MatchIP6Addr(recordset.DnsValue) {
|
||||
return httperrors.NewInputParameterError("invalid ipv6 %s for AAAA record", recordset.DnsValue)
|
||||
}
|
||||
case cloudprovider.DnsTypeCNAME:
|
||||
if !domainReg.MatchString(recordset.DnsValue) {
|
||||
return httperrors.NewInputParameterError("invalid domain %s for CNAME record", recordset.DnsValue)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user