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.



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

def auto_run
  @auto_run
end

.check_public_suffixObject

Returns the value of attribute check_public_suffix.



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

def check_public_suffix
  @check_public_suffix
end

.listenObject

Returns the value of attribute listen.



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

def listen
  @listen
end

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

.ttlObject

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



54
55
56
# File 'lib/vagrant-dns/config.rb', line 54

def patterns
  @patterns
end

#recordsObject

Returns the value of attribute records.



53
54
55
# File 'lib/vagrant-dns/config.rb', line 53

def records
  @records
end

#tldsObject (readonly)

Returns the value of attribute tlds.



54
55
56
# File 'lib/vagrant-dns/config.rb', line 54

def tlds
  @tlds
end

Class Method Details

.validate_tlds(vm) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vagrant-dns/config.rb', line 26

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=



56
57
58
# File 'lib/vagrant-dns/config.rb', line 56

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

#tld=(tld) ⇒ Object



61
62
63
# File 'lib/vagrant-dns/config.rb', line 61

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

#to_hashObject

explicit hash, to get symbols in hash keys



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

def to_hash
  {
    :patterns => patterns,
    :records => records,
    :tlds => tlds
  }
end

#validate(machine) ⇒ Object



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

def validate(machine)
  errors = _detected_errors

  errors = validate_check_public_suffix(errors, machine)

  { "vagrant_dns" => errors }
end

#validate_check_public_suffix(errors, machine) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vagrant-dns/config.rb', line 86

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