validate dns entry does not contain whitespace (#2512)

This commit is contained in:
Matthew R Kasun
2023-08-22 02:20:28 -04:00
committed by GitHub
parent a775d7402f
commit d366c23c63
3 changed files with 28 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package logic
import (
"encoding/json"
"os"
"regexp"
"sort"
validator "github.com/go-playground/validator/v10"
@@ -203,6 +204,11 @@ func ValidateDNSCreate(entry models.DNSEntry) error {
v := validator.New()
_ = v.RegisterValidation("whitespace", func(f1 validator.FieldLevel) bool {
match, _ := regexp.MatchString(`\s`, entry.Name)
return !match
})
_ = v.RegisterValidation("name_unique", func(fl validator.FieldLevel) bool {
num, err := GetDNSEntryNum(entry.Name, entry.Network)
return err == nil && num == 0
@@ -227,6 +233,11 @@ func ValidateDNSUpdate(change models.DNSEntry, entry models.DNSEntry) error {
v := validator.New()
_ = v.RegisterValidation("whitespace", func(f1 validator.FieldLevel) bool {
match, _ := regexp.MatchString(`\s`, entry.Name)
return !match
})
_ = v.RegisterValidation("name_unique", func(fl validator.FieldLevel) bool {
//if name & net not changing name we are good
if change.Name == entry.Name && change.Network == entry.Network {