forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns_validator.go
41 lines (32 loc) · 852 Bytes
/
dns_validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package net
import (
"strings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type DNSValidator interface {
Validate([]string) error
}
type dnsValidator struct {
fs boshsys.FileSystem
}
func NewDNSValidator(fs boshsys.FileSystem) DNSValidator {
return &dnsValidator{
fs: fs,
}
}
func (d *dnsValidator) Validate(dnsServers []string) error {
if len(dnsServers) == 0 {
return nil
}
resolvConfContents, err := d.fs.ReadFileString("/etc/resolv.conf")
if err != nil {
return bosherr.WrapError(err, "Reading /etc/resolv.conf")
}
for _, dnsServer := range dnsServers {
if strings.Contains(resolvConfContents, dnsServer) {
return nil
}
}
return bosherr.WrapError(err, "None of the DNS servers that were specified in the manifest were found in /etc/resolv.conf.")
}