vagrant-dns 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 683d8d24cadf716452cf7aa6fd6b0e57f79d4e5fb878b24e8c878bc332198256
4
- data.tar.gz: 11a2020530cf15c48ac66f877de68bbd4eb50f365b08d622c7f23cf6d72a7fdd
3
+ metadata.gz: b96bd995237133ab779883dc28ed8ac0ed8b2cb15b71c81c755bef68f93fc6bb
4
+ data.tar.gz: 9ddc6a521a68af235a6626672e6d7089e330bfcc0445b2126e01f8f45f4ebf32
5
5
  SHA512:
6
- metadata.gz: 96f4e9cdbde13a3b31aa6e39a578aac3dd7792a9e4943ffaf2a1622202add7c3af49ec4faad1cecf5b6093563928766c41f6036b77dc8fd243aca310f2407626
7
- data.tar.gz: 1641b1b9bc427d8705553d0bfe901c3c9f277ff8d34de370f8d9cd4aec92ed46d9714038e8cb58e3f981430d4f4cd5a761642422dc7c5979fdca7f6c0ee06ea6
6
+ metadata.gz: dee69e1a9fb66bdb817a310a2e2daf049bab4c032f907f7220825feffac480dbdeb4356c412c59dd7bd2369f40b030e8b21576e0c21d7bfd6dd6d3460fc69d74
7
+ data.tar.gz: d58f43351a8a12aa3f79e6bdb7c047f312b38714767a0c4d0e03c5e2e4a484c9bd11a57aec95d775f37e425ed6cda027af49b8c8cd66f38a84b5fb92bd8439bd
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.7.7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 2.4.0 (2023-04-11)
2
+
3
+ * DHCP support. [GH-51]
4
+ * Non-A-queries (like IPv6 AAAA- or TXT records) matching a configured pattern will be answered with a `NOTIMP` error. [GH-76]
5
+ * Upstream / passthrough DNS servers are now configurable, defaulting to the system config (existing behavior). [GH-76]
6
+ * Passthrough behavior is now configurable (`true`/`false`/`:unknown`). [GH-77]
7
+
1
8
  ## 2.3.0 (2023-01-14)
2
9
 
3
10
  * 🎉 Linux Support. Many thanks @mattiasb [GH-75]
@@ -23,7 +30,7 @@
23
30
 
24
31
  ## 2.2.0
25
32
 
26
- ### New Feautres:
33
+ ### New Features:
27
34
 
28
35
  * Add global config for time-to-live via `VagrantDNS::Config.ttl`
29
36
 
@@ -34,16 +41,16 @@
34
41
 
35
42
  ### Breaking Changes:
36
43
 
37
- * Removes the global and vm config `ipv4only`. It was nver been used.
44
+ * Removes the global and vm config `ipv4only`. It was never used.
38
45
 
39
46
  ### Changes:
40
47
 
41
- * Resources will now respond with a low TTL (time-to-live) of 5 minutes (300 seconds) instead of the old 24 hours by default. Use `VagrantDNS::Config.ttl = 86400` to reset to the old behaviour.
48
+ * Resources will now respond with a low TTL (time-to-live) of 5 minutes (300 seconds) instead of the old 24 hours by default. Use `VagrantDNS::Config.ttl = 86400` to reset to the old behavior.
42
49
  * Internal changes on how the dns pattern config is read and written. (Now using `YAML::Store`)
43
50
  * Acceptance tests run against vagrant v2.1.4
44
51
  * Acceptance tests run against Ubuntu 18.04
45
52
 
46
- ### New Feautres:
53
+ ### New Features:
47
54
 
48
55
  * Adds a check for the VMs configured TLDs to not be included in the [Public Suffix List](https://publicsuffix.org/)
49
56
 
@@ -84,7 +91,7 @@
84
91
  * Add support for boxes with `public_network` and static IP.
85
92
  * Breaking: No longer falls back to `127.0.0.1` when no IP could be found.
86
93
  * Log messages will now be tagged with the related box (vm) and `[vagrant-dns]`
87
- * Develepment targets Vagrant 1.9.3
94
+ * Development targets Vagrant 1.9.3
88
95
 
89
96
  ## 1.0.0
90
97
 
data/DEVELOPMENT.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  TODO: Expand this section :)
4
4
 
5
- The `Gemfile` uses two environment variables, `TEST_RUBY_VERSION` and `TEST_VAGRANT_VERSION` to control which version of ruby and vagrant are used during local development.
5
+ The `Gemfile` uses the `TEST_VAGRANT_VERSION` environment variable to control which version of vagrant is used during local development.
6
+ To adjust the ruby version used, change the contents of the `.ruby-version` file, even if you don't use a ruby version manager.
6
7
 
