Add validation for DNS server config
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package resolver
|
package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -109,6 +110,7 @@ The format is: "protocol://ip:port?parameter=value¶meter=value"
|
|||||||
ReleaseLevel: config.ReleaseLevelStable,
|
ReleaseLevel: config.ReleaseLevelStable,
|
||||||
DefaultValue: defaultNameServers,
|
DefaultValue: defaultNameServers,
|
||||||
ValidationRegex: fmt.Sprintf("^(%s|%s|%s)://.*", ServerTypeDoT, ServerTypeDNS, ServerTypeTCP),
|
ValidationRegex: fmt.Sprintf("^(%s|%s|%s)://.*", ServerTypeDoT, ServerTypeDNS, ServerTypeTCP),
|
||||||
|
ValidationFunc: validateNameservers,
|
||||||
Annotations: config.Annotations{
|
Annotations: config.Annotations{
|
||||||
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
||||||
config.DisplayOrderAnnotation: cfgOptionNameServersOrder,
|
config.DisplayOrderAnnotation: cfgOptionNameServersOrder,
|
||||||
@@ -265,6 +267,22 @@ The format is: "protocol://ip:port?parameter=value¶meter=value"
|
|||||||
return nil
|
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 {
|
func formatScopeList(list []string) string {
|
||||||
formatted := make([]string, 0, len(list))
|
formatted := make([]string, 0, len(list))
|
||||||
for _, domain := range list {
|
for _, domain := range list {
|
||||||
|
|||||||
Reference in New Issue
Block a user