Skip to content

Commit

Permalink
Add TTL config option with default to 300sec
Browse files Browse the repository at this point in the history
ref #4
  • Loading branch information
fnordfish committed Nov 29, 2018
1 parent 5dcf6ea commit 574276c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
## 2.2.0 (unreleased)

### New Feautres:

* Add global config for time-to-live via `VagrantDNS::Config.ttl`

### Fixes:

* Fixes acceptance tests for macOS High Sierra (10.13) to cope with `scutil`s new output format
* Adds the log-time missing `license` gem config

### Changes:
### Breaking Changes:

* Removes the global and vm config `ipv4only`. It was nver been used.

### Changes:

* 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.
* Internal changes on how the dns pattern config is read and written. (Now using `YAML::Store`)
* Acceptance tests run against vagrant v2.1.4
* Acceptance tests run against Ubuntu 18.04
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ We can use [multivm](https://www.vagrantup.com/docs/multi-machine/) configuratio
## Global Options

* `VagrantDNS::Config.listen`: an Array of Arrays describing interfaces to bind to. Defaults to `[[:udp, "127.0.0.1", 5300]]`.
* `VagrantDNS::Config.ttl`: The time-to-live in seconds for all resources. Defaults to `300` (5 minutes).
* `VagrantDNS::Config.auto_run`: (re)start and reconfigure the server every time a machine is started. On by default.
* `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:
- `false`: Disables the feature.
Expand Down
6 changes: 5 additions & 1 deletion lib/vagrant-dns/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
module VagrantDNS
class Config < Vagrant.plugin(2, :config)
class << self
attr_accessor :listen, :logger, :auto_run, :check_public_suffix
attr_accessor :listen, :ttl, :logger, :auto_run, :check_public_suffix

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

def ttl
@ttl ||= 300
end

def auto_run
return true if @auto_run.nil?
@auto_run
Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant-dns/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def run!(run_options)

registry = Registry.new(tmp_path).to_hash
std_resolver = RubyDNS::Resolver.new(Async::DNS::System.nameservers)
ttl = VagrantDNS::Config.ttl

RubyDNS::run_server(VagrantDNS::Config.listen) do
registry.each do |pattern, ip|
match(pattern, Resolv::DNS::Resource::IN::A) do |transaction, match_data|
transaction.respond!(ip)
transaction.respond!(ip, ttl: ttl)
end
end

Expand Down
1 change: 1 addition & 0 deletions testdrive/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", disabled: true

VagrantDNS::Config.listen = [[:udp, "0.0.0.0", 5300]]
VagrantDNS::Config.ttl = 30
end

0 comments on commit 574276c

Please sign in to comment.