7
8
  ## Running Acceptance Tests
8
9
 
@@ -19,5 +20,20 @@ bundle exec rake -D acceptance
19
20
  bundle exec rake acceptance:setup:virtualbox
20
21
 
21
22
  # Run tests
22
- rake acceptance:virtualbox
23
+ bundle exec rake acceptance:virtualbox
24
+ ```
25
+
26
+ ### On other providers
27
+
28
+ 1. If it's not a default provider, add it to to `Gemfile` as a dependency and re-run `bundle install`.
29
+ 2. Add a box provider name to box URL mapping to the `TEST_BOXES` hash in `tasks/acceptance.rake`
30
+ 3. Run the `acceptance` rake task like above, replacing `virtualbox` with your provider.
31
+
32
+
33
+ ### VMware IPs
34
+
35
+ VMware uses IPs from its bridges for DHCP and static private networks. Check IP and net masks using:
36
+
37
+ ```console
38
+ ifconfig -X bridge | grep 'inet ' | grep -v '127.0.0.1' | awk '{ print $2 "\t" $4 }'
23
39
  ```
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
- ruby(ENV['TEST_RUBY_VERSION'] || '~> 2.7.3')
2
+ ruby(File.read(File.expand_path('.ruby-version', __dir__))[/\d+\.\d+\.\d+.*/])
3
3
 
4
4
  ENV['TEST_VAGRANT_VERSION'] ||= 'v2.3.4'
5
5
 
@@ -7,6 +7,9 @@ ENV['TEST_VAGRANT_VERSION'] ||= 'v2.3.4'
7
7
  # during acceptance tests.
8
8
  group :plugins do
9
9
  gemspec
10
+ # source "https://gems.hashicorp.com/" do
11
+ # gem "vagrant-vmware-desktop"
12
+ # end
10
13
  end
11
14
 
12
15
  group :test, :development do
data/README.md CHANGED
@@ -12,11 +12,11 @@ Alternatively, you can install an older version of vagrant-dns like this: `vagra
12
12
 
13
13
  ## Usage
14
14
 
15
- In addition to your networking config, configure a toplevel domain and a `hostname` for your machine. Optionally, configure a set of free matching patterns. Global configuration options can be given through the `VagrantDNS::Config` object:
15
+ In addition to your networking config, configure a top-level domain and a `hostname` for your machine. Optionally, configure a set of free matching patterns. Global configuration options can be given through the `VagrantDNS::Config` object:
16
16
 
