Add validation for DNS server config
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -109,6 +110,7 @@ The format is: "protocol://ip:port?parameter=value¶meter=value"
|
||||
ReleaseLevel: config.ReleaseLevelStable,
|
||||
DefaultValue: defaultNameServers,
|
||||
ValidationRegex: fmt.Sprintf("^(%s|%s|%s)://.*", ServerTypeDoT, ServerTypeDNS, ServerTypeTCP),
|
||||
ValidationFunc: validateNameservers,
|
||||
Annotations: config.Annotations{
|
||||
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
||||
config.DisplayOrderAnnotation: cfgOptionNameServersOrder,
|
||||
@@ -265,6 +267,22 @@ The format is: "protocol://ip:port?parameter=value¶meter=value"
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateNameservers(value interface{}) error {
|
||||
list, ok := value.([]string)
|
||||
if !ok {
|
||||
return errors.New("invalid type")
|
||||
}
|
||||
|
||||
for i, entry := range list {
|
||||
_, _, err := createResolver(entry, ServerSourceConfigured)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse DNS server \"%s\" (#%d): %w", entry, i+1, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatScopeList(list []string) string {
|
||||
formatted := make([]string, 0, len(list))
|
||||
for _, domain := range list {
|
||||
|
||||
Reference in New Issue
Block a user