Class: VagrantDNS::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-dns/config.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.auto_runObject

Returns the value of attribute auto_run.



7
8
9
# File 'lib/vagrant-dns/config.rb', line 7

def auto_run
  @auto_run
end

.check_public_suffixObject

Returns the value of attribute check_public_suffix.



7
8
9
# File 'lib/vagrant-dns/config.rb', line 7

def check_public_suffix
  @check_public_suffix
end

.listenObject



9
10
11
# File 'lib/vagrant-dns/config.rb', line 9

def listen
  @listen ||= [[:udp, "127.0.0.1", 5300]]
end

.loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/vagrant-dns/config.rb', line 7

def logger
  @logger
end

.passthroughObject



17
18
19
20
# File 'lib/vagrant-dns/config.rb', line 17

def passthrough
  return true if @passthrough.nil?
  @passthrough
end

.passthrough_resolverObject



22
23
24
# File 'lib/vagrant-dns/config.rb', line 22

def passthrough_resolver
  @passthrough_resolver ||= :system
end

.ttlObject



13
14
15
# File 'lib/vagrant-dns/config.rb', line 13

def ttl
  @ttl ||= 300
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



63
64
65
# File 'lib/vagrant-dns/config.rb', line 63

def ip
  @ip
end

#patternsObject (readonly)

Returns the value of attribute patterns.



64
65
66
# File 'lib/vagrant-dns/config.rb', line 64

def patterns
  @patterns
end

#recordsObject

Returns the value of attribute records.



63
64
65
# File 'lib/vagrant-dns/config.rb', line 63

def records
  @records
end

#tldsObject (readonly)

Returns the value of attribute tlds.



64
65
66
# File 'lib/vagrant-dns/config.rb', line 64

def tlds
  @tlds
end

Class Method Details

.validate_tlds(vm) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vagrant-dns/config.rb', line 36

def validate_tlds(vm)
  return [true, nil] unless check_public_suffix

  require "public_suffix"

  # Don't include private domains in the list, we are only interested in TLDs and such
  list = PublicSuffix::List.parse(
    File.read(PublicSuffix::List::DEFAULT_LIST_PATH),
    private_domains: false
  )

  failed_tlds = vm.config.dns.tlds.select { |tld| list.find(tld, default: false) }

  err = if failed_tlds.any?
    "tlds include a public suffix: #{failed_tlds.join(", ")}"
  end

  if err && check_public_suffix.to_s == "error"
    [false, err]
  elsif err
    [true, err]
  else
    [true, nil]
  end
end

Instance Method Details

#pattern=(pattern) ⇒ Object Also known as: patterns=



66
67
68
# File 'lib/vagrant-dns/config.rb', line 66

def pattern=(pattern)
  @patterns = (pattern ? Array(pattern) : pattern)
end

#tld=(tld) ⇒ Object



71
72
73
# File 'lib/vagrant-dns/config.rb', line 71

def tld=(tld)
  @tlds = Array(tld)
end

#to_hashObject

explicit hash, to get symbols in hash keys



80
81
82
# File 'lib/vagrant-dns/config.rb', line 80

def to_hash
  { patterns: patterns, records: records, tlds: tlds, ip: ip }
end

#validate(machine) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/vagrant-dns/config.rb', line 84

def validate(machine)
  errors = _detected_errors

  errors = validate_check_public_suffix(errors, machine)

  { "vagrant_dns" => errors }
end

#validate_check_public_suffix(errors, machine) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/vagrant-dns/config.rb', line 92

def validate_check_public_suffix(errors, machine)
  valid, err = self.class.validate_tlds(machine)

  if !valid
    errors << err
  elsif err
    machine.ui.warn(err)
  end

  errors
end