17
17
  ```ruby
18
18
  Vagrant.configure("2") do |config|
19
- #...
19
+ # ...
20
20
 
21
21
  config.dns.tld = "test"
22
22
 
@@ -148,12 +148,20 @@ We can use [multivm](https://www.vagrantup.com/docs/multi-machine/) configuratio
148
148
  * Execute : `vagrant dns --install`
149
149
  * Test via: `ping worker2.mysite.box` or `worker1.mysite.box`
150
150
 
151
-
152
151
  ## VM options
153
152
 
154
153
  * `vm.dns.tld`: Set the tld for the given virtual machine. No default.
155
- * `vm.dns.tlds`: Set multiple tlds. Default: `[tld]`
154
+ * `vm.dns.tlds`: Set multiple TLDs. Default: `[tld]`
156
155
  * `vm.dns.patterns`: A list of domain patterns to match. Defaults to `[/^.*{host_name}.{tld}$/]`
156
+ * `vm.dns.ip`: Optional, overwrite of the default static IP detection. Valid values are:
157
+ - `Proc`: A Proc which return value will get used as IP. Eg: `proc { |vm, opts| }` (See DHCP section for full sample)
158
+ - `Symbol`: Forces the use of the named static network:
159
+ + `:private_network`: Use static ip of a configured private network (`config.vm.network "private_network", ip: "192.168.50.4"`)
160
+ + `:public_network`: Use static ip of a configured public network (`config.vm.network "public_network", ip: "192.168.0.17"`)
161
+ + `:dynamic`, `:dhcp`: Force reading the guest IP using vagrants build-in `read_ip_address` capability.
162
+ - Default:
163
+ If there is no network with a statically defined IP, and no `ip` override is given, use the build-in `read_ip_address` capability.
164
+ Else, check `:private_network`, if none found check `:public_network`
157
165
 
158
166
  ## Global Options
159
167
 
@@ -162,9 +170,16 @@ We can use [multivm](https://www.vagrantup.com/docs/multi-machine/) configuratio
162
170
  * `VagrantDNS::Config.auto_run`: (re)start and reconfigure the server every time a machine is started. On by default.
163
171
  * `VagrantDNS::Config.check_public_suffix`: Check if you are going to configure a [Public Suffix](https://publicsuffix.org/) (like a Top Level Domain) in a VMs `tld(s)` config, which could mess up your local dev machines DNS config. Possible configuration values are:
164
172
  - `false`: Disables the feature.
165
- - `"warn"`: Check and print a warning. (Still creates a resolver config and potentionally messes up your DNS) **At the moment, this is the default** because lots of projetcs used to use `"dev"` as a TLD, but this got registered by google and is now a public suffix.
173
+ - `"warn"`: Check and print a warning. (Still creates a resolver config and potentially messes up your DNS) **At the moment, this is the default** because lots of projects used to use `"dev"` as a TLD, but this got registered by google and is now a public suffix.
166
174
  - `"error"`: Check and prevent the box from starting. (Does not create the resolver config, it will also prevent the box from starting.)
167
-
175
+ * `VagrantDNS::Config.passthrough`: Configure how to deal with non-matching DNS queries. Will be set to `false` if no `passthrough_resolver` could be detected, or none is set.
176
+ - `true`: (default) Every non-matching query is passed through to the upstream DNS server (see `passthrough_resolver`)
177
+ - `false`: Disable passthrough. Every non-A-query to a matching pattern fails with `NotImp`. Every other query fails with `NXDomain`.
178
+ - `:unknown`: Only forward queries for which there's no matching pattern. Every non-A-query to a matching pattern fails with `NotImp`. Every other query will be passed through.
179
+ * `VagrantDNS::Config.passthrough_resolver`: By default, DNS queries not matching any patterns will be passed to an upstream DNS server.
180
+ - `:system`: (Default) pass through to the system configured default DNS server
181
+ - `[[:udp, "1.1.1.1", 53], [:tcp, "1.1.1.1", 53]]`: an Array of Arrays describing the DNS server(s) to use. (Protocol, IP, Port)
182
+
168
183
  ## Using custom domains from inside the VM (VirtualBox only)
169
184
 
170
185
  If you need to be able to resolve custom domains managed by this plugin from inside your virtual machine (and you're using VirtualBox), add the following
@@ -189,6 +204,32 @@ setting, however, the NAT engine will act as a DNS proxy
189
204
  (see [Virtualbox docs](https://www.virtualbox.org/manual/ch09.html#nat-adv-dns)). That way, queries for your custom domains
190
205
  from inside the guest will also be handled by the DNS server run by the plugin.
191
206
 
207
+ ## DHCP / Dynamic IP
208
+
209
+ When configuring your VM with a DHCP network, vagrant-dns tries to identify the guest IP using vagrants build-in `read_ip_address` capability.
210
+
211
+ For more fine-grained control use the `ip` config.
212
+ Here is an example using the VM's default way of communication and using the `hostname` command on it:
213
+
214
+ ```ruby
215
+ Vagrant.configure("2") do |config|
216
+ # ...
217
+
218
+ # - `vm` is the vagrant virtual machine instance and can be used to communicate with it
219
+ # - `opts` is the vagrant-dns options hash (everything configured via `config.dns.*`)
220
+ config.dns.ip = -> (vm, opts) do
221
+ # note: the block handed to `execute` might get called multiple times, hence this closure
222
+ ip = nil
223
+ vm.communicate.execute("hostname -I | cut -d ' ' -f 1") do |type, data|
224
+ ip = data.strip if type == :stdout
225
+ end
226
+ ip
227
+ end
228
+ end
229
+ ```
230
+
231
+ __NOTES__: In order to obtain the IP in this way, the vagrant box needs to be up and running. You will get a log output (`Postponing running user provided IP script until box has started.`) when you try to run `vagrant dns` on a non-running box.
232
+
192
233
  ## Issues
193
234
 
194
235
  * macOS and systemd-resolved enabled Linux only (please read: [Platform Support](https://github.com/BerlinVagrant/vagrant-dns/blob/master/PLATFORM_SUPPORT.md) before ranting about this).
@@ -1,9 +1,10 @@
1
- require 'logger'
1
+ require "logger"
2
2
 
3
3
  module VagrantDNS
4
4
  class Config < Vagrant.plugin(2, :config)
5
5
  class << self
6
- attr_accessor :listen, :ttl, :logger, :auto_run, :check_public_suffix
6
+ attr_writer :listen, :ttl, :passthrough, :passthrough_resolver
7
+ attr_accessor :logger, :auto_run, :check_public_suffix
7
8
 
8
9
  def listen
9
10
  @listen ||= [[:udp, "127.0.0.1", 5300]]
@@ -13,6 +14,15 @@ module VagrantDNS
13
14
  @ttl ||= 300
14
15
  end
15
16
 
17
+ def passthrough
18
+ return true if @passthrough.nil?
19
+ @passthrough
20
+ end
21
+
22
+ def passthrough_resolver
23
+ @passthrough_resolver ||= :system
24
+ end
25
+
16
26
  def auto_run
17
27
  return true if @auto_run.nil?
18
28
  @auto_run
@@ -37,7 +47,7 @@ module VagrantDNS
37
47
  failed_tlds = vm.config.dns.tlds.select { |tld| list.find(tld, default: false) }
38
48
 
39
49
  err = if failed_tlds.any?
40
- "tlds include a public suffix: #{failed_tlds.join(', ')}"
50
+ "tlds include a public suffix: #{failed_tlds.join(", ")}"
41
51
  end
42
52
 
43
53
  if err && check_public_suffix.to_s == "error"
@@ -50,7 +60,7 @@ module VagrantDNS
50
60
  end
51
61
  end
52
62
 
53
- attr_accessor :records
63
+ attr_accessor :records, :ip
54
64
  attr_reader :tlds, :patterns
55
65
 
56
66
  def pattern=(pattern)
@@ -68,11 +78,7 @@ module VagrantDNS
68
78
 
69
79
  # explicit hash, to get symbols in hash keys
70
80
  def to_hash
71
- {
72
- :patterns => patterns,
73
- :records => records,
74
- :tlds => tlds
75
- }
81
+ { patterns: patterns, records: records, tlds: tlds, ip: ip }
76
82
  end
77
83
 
78
84
  def validate(machine)
@@ -96,4 +102,3 @@ module VagrantDNS
96
102
  end
97
103
  end
98
104
  end
99
-
@@ -1,4 +1,4 @@
1
- require 'fileutils'
1
+ require "fileutils"
2
2
 
3
3
  module VagrantDNS
4
4
  class Configurator
@@ -20,124 +20,188 @@ module VagrantDNS
20
20
  unregister_patterns!
21
21
  end
22
22
 
23
- private
24
- def validate_tlds
25
- valid, err = VagrantDNS::Config.validate_tlds(vm)
26
- if !valid
27
- vm.ui.error(err)
28
- elsif err
29
- vm.ui.warn(err)
30
- end
31
- valid
23
+ private def validate_tlds
24
+ valid, err = VagrantDNS::Config.validate_tlds(vm)
25
+ if !valid
26
+ vm.ui.error(err)
27
+ elsif err
28
+ vm.ui.warn(err)
32
29
  end
30
+ valid
31
+ end
33
32
 
34
- def regenerate_resolvers!
35
- resolver_folder = self.resolver_folder
36
- _proto, ip, port = VagrantDNS::Config.listen.first
37
- tlds = register_tlds!
33
+ private def regenerate_resolvers!
34
+ resolver_folder = self.resolver_folder
35
+ _proto, ip, port = VagrantDNS::Config.listen.first
36
+ tlds = register_tlds!
38
37
 
39
- resolver_files(ip, port, tlds) do |filename, contents|
40
- File.write(File.join(resolver_folder, filename), contents)
41
- end
38
+ resolver_files(ip, port, tlds) do |filename, contents|
39
+ File.write(File.join(resolver_folder, filename), contents)
42
40
  end
41
+ end
43
42
 
44
- def register_tlds!
45
- add_tlds = dns_options(vm)[:tlds]
46
- VagrantDNS::TldRegistry.new(tmp_path).transaction do |store|
43
+ private def register_tlds!
44
+ add_tlds = dns_options(vm)[:tlds]
45
+ VagrantDNS::TldRegistry
46
+ .new(tmp_path)
47
+ .transaction do |store|
47
48
  store["tlds"] ||= []
48
49
  store["tlds"] |= add_tlds
49
50
  store["tlds"]
50
51
  end
52
+ end
53
+
54
+ private def register_patterns!
55
+ opts = dns_options(vm)
56
+
57
+ patterns = opts[:patterns] || default_patterns(opts)
58
+ if patterns.empty?
59
+ vm.ui.warn "[vagrant-dns] TLD but no host_name given. No patterns will be configured."
60
+ return
51
61
  end
52
62
 
53
- def register_patterns!
54
- opts = dns_options(vm)
63
+ ip = vm_ip(opts)
64
+ unless ip
65
+ vm.ui.detail "[vagrant-dns] No patterns will be configured."
66
+ return
67
+ end
55
68
 
56
- patterns = opts[:patterns] || default_patterns(opts)
57
- if patterns.empty?
58
- vm.ui.warn '[vagrant-dns] TLD but no host_name given. No patterns will be configured.'
59
- return
60
- end
69
+ registry = Registry.new(tmp_path)
70
+ registry.transaction do
71
+ patterns.each { |pattern| registry[pattern] = ip }
72
+ end
73
+ end
61
74
 
62
- network = opts[:networks].find do |nw|
63
- nw.first == :private_network && nw.last[:ip]
75
+ private def unregister_patterns!
76
+ opts = dns_options(vm)
77
+
78
+ patterns = opts[:patterns] || default_patterns(opts)
79
+ if patterns.empty?
80
+ vm.ui.warn "[vagrant-dns] TLD but no host_name given. No patterns will be removed."
81
+ return
82
+ end
83
+
84
+ registry = Registry.open(tmp_path)
85
+ return unless registry
86
+
87
+ registry.transaction do
88
+ unless registry.any?
89
+ vm.ui.warn "[vagrant-dns] Configuration missing or empty. No patterns will be removed."
90
+ registry.abort
64
91
  end
65
92
 
66
- unless network
67
- network = opts[:networks].find do |nw|
68
- nw.first == :public_network && nw.last[:ip]
93
+ patterns.each do |pattern|
94
+ if (ip = registry.delete(pattern))
95
+ vm.ui.info "[vagrant-dns] Removing pattern: #{pattern} for ip: #{ip}"
96
+ else
97
+ vm.ui.info "[vagrant-dns] Pattern: #{pattern} was not in config."
69
98
  end
70
99
  end
100
+ end
101
+ end
71
102
 
72
- unless network
73
- vm.ui.warn '[vagrant-dns] Could not find any static network IP. No patterns will be configured.'
74
- return
75
- end
103
+ private def dns_options(vm)
104
+ return @dns_options if @dns_options
76
105
 
77
- ip = network.last[:ip]
106
+ @dns_options = vm.config.dns.to_hash
107
+ @dns_options[:host_name] = vm.config.vm.hostname
108
+ @dns_options[:networks] = vm.config.vm.networks
109
+ @dns_options
110
+ end
78
111
 
79
- registry = Registry.new(tmp_path)
80
- registry.transaction do
81
- patterns.each do |pattern|
82
- registry[pattern] = ip
83
- end
84
- end
112
+ private def default_patterns(opts)
113
+ if opts[:host_name]
114
+ opts[:tlds].map { |tld| /^.*#{opts[:host_name]}.#{tld}$/ }
115
+ else
116
+ []
85
117
  end
118
+ end
86
119
 
87
- def unregister_patterns!
88
- opts = dns_options(vm)
120
+ private def vm_ip(opts)
121
+ user_ip = opts[:ip]
89
122
 
90
- patterns = opts[:patterns] || default_patterns(opts)
91
- if patterns.empty?
92
- vm.ui.warn '[vagrant-dns] TLD but no host_name given. No patterns will be removed.'
93
- return
94
- end
123
+ if !user_ip && dynamic_ip_network?(opts) || [:dynamic, :dhcp].include?(user_ip)
124
+ user_ip = DYNAMIC_VM_IP
125
+ end
95
126
 
96
- registry = Registry.open(tmp_path)
97
- return unless registry
127
+ ip =
128
+ case user_ip
129
+ when Proc
130
+ if vm.communicate.ready?
131
+ user_ip.call(vm, opts.dup.freeze)
132
+ else
133
+ vm.ui.info "[vagrant-dns] Postponing running user provided IP script until box has started."
134
+ return
135
+ end
136
+ when Symbol
137
+ _ip = static_vm_ip(user_ip, opts)
98
138
 
99
- registry.transaction do
100
- unless registry.any?
101
- vm.ui.warn '[vagrant-dns] Configuration missing or empty. No patterns will be removed.'
102
- registry.abort
139
+ unless _ip
140
+ vm.ui.warn "[vagrant-dns] Could not find any static network IP in network type `#{user_ip}'."
141
+ return
103
142
  end
