mirror of https://github.com/docker/cli.git
Relax dns search to accept empty domain
In that case /etc/resolv.conf will be generated with no search option. Usage: --dns-search=. Docker-DCO-1.1-Signed-off-by: Fabio Falci <fabiofalci@gmail.com> (github: fabiofalci)
This commit is contained in:
parent
7297bfab30
commit
9fdc86ac55
11
opts/opts.go
11
opts/opts.go
|
@ -137,7 +137,16 @@ func ValidateIp4Address(val string) (string, error) {
|
|||
return "", fmt.Errorf("%s is not an ip4 address", val)
|
||||
}
|
||||
|
||||
func ValidateDomain(val string) (string, error) {
|
||||
// Validates domain for resolvconf search configuration.
|
||||
// A zero length domain is represented by .
|
||||
func ValidateDnsSearch(val string) (string, error) {
|
||||
if val = strings.Trim(val, " "); val == "." {
|
||||
return val, nil
|
||||
}
|
||||
return validateDomain(val)
|
||||
}
|
||||
|
||||
func validateDomain(val string) (string, error) {
|
||||
alpha := regexp.MustCompile(`[a-zA-Z]`)
|
||||
if alpha.FindString(val) == "" {
|
||||
return "", fmt.Errorf("%s is not a valid domain", val)
|
||||
|
|
|
@ -23,8 +23,9 @@ func TestValidateIP4(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestValidateDomain(t *testing.T) {
|
||||
func TestValidateDnsSearch(t *testing.T) {
|
||||
valid := []string{
|
||||
`.`,
|
||||
`a`,
|
||||
`a.`,
|
||||
`1.foo`,
|
||||
|
@ -49,7 +50,8 @@ func TestValidateDomain(t *testing.T) {
|
|||
|
||||
invalid := []string{
|
||||
``,
|
||||
`.`,
|
||||
` `,
|
||||
` `,
|
||||
`17`,
|
||||
`17.`,
|
||||
`.17`,
|
||||
|
@ -65,14 +67,14 @@ func TestValidateDomain(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, domain := range valid {
|
||||
if ret, err := ValidateDomain(domain); err != nil || ret == "" {
|
||||
t.Fatalf("ValidateDomain(`"+domain+"`) got %s %s", ret, err)
|
||||
if ret, err := ValidateDnsSearch(domain); err != nil || ret == "" {
|
||||
t.Fatalf("ValidateDnsSearch(`"+domain+"`) got %s %s", ret, err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, domain := range invalid {
|
||||
if ret, err := ValidateDomain(domain); err == nil || ret != "" {
|
||||
t.Fatalf("ValidateDomain(`"+domain+"`) got %s %s", ret, err)
|
||||
if ret, err := ValidateDnsSearch(domain); err == nil || ret != "" {
|
||||
t.Fatalf("ValidateDnsSearch(`"+domain+"`) got %s %s", ret, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue