Better naming plus minor changes

Signed-off-by: Nick Jüttner <nick@juni.io>
This commit is contained in:
Nick Jüttner 2018-06-01 09:31:21 +02:00
parent efe46c429d
commit 52819663f8
2 changed files with 5 additions and 5 deletions

View File

@ -82,7 +82,7 @@ type planTableRow struct {
}
func (t planTable) addCurrent(e *endpoint.Endpoint) {
dnsName, err := stripLowerName(e.DNSName)
dnsName, err := validateDNSName(e.DNSName)
if err != nil {
log.Errorf("Skipping endpoint %v", err)
return
@ -94,7 +94,7 @@ func (t planTable) addCurrent(e *endpoint.Endpoint) {
}
func (t planTable) addCandidate(e *endpoint.Endpoint) {
dnsName, err := stripLowerName(e.DNSName)
dnsName, err := validateDNSName(e.DNSName)
if err != nil {
log.Errorf("Skipping endpoint %v", err)
return
@ -191,7 +191,7 @@ func shouldUpdateTTL(desired, current *endpoint.Endpoint) bool {
return desired.RecordTTL != current.RecordTTL
}
func stripLowerName(dnsName string) (string, error) {
func validateDNSName(dnsName string) (string, error) {
dnsName = strings.ToLower(dnsName)
dnsName = strings.TrimSpace(dnsName)
reg, err := regexp.Compile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
@ -199,7 +199,7 @@ func stripLowerName(dnsName string) (string, error) {
return "", err
}
if !reg.MatchString(dnsName) {
return "", fmt.Errorf("%s because dns record is invalid", dnsName)
return "", fmt.Errorf("%s because DNS name is invalid", dnsName)
}
return dnsName, nil
}

View File

@ -110,7 +110,7 @@ func (suite *PlanTestSuite) SetupTest() {
RecordType: "CNAME",
}
suite.invalidWithTTL = &endpoint.Endpoint{
DNSName: "5HW598OVOMBY!!!.cluster.juni.io",
DNSName: "www-test?32.cluster.com",
Targets: endpoint.Targets{"127.0.0.1"},
RecordType: "A",
RecordTTL: 300,