104
143
 
105
- patterns.each do |pattern|
106
- if (ip = registry.delete(pattern))
107
- vm.ui.info "[vagrant-dns] Removing pattern: #{pattern} for ip: #{ip}"
108
- else
109
- vm.ui.info "[vagrant-dns] Pattern: #{pattern} was not in config."
110
- end
144
+ _ip
145
+ else
146
+ _ip = static_vm_ip(:private_network, opts)
147
+ _ip ||= static_vm_ip(:public_network, opts)
148
+
149
+ unless _ip
150
+ vm.ui.warn "[vagrant-dns] Could not find any static network IP."
151
+ return
111
152
  end
153
+
154
+ _ip
112
155
  end
156
+
157
+ # we where unable to find an IP, and there's no user-supplied callback
158
+ # falling back to dynamic/dhcp style detection
159
+ if !ip && !user_ip
160
+ vm.ui.info "[vagrant-dns] Falling back to dynamic IP detection."
161
+ ip = DYNAMIC_VM_IP.call(vm, opts.dup.freeze)
113
162
  end
114
163
 
115
- def dns_options(vm)
116
- @dns_options ||= vm.config.dns.to_hash.merge!(
117
- :host_name => vm.config.vm.hostname,
118
- :networks => vm.config.vm.networks
119
- )
164
+ if !ip || ip.empty?
165
+ vm.ui.warn "[vagrant-dns] Failed to identify IP."
166
+ return
120
167
  end
121
168
 
122
- def default_patterns(opts)
123
- if opts[:host_name]
124
- opts[:tlds].map { |tld| /^.*#{opts[:host_name]}.#{tld}$/ }
169
+ ip
170
+ end
171
+
172
+ private def dynamic_ip_network?(opts)
173
+ opts[:networks].none? { |(_nw_type, nw_config)| nw_config[:ip] }
174
+ end
175
+
176
+ # tries to find an IP in the configured +type+ networks
177
+ private def static_vm_ip(type, opts)
178
+ network = opts[:networks].find { |(nw_type, nw_config)| nw_config[:ip] && nw_type == type }
179
+
180
+ network.last[:ip] if network
181
+ end
182
+
183
+ DYNAMIC_VM_IP = proc { |vm|
184
+ vm.guest.capability(:read_ip_address).tap { |ip|
185
+ if ip
186
+ vm.ui.info "[vagrant-dns] Identified DHCP IP as '#{ip}'."
125
187
  else
126
- []
188
+ vm.ui.warn "[vagrant-dns] Could not identify DHCP IP."
127
189
  end
128
- end
190
+ }
191
+ }
192
+ private_constant :DYNAMIC_VM_IP
129
193
 
130
- def resolver_files(ip, port, tlds, &block)
131
- installer_class = VagrantDNS::Installers.resolve
132
- installer_class.resolver_files(ip, port, tlds, &block)
133
- end
194
+ private def resolver_files(ip, port, tlds, &block)
195
+ installer_class = VagrantDNS::Installers.resolve
196
+ installer_class.resolver_files(ip, port, tlds, &block)
197
+ end
134
198
 
135
- def resolver_folder
136
- File.join(tmp_path, "resolver").tap { |dir| FileUtils.mkdir_p(dir) }
137
- end
199
+ private def resolver_folder
200
+ File.join(tmp_path, "resolver").tap { |dir| FileUtils.mkdir_p(dir) }
201
+ end
138
202
 
139
- def ensure_deamon_env!
140
- FileUtils.mkdir_p(File.join(tmp_path, "daemon"))
141
- end
203
+ private def ensure_deamon_env!
204
+ FileUtils.mkdir_p(File.join(tmp_path, "daemon"))
205
+ end
142
206
  end
143
207
  end
@@ -0,0 +1,82 @@
1
+ require 'pp'
2
+ require 'rubydns'
3
+ require 'async/dns/system'
4
+
5
+ module VagrantDNS
6
+ class Server
7
+ attr_reader :registry, :listen, :ttl, :resolver, :passthrough
8
+
9
+ def initialize(registry, listen:, ttl:, resolver:, passthrough:)
10
+ @registry = registry.to_hash
11
+ @listen = listen
12
+ @ttl = ttl
13
+
14
+ @resolver = if resolver.nil? || resolver == :system
15
+ RubyDNS::Resolver.new(Async::DNS::System.nameservers)
16
+ elsif !resolver || resolver.empty?
17
+ nil
18
+ else
19
+ RubyDNS::Resolver.new(resolver)
20
+ end
21
+
22
+ if passthrough && !resolver
23
+ puts "[Warning] 'passthrough' config has no effect, sice no passthrough resolver is set."
24
+ end
25
+
26
+ @passthrough = !!@resolver && passthrough
27
+ end
28
+
29
+ def run
30
+ # need those clusures for the +RubyDNS::run_server+ block
31
+ passthrough = self.passthrough
32
+ registry = self.registry
33
+ resolver = self.resolver
34
+ ttl = self.ttl
35
+
36
+ _passthrough = if passthrough
37
+ proc do |transaction|
38
+ transaction.passthrough!(resolver) do |response|
39
+ puts "Passthrough response: #{response.inspect}"
40
+ end
41
+ end
42
+ end
43
+
44
+ RubyDNS::run_server(listen) do
45
+ # match all known patterns first
46
+ registry.each do |pattern, ip|
47
+ match(pattern, Resolv::DNS::Resource::IN::A) do |transaction, match_data|
48
+ transaction.respond!(ip, ttl: ttl)
49
+ end
50
+ end
51
+
52
+ case passthrough
53
+ when true
54
+ # forward everything
55
+ otherwise(&_passthrough)
56
+ when false
57
+ # fail known patterns for non-A queries as NotImp
58
+ registry.each do |pattern, ip|
59
+ match(pattern) do |transaction, match_data|
60
+ transaction.fail!(:NotImp)
61
+ end
62
+ end
63
+
64
+ # unknown pattern end up as NXDomain
65
+ otherwise do |transaction|
66
+ transaction.fail!(:NXDomain)
67
+ end
68
+ when :unknown
69
+ # fail known patterns for non-A queries as NotImp
70
+ registry.each do |pattern, ip|
71
+ match(pattern) do |transaction, match_data|
72
+ transaction.fail!(:NotImp)
73
+ end
74
+ end
75
+
76
+ # forward only unknown patterns
77
+ otherwise(&_passthrough)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -20,44 +20,27 @@ module VagrantDNS
20
20
  run!("status")
21
21
  end
22
22
 
23
- SERVER = Proc.new do |tmp_path, skip_require_dependencies|
24
- unless skip_require_dependencies
25
- require 'rubydns'
26
- require 'async/dns/system'
27
- end
28
-
29
- registry = Registry.new(tmp_path).to_hash
30
- std_resolver = RubyDNS::Resolver.new(Async::DNS::System.nameservers)
31
- ttl = VagrantDNS::Config.ttl
32
-
33
- RubyDNS::run_server(VagrantDNS::Config.listen) do
34
- registry.each do |pattern, ip|
35
- match(pattern, Resolv::DNS::Resource::IN::A) do |transaction, match_data|
36
- transaction.respond!(ip, ttl: ttl)
37
- end
38
- end
39
-
40
- otherwise do |transaction|
41
- transaction.passthrough!(std_resolver) do |reply, reply_name|
42
- puts reply
43
- puts reply_name
44
- end
45
- end
46
- end
47
- end
48
-
49
23
  def run!(cmd, opts = {})
50
24
  # On darwin, when the running Ruby is not compiled for the running OS
51
25
  # @see: https://github.com/BerlinVagrant/vagrant-dns/issues/72
52
26
  use_issue_72_workround = RUBY_PLATFORM.match?(/darwin/) && !RUBY_PLATFORM.end_with?(`uname -r`[0, 2])
53
27
 
54
28
  if cmd == "start" && use_issue_72_workround
55
- require 'rubydns'
56
- require 'async/dns/system'
29
+ require_relative "./server"
57
30
  end
58
31
 
59
32
  Daemons.run_proc("vagrant-dns", run_options(cmd, opts)) do
60
- SERVER.call(tmp_path, use_issue_72_workround)
33
+ unless use_issue_72_workround
34
+ require_relative "./server"
35
+ end
36
+
37
+ VagrantDNS::Server.new(
38
+ Registry.new(tmp_path),
39
+ listen: VagrantDNS::Config.listen,
40
+ ttl: VagrantDNS::Config.ttl,
41
+ passthrough: VagrantDNS::Config.passthrough,
42
+ resolver: VagrantDNS::Config.passthrough_resolver
43
+ ).run
61
44
  end
62
45
  end
63
46
 
@@ -92,9 +75,7 @@ module VagrantDNS
92
75
  end
93
76
  end
94
77
 
95
- private
96
-
97
- def run_options(cmd, extra = {})
78
+ private def run_options(cmd, extra = {})
98
79
  daemon_dir = File.join(tmp_path, "daemon")
99
80
  {
100
81
  ARGV: [cmd],
@@ -103,7 +84,7 @@ module VagrantDNS
103
84
  log_output: true,
104
85
  log_dir: daemon_dir,
105
86
  **extra
106
- }
87
+ }
107
88
  end
108
89
  end
109
90
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantDNS
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -11,7 +11,9 @@ namespace :acceptance do
11
11
  # Ubuntu 16.04 https://app.vagrantup.com/ubuntu/boxes/xenial64.json
12
12
  # :virtualbox => "https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20180511.0.0/providers/virtualbox.box"
13
13
  # Ubuntu 18.04 https://app.vagrantup.com/ubuntu/boxes/bionic64.json
14
- :virtualbox => "https://vagrantcloud.com/ubuntu/boxes/bionic64/versions/20180709.0.0/providers/virtualbox.box"
14
+ virtualbox: "https://vagrantcloud.com/ubuntu/boxes/bionic64/versions/20180709.0.0/providers/virtualbox.box",
15
+ # Ubuntu 22.10 https://app.vagrantup.com/bento/boxes/ubuntu-22.10
16
+ vmware_desktop: "https://app.vagrantup.com/bento/boxes/ubuntu-22.10/versions/202303.13.0/providers/vmware_desktop.box"
15
17
  }
16
18
 
17
19
  TEST_BOXES.each do |provider, box_url|
data/vagrant-dns.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["florian.gilcher@asquera.de", "robert@dotless.de"]
7
7
  gem.description = %q{vagrant-dns is a vagrant plugin that manages DNS records associated with local machines.}
8
8
  gem.summary = %q{vagrant-dns manages DNS records of vagrant machines}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/BerlinVagrant/vagrant-dns"
10
10
  gem.license = "MIT"
11
11
 
12
12
  gem.files = `git ls-files`.split($\).reject { |f| f.match(%r{^(test|testdrive)/}) }
@@ -16,6 +16,13 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = VagrantDNS::VERSION
18
18
 
19
+ gem.metadata = {
20
+ "bug_tracker_uri" => "https://github.com/BerlinVagrant/vagrant-dns/issues",
21
+ "changelog_uri" => "https://github.com/BerlinVagrant/vagrant-dns/blob/master/CHANGELOG.md",
22
+ "source_code_uri" => "https://github.com/BerlinVagrant/vagrant-dns",
23
+ "wiki_uri" => "https://github.com/BerlinVagrant/vagrant-dns/wiki"
24
+ }
25
+
19
26
  gem.required_ruby_version = '>= 2.2.6'
20
27
 
21
28
  gem.add_dependency "daemons"
@@ -25,7 +32,7 @@ Gem::Specification.new do |gem|
25
32
  # Pinning async gem to work around an issue in vagrant, where it does not
26
33
  # honor "required_ruby_version" while resolving sub-dependencies.
27
34
  # see: https://github.com/hashicorp/vagrant/issues/12640
28
- gem.add_dependency 'async', '< 2'
35
+ gem.add_dependency 'async', '~> 1.30', '>= 1.30.3'
29
36
 
30
37
  gem.add_development_dependency 'rspec'
31
38
  end
@@ -7,9 +7,7 @@ Vagrant::Spec::Acceptance.configure do |c|
7
7
  c.component_paths = [acceptance_dir.to_s]
8
8
  c.skeleton_paths = [(acceptance_dir + 'skeletons').to_s]
9
9
 
10
- c.provider ENV['VS_PROVIDER'],
11
- box: ENV['VS_BOX_PATH'],
12
- skeleton_path: c.skeleton_paths
10
+ c.provider ENV['VS_PROVIDER'], box: ENV['VS_BOX_PATH'], skeleton_path: c.skeleton_paths
13
11
 
14
12
  # there seems no other way to set additional environment variables
15
13
  # see: https://github.com/mitchellh/vagrant-spec/pull/17
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Gilcher
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-14 00:00:00.000000000 Z
12
+ date: 2023-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
@@ -57,16 +57,22 @@ dependencies:
57
57
  name: async
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "<"
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.30'
63
+ - - ">="
61
64
  - !ruby/object:Gem::Version
62
- version: '2'
65
+ version: 1.30.3
63
66
  type: :runtime
64
67
  prerelease: false
65
68
  version_requirements: !ruby/object:Gem::Requirement
66
69
  requirements:
67
- - - "<"
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.30'
73
+ - - ">="
68
74
  - !ruby/object:Gem::Version
69
- version: '2'
75
+ version: 1.30.3
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: rspec
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -92,6 +98,7 @@ extra_rdoc_files: []
92
98
  files:
93
99
  - ".editorconfig"
94
100
  - ".gitignore"
101
+ - ".ruby-version"
95
102
  - CHANGELOG.md
96
103
  - DEVELOPMENT.md
97
104
  - Gemfile
@@ -110,6 +117,7 @@ files:
110
117
  - lib/vagrant-dns/middlewares/config_up.rb
111
118
  - lib/vagrant-dns/middlewares/restart.rb
112
119
  - lib/vagrant-dns/registry.rb
120
+ - lib/vagrant-dns/server.rb
113
121
  - lib/vagrant-dns/service.rb
114
122
  - lib/vagrant-dns/store.rb
115
123
  - lib/vagrant-dns/tld_registry.rb
@@ -117,10 +125,14 @@ files:
117
125
  - tasks/acceptance.rake
118
126
  - vagrant-dns.gemspec
119
127
  - vagrant-spec.config.rb
120
- homepage: ''
128
+ homepage: https://github.com/BerlinVagrant/vagrant-dns
121
129
  licenses:
122
130
  - MIT
123
- metadata: {}
131
+ metadata:
132
+ bug_tracker_uri: https://github.com/BerlinVagrant/vagrant-dns/issues
133
+ changelog_uri: https://github.com/BerlinVagrant/vagrant-dns/blob/master/CHANGELOG.md
134
+ source_code_uri: https://github.com/BerlinVagrant/vagrant-dns
135
+ wiki_uri: https://github.com/BerlinVagrant/vagrant-dns/wiki
124
136
  post_install_message:
125
137
  rdoc_options: []
126
138
  require_paths: