vagrant-dns 2.2.3 → 2.3.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: 79dfdc20901e6817d9acb8d2833a1be00655cd974b2d9d6afbffc5ddea2d3ff2
4
- data.tar.gz: 6c4fa0e10842aee72a453b368bb535a0d450f64b2c0eb88e1479d1a4d83f2984
3
+ metadata.gz: 683d8d24cadf716452cf7aa6fd6b0e57f79d4e5fb878b24e8c878bc332198256
4
+ data.tar.gz: 11a2020530cf15c48ac66f877de68bbd4eb50f365b08d622c7f23cf6d72a7fdd
5
5
  SHA512:
6
- metadata.gz: 7b55bfad4178e4dfb15fff551de3fde4ab324520ce4d4e1e2cab3acc13b67b3e9d194be2af2e0281922b9f03061540472decda0f5ca94173f1600add4fbdd9ae
7
- data.tar.gz: 0cbd95cb993d9cc857838629ad7eaeb6c5708c53b337b246c685468783a3e0864bc7f1ff6e9b8afe675add2b173ef09e4e9def27d038915e503be59440d794b4
6
+ metadata.gz: 96f4e9cdbde13a3b31aa6e39a578aac3dd7792a9e4943ffaf2a1622202add7c3af49ec4faad1cecf5b6093563928766c41f6036b77dc8fd243aca310f2407626
7
+ data.tar.gz: 1641b1b9bc427d8705553d0bfe901c3c9f277ff8d34de370f8d9cd4aec92ed46d9714038e8cb58e3f981430d4f4cd5a761642422dc7c5979fdca7f6c0ee06ea6
data/.editorconfig ADDED
@@ -0,0 +1,16 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ charset = utf-8
6
+
7
+ [{*.rb,Gemfile,Vagrantfile}]
8
+ indent_style = space
9
+ indent_size = 2
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = false
15
+ indent_style = space
16
+ indent_size = 2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.3.0 (2023-01-14)
2
+
3
+ * 🎉 Linux Support. Many thanks @mattiasb [GH-75]
4
+ * Managed TLDs are now stored in separate config file, which can be inspected via `vagrant dns --list-ltds`.
5
+
1
6
  ## 2.2.3
2
7
 
3
8
  ### Fixes:
data/PLATFORM_SUPPORT.md CHANGED
@@ -1,13 +1,15 @@
1
1
  Platform Support
2
2
  ================
3
3
 
4
- Vagrant-DNS only supports OS X at the moment. This has 2 main reasons:
4
+ Vagrant-DNS was originally developed for macOS (or Mac OS X back in the time). This had 2 main reasons:
5
5
 
6
- 1) All main developers are on OS X and have no good idea how to properly implement such a system for other OSes. Also, OS X makes it incredibly easy to do what vagrant-dns does.
6
+ 1) All main developers are on macOS and have no good idea how to properly implement such a system for other OSes. Also, macOS makes it incredibly easy to do what vagrant-dns does.
7
7
 
8
8
  2) We spoke to multiple Linux and Windows-Developers and found that a half-baked implementation of people not invested at the respective platform as a _convenient development_ platform is only harmful and might at worst mess with users systems in unintended ways. None of them have supplied us with a proper way to implement this.
9
9
 
10
- That said, we will happily accept any patches and want to encourage platform support beyond OS X, including ensuring further development of those solutions. Some of the groundwork for this has been layed. It might not be 100% finished, but we happily apply any changes necessary.
10
+ Vagrant-DNS just recently gained support for Linux, more specificity systemd with resolved.
11
+
12
+ That said, we will happily accept any patches and want to encourage platform support beyond macOS, including ensuring further development of those solutions. Some of the groundwork for this has been layed. It might not be 100% finished, but we happily apply any changes necessary.
11
13
 
12
14
  This document aims to be a guide to implementing support for other platforms.
13
15
 
@@ -23,10 +25,10 @@ Design Goals
23
25
 
24
26
  Vagrant-DNS should not require superuser access for anything except reconfiguring the hosts DNS system. This is why there is a seperate "install" step that registers the Vagrant-DNS server to your system (for the configured TLDs). (Re)starts of the server (happening at startup of the machine) need to happen without superuser access.
25
27
 
26
- Mac OS X
27
- ========
28
+ macOS
29
+ =====
28
30
 
29
- As a reference, here is how this works on OS X:
31
+ As a reference, here is how this works on macOS:
30
32
 
31
33
  * `install` places a symlink in `/etc/resolver/{tld}` that links to a corresponding file in `.vagrant.d` with content similar to this one:
32
34
 
@@ -40,10 +42,19 @@ From then on, OS X will resolve all requests to that top level domain using the
40
42
  Linux
41
43
  =====
42
44
 
43
- To help anyone that attempts a Linux implementation, here is what has already been tried.
45
+ With `systemd-resolved`, we finally got a mechanism that resembles the macOS approach, with some subtile differences.
46
+
47
+ * `install` creates a single file `vagrant-dns.conf`, even when multiple top level domains are configured:
48
+
49
+ ```
50
+ [Resolve]
51
+ DNS=127.0.0.1:5300
52
+ Domains=~test ~othertld
53
+ ```
54
+
55
+ This file is then copied into `/etc/systemd/resolved.conf.d/`. The macOS strategy of adding symlinks from config files to a file within `/home/<user>/` doesn't work since the user that runs systemd-resolved doesn't have permission to read there.
44
56
 
45
- * Editing resolv.conf: Linux resolv.conf (in contrast to, say OpenBSD) does not allow you to set a port number for the DNS server. Also, its size is limited to 3 servers and the file is often under OS control, so messing around with it might not be advisable.
46
- * Setting up dnsmasq: this is certainly an option, but we couldn't find out how invasive this was, which Linux flavors might already come with dnsmasq configurations and how not to shoot other people in the foot with it. User help is needed.
57
+ This makes zombie configurations likely. For example when `vagrant-dns` is not correctly uninstalled using its `uninstall` command, its `resolved` configuration will point to a non-existing server, potentially causing troubles.
47
58
 
48
59
  (Open)BSD
49
60
  =========
data/README.md CHANGED
@@ -37,7 +37,9 @@ Then, register the DNS server as a resolver:
37
37
  $ vagrant dns --install
38
38
  ```
39
39
 
40
- On OS X, this will create a file `/etc/resolver/test`, which tells OS X to resolve the TLD `.test` by using the nameserver given in this file. You will have to rerun --install every time a tld is added.
40
+ This command will write out a configuration file that tells the operating system to resolve the `.test` TLD via the `vagrant-dns` DNS server. On OS X, this config file is located at `/etc/resolver/test` while on Linux it's at `/etc/systemd/resolved.conf.d/vagrant-dns.conf`.
41
+
42
+ You will have to rerun --install every time a tld is added.
41
43
 
42
44
  You can delete this file by running:
43
45
 
@@ -45,7 +47,7 @@ You can delete this file by running:
45
47
  $ vagrant dns --uninstall
46
48
  ```
47
49
 
48
- To also delete the created config file for this TLD (`~/.vagrant.d/tmp/dns/resolver/test` in our example) run:
50
+ To also delete the created config file for this TLD (`~/.vagrant.d/tmp/dns/resolver/test` or `~/.vagrant.d/tmp/dns/resolver/vagrant-dns.conf` in our example) run:
49
51
 
50
52
 
51
53
  ```bash
@@ -60,26 +62,45 @@ $ vagrant dns --start
60
62
 
61
63
  And test it:
62
64
 
65
+ **OS X:**
66
+
63
67
  ```bash
64
68
  $ scutil --dns
65
- ...
69
+ [ … ]
66
70
  resolver #8
67
71
  domain : test
68
72
  nameserver[0] : 127.0.0.1
69
73
  port : 5300
70
- ...
74
+ [ … ]
75
+
71
76
  $ dscacheutil -q host -a name test.machine.test
72
77
  name: test.machine.test
73
78
  ip_address: 33.33.33.10
74
79
  ```
75
80
 
76
- You can now reach the server under the given domain.
81
+ **Linux**:
82
+
83
+ ```bash
84
+ $ resolvectl status
85
+ Global
86
+ Protocols: LLMNR=resolve -mDNS -DNSOverTLS DNSSEC=no/unsupported
87
+ resolv.conf mode: stub
88
+ DNS Domain: ~test
89
+ [ … ]
90
+
91
+ $ resolvectl query test.machine.test
92
+ test.machine.test: 33.33.33.10
93
+
94
+ -- Information acquired via protocol DNS in 10.1420s.
95
+ -- Data is authenticated: no; Data was acquired via local or encrypted transport: no
96
+ ```
77
97
 
78
98
  **Note:** Mac OS X is quite different from Linux regarding DNS resolution. As a result, do not use
79
99
  `dig` or `nslookup`, but `dscacheutil` instead. Read [this article](http://apple.stackexchange.com/a/70583)
80
100
  for more information.
81
101
 
82
- Finally, stop the server using:
102
+
103
+ You can now reach the server under the given domain.
83
104
 
84
105
  ```bash
85
106
  $ vagrant dns --stop
@@ -146,7 +167,7 @@ We can use [multivm](https://www.vagrantup.com/docs/multi-machine/) configuratio
146
167
 
147
168
  ## Using custom domains from inside the VM (VirtualBox only)
148
169
 
149
- If you need to be able to resolve custom domains managed by this plugin from inside your virtual machine, add the following
170
+ 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
150
171
  setting to your `Vagrantfile`:
151
172
 
152
173
  ```ruby
@@ -170,8 +191,7 @@ from inside the guest will also be handled by the DNS server run by the plugin.
170
191
 
171
192
  ## Issues
172
193
 
194
+ * 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).
173
195
  * `A` records only
174
196
  * No IPv6 support
175
- * OS X only (please read: [Platform
176
- Support](https://github.com/BerlinVagrant/vagrant-dns/blob/master/PLATFORM_SUPPORT.md) before ranting about this).
177
197
  * Not automatically visible inside the box (special configuration of your guest system or provider needed)
@@ -59,6 +59,11 @@ module VagrantDNS
59
59
  options[:build_config] = false
60
60
  end
61
61
 
62
+ opts.on("--list-tlds", "-L", "Show the current TopLevelDomains registered. This works in conjunction with --start --stop --restart --status.") do
63
+ options[:show_tld_config] = true
64
+ options[:build_config] = false
65
+ end
66
+
62
67
  opts.on("--with-sudo", "In conjunction with `--install`, `--uninstall`, `--purge`: Run using `sudo` instead of `osascript`. Useful for automated scripts running as sudoer.") do
63
68
  options[:installer_opts] = { exec_style: :sudo }
64
69
  end
@@ -76,25 +81,23 @@ module VagrantDNS
76
81
  build_config(vms, options) if options[:build_config]
77
82
  manage_service(vms, options)
78
83
  manage_installation(vms, options) if options[:manage_installation]
79
- show_config(vms, options) if options[:show_config]
84
+ show_config(vms, options) if options[:show_config] || options[:show_tld_config]
80
85
  end
81
86
 
82
87
  protected
83
88
 
84
89
  def manage_installation(vms, options)
85
- if Vagrant::Util::Platform.darwin?
86
- installer_options = options.fetch(:installer_opts, {})
87
- installer = VagrantDNS::Installers::Mac.new(tmp_path, installer_options)
88
-
89
- if options[:install]
90
- installer.install!
91
- elsif options[:uninstall]
92
- installer.uninstall!
93
- elsif options[:purge]
94
- installer.purge!
95
- end
96
- else
97
- raise 'installing and uninstalling is only supported on Mac OS X at the moment.'
90
+ installer_class = VagrantDNS::Installers.resolve
91
+
92
+ installer_options = options.fetch(:installer_opts, {})
93
+ installer = installer_class.new(tmp_path, installer_options)
94
+
95
+ if options[:install]
96
+ installer.install!
97
+ elsif options[:uninstall]
98
+ installer.uninstall!
99
+ elsif options[:purge]
100
+ installer.purge!
98
101
  end
99
102
  end
100
103
 
@@ -114,7 +117,8 @@ module VagrantDNS
114
117
 
115
118
  def show_config(vms, options)
116
119
  service = VagrantDNS::Service.new(tmp_path)
117
- service.show_config
120
+ service.show_tld_config if options[:show_tld_config]
121
+ service.show_config if options[:show_config]
118
122
  end
119
123
 
120
124
  def build_config(vms, options)
@@ -32,20 +32,26 @@ module VagrantDNS
32
32
  end
33
33
 
34
34
  def regenerate_resolvers!
35
- FileUtils.mkdir_p(resolver_folder)
35
+ resolver_folder = self.resolver_folder
36
+ _proto, ip, port = VagrantDNS::Config.listen.first
37
+ tlds = register_tlds!
36
38
 
37
- port = VagrantDNS::Config.listen.first.last
38
- tlds = dns_options(vm)[:tlds]
39
+ resolver_files(ip, port, tlds) do |filename, contents|
40
+ File.write(File.join(resolver_folder, filename), contents)
41
+ end
42
+ end
39
43
 
40
- tlds.each do |tld|
41
- File.open(File.join(resolver_folder, tld), "w") do |f|
42
- f << resolver_file(port)
43
- end
44
+ def register_tlds!
45
+ add_tlds = dns_options(vm)[:tlds]
46
+ VagrantDNS::TldRegistry.new(tmp_path).transaction do |store|
47
+ store["tlds"] ||= []
48
+ store["tlds"] |= add_tlds
49
+ store["tlds"]
44
50
  end
45
51
  end
46
52
 
47
53
  def register_patterns!
48
- opts = dns_options(vm)
54
+ opts = dns_options(vm)
49
55
 
50
56
  patterns = opts[:patterns] || default_patterns(opts)
51
57
  if patterns.empty?
@@ -79,7 +85,7 @@ module VagrantDNS
79
85
  end
80
86
 
81
87
  def unregister_patterns!
82
- opts = dns_options(vm)
88
+ opts = dns_options(vm)
83
89
 
84
90
  patterns = opts[:patterns] || default_patterns(opts)
85
91
  if patterns.empty?
@@ -87,7 +93,9 @@ module VagrantDNS
87
93
  return
88
94
  end
89
95
 
90
- registry = Registry.new(tmp_path)
96
+ registry = Registry.open(tmp_path)
97
+ return unless registry
98
+
91
99
  registry.transaction do
92
100
  unless registry.any?
93
101
  vm.ui.warn '[vagrant-dns] Configuration missing or empty. No patterns will be removed.'
@@ -105,10 +113,10 @@ module VagrantDNS
105
113
  end
106
114
 
107
115
  def dns_options(vm)
108
- dns_options = vm.config.dns.to_hash
109
- dns_options[:host_name] = vm.config.vm.hostname
110
- dns_options[:networks] = vm.config.vm.networks
111
- dns_options
116
+ @dns_options ||= vm.config.dns.to_hash.merge!(
117
+ :host_name => vm.config.vm.hostname,
118
+ :networks => vm.config.vm.networks
119
+ )
112
120
  end
113
121
 
114
122
  def default_patterns(opts)
@@ -119,14 +127,13 @@ module VagrantDNS
119
127
  end
120
128
  end
121
129
 
122
- def resolver_file(port)
123
- "# this file is generated by vagrant-dns\n" \
124
- "nameserver 127.0.0.1\n" \
125
- "port #{port}\n"
130
+ def resolver_files(ip, port, tlds, &block)
131
+ installer_class = VagrantDNS::Installers.resolve
132
+ installer_class.resolver_files(ip, port, tlds, &block)
126
133
  end
127
134
 
128
135
  def resolver_folder
129
- File.join(tmp_path, "resolver")
136
+ File.join(tmp_path, "resolver").tap { |dir| FileUtils.mkdir_p(dir) }
130
137
  end
131
138
 
132
139
  def ensure_deamon_env!
@@ -0,0 +1,73 @@
1
+ module VagrantDNS
2
+ module Installers
3
+ class Linux
4
+ EXEC_STYLES = %i{sudo}
5
+ RESOLVED_CONFIG = "vagrant-dns.conf"
6
+
7
+ attr_accessor :tmp_path, :install_path, :exec_style
8
+
9
+ def initialize(tmp_path, options = {})
10
+ self.tmp_path = tmp_path
11
+ self.install_path = options.fetch(:install_path, "/etc/systemd/resolved.conf.d")
12
+ self.exec_style = options.fetch(:exec_style, :sudo)
13
+ end
14
+
15
+ # Generate the resolved config.
16
+ #
17
+ # @yield [filename, content]
18
+ # @yieldparam filename [String] The filename to use for the resolved config file (relative to +install_path+)
19
+ # @yieldparam content [String] The content for +filename+
20
+ def self.resolver_files(ip, port, tlds)
21
+ contents =
22
+ "# This file is generated by vagrant-dns\n" \
23
+ "[Resolve]\n" \
24
+ "DNS=#{ip}:#{port}\n" \
25
+ "Domains=~#{tlds.join(' ~')}\n"
26
+
27
+ yield "vagrant-dns.conf", contents
28
+ end
29
+
30
+ def install!
31
+ require 'fileutils'
32
+
33
+ src = File.join(tmp_path, "resolver", RESOLVED_CONFIG)
34
+ dest = File.join(install_path, RESOLVED_CONFIG)
35
+
36
+ commands = [
37
+ ['install', '-D', '-m', '0644', '-T', src.shellescape, dest.shellescape],
38
+ ['systemctl', 'reload-or-restart', 'systemd-resolved.service']
39
+ ]
40
+
41
+ exec(*commands)
42
+ end
43
+
44
+ def uninstall!
45
+ commands = [
46
+ ['rm', File.join(install_path, RESOLVED_CONFIG)],
47
+ ['systemctl', 'reload-or-restart', 'systemd-resolved.service']
48
+ ]
49
+
50
+ exec(*commands)
51
+ end
52
+
53
+ def purge!
54
+ require 'fileutils'
55
+ uninstall!
56
+ FileUtils.rm_r(tmp_path)
57
+ end
58
+
59
+ def exec(*commands)
60
+ return if !commands || commands.empty?
61
+
62
+ case exec_style
63
+ when :sudo
64
+ commands.each do |c|
65
+ system 'sudo', *c
66
+ end
67
+ else
68
+ raise ArgumentError, "Unsupported execution style: #{exec_style}. Use one of #{EXEC_STYLES.map(&:inspect).join(' ')}"
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -11,6 +11,22 @@ module VagrantDNS
11
11
  self.exec_style = options.fetch(:exec_style, :osa)
12
12
  end
13
13
 
14
+ # Generate the resolved config.
15
+ #
16
+ # @yield [filename, content]
17
+ # @yieldparam filename [String] The filename to use for the resolved config file (relative to +install_path+)
18
+ # @yieldparam content [String] The content for +filename+
19
+ def self.resolver_files(ip, port, tlds)
20
+ tlds.each do |tld|
21
+ contents =
22
+ "# This file is generated by vagrant-dns\n" \
23
+ "nameserver #{ip}\n" \
24
+ "port #{port}"
25
+
26
+ yield tld, contents
27
+ end
28
+ end
29
+
14
30
  def install!
15
31
  require 'fileutils'
16
32
 
@@ -26,8 +42,6 @@ module VagrantDNS
26
42
  end
27
43
 
28
44
  def uninstall!
29
- require 'fileutils'
30
-
31
45
  commands = registered_resolvers.map do |r|
32
46
  installed_resolver = File.join(install_path, File.basename(r))
33
47
  ['rm', '-rf', installed_resolver]
@@ -0,0 +1,16 @@
1
+ module VagrantDNS
2
+ module Installers
3
+ def self.resolve
4
+ if Vagrant::Util::Platform.darwin?
5
+ VagrantDNS::Installers::Mac
6
+ elsif Vagrant::Util::Platform.linux?
7
+ VagrantDNS::Installers::Linux
8
+ else
9
+ raise 'installing and uninstalling is only supported on Linux and macOS at the moment.'
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ require "vagrant-dns/installers/mac"
16
+ require "vagrant-dns/installers/linux"
@@ -1,60 +1,19 @@
1
- require 'yaml/store'
2
- require 'forwardable'
3
-
4
1
  module VagrantDNS
5
2
  # This is the dns pattern registry (aka "config")
6
3
  # It basically delegates everything to a YAML::Store but handles the conversion
7
4
  # of Regexp dns-patterns into YAML string keys and reverse.
8
5
  class Registry
9
- extend Forwardable
10
-
11
- def initialize(tmp_path)
12
- @store = YAML::Store.new(File.join(tmp_path, "config"), true)
13
- end
6
+ include VagrantDNS::Store
14
7
 
15
- def_delegators :@store, :transaction, :abort, :commit
16
-
17
- # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
18
- def [](name)
19
- name = name.source if name.respond_to? :source
20
- @store[name]
21
- end
22
-
23
- # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
24
- def []=(name, value)
25
- name = name.source if name.respond_to? :source
26
- @store[name] = value
27
- end
8
+ NAME = "config"
28
9
 
29
- def delete(name)
30
- name = name.source if name.respond_to? :source
31
- @store.delete(name)
32
- end
33
-
34
- # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
35
- def root?(name)
36
- name = name.source if name.respond_to? :source
37
- @store.root?(name)
38
- end
39
- alias_method :key?, :root?
40
-
41
- # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
42
- def roots
43
- @store.roots.map { |name| Regexp.new(name) }
44
- end
45
- alias_method :keys, :roots
46
-
47
- # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
48
- def any?
49
- @store.roots.any?
10
+ def initialize(tmp_path)
11
+ @store = YAML::Store.new(File.join(tmp_path, NAME), true)
50
12
  end
51
13
 
52
- def to_hash
53
- @store.transaction(true) do
54
- @store.roots.each_with_object({}) do |name, a|
55
- a[Regexp.new(name)] = @store[name]
56
- end
57
- end
14
+ # @return [VagrantDNS::Registry,nil] Eitehr an instance or +nil+ if cofig file does not exist.
15
+ def self.open(tmp_path)
16
+ new(tmp_path) if File.exist?(File.join(tmp_path, NAME))
58
17
  end
59
18
  end
60
19
  end
@@ -67,14 +67,28 @@ module VagrantDNS
67
67
  end
68
68
 
69
69
  def show_config
70
- registry = Registry.new(tmp_path).to_hash
70
+ registry = Registry.open(tmp_path)
71
+ return unless registry
71
72
 
72
- if registry.any?
73
- registry.each do |pattern, ip|
73
+ config = registry.to_hash
74
+ if config.any?
75
+ config.each do |pattern, ip|
74
76
  puts format("%s => %s", pattern.inspect, ip)
75
77
  end
76
78
  else
77
- puts "Configuration missing or empty."
79
+ puts "Pattern configuration missing or empty."
80
+ end
81
+ end
82
+
83
+ def show_tld_config
84
+ tld_registry = VagrantDNS::TldRegistry.open(tmp_path)
85
+ return unless tld_registry
86
+
87
+ tlds = tld_registry.transaction { |store| store.fetch("tlds", []) }
88
+ if !tlds || tlds.empty?
89
+ puts "No TLDs configured."
90
+ else
91
+ puts tlds
78
92
  end
79
93
  end
80
94
 
@@ -0,0 +1,59 @@
1
+ require 'yaml/store'
2
+ require 'forwardable'
3
+
4
+ module VagrantDNS
5
+ module Store
6
+ module InstanceMethods
7
+ # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
8
+ def [](name)
9
+ name = name.source if name.respond_to? :source
10
+ @store[name]
11
+ end
12
+
13
+ # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
14
+ def []=(name, value)
15
+ name = name.source if name.respond_to? :source
16
+ @store[name] = value
17
+ end
18
+
19
+ def delete(name)
20
+ name = name.source if name.respond_to? :source
21
+ @store.delete(name)
22
+ end
23
+
24
+ # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
25
+ def root?(name)
26
+ name = name.source if name.respond_to? :source
27
+ @store.root?(name)
28
+ end
29
+ alias_method :key?, :root?
30
+
31
+ # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
32
+ def roots
33
+ @store.roots.map { |name| Regexp.new(name) }
34
+ end
35
+ alias_method :keys, :roots
36
+
37
+ # This method is only valid in a #transaction and it cannot be read-only. It will raise PStore::Error if called at any other time.
38
+ def any?
39
+ @store.roots.any?
40
+ end
41
+
42
+ def to_hash
43
+ @store.transaction(true) do
44
+ @store.roots.each_with_object({}) do |name, a|
45
+ a[Regexp.new(name)] = @store[name]
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.included(receiver)
52
+ receiver.class_eval do
53
+ extend Forwardable
54
+ def_delegators :@store, :transaction, :abort, :commit
55
+ include InstanceMethods
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ module VagrantDNS
2
+ # This is the dns pattern registry (aka "config")
3
+ # It basically delegates everything to a YAML::Store but handles the conversion
4
+ # of Regexp dns-patterns into YAML string keys and reverse.
5
+ class TldRegistry
6
+ include VagrantDNS::Store
7
+
8
+ NAME = "ltds"
9
+
10
+ def initialize(tmp_path)
11
+ @store = YAML::Store.new(File.join(tmp_path, NAME), true)
12
+ end
13
+
14
+ # @return [VagrantDNS::Registry,nil] Eitehr an instance or +nil+ if cofig file does not exist.
15
+ def self.open(tmp_path)
16
+ new(tmp_path) if File.exist?(File.join(tmp_path, NAME))
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module VagrantDNS
2
- VERSION = "2.2.3"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/vagrant-dns.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require "vagrant-dns/version"
2
2
  require "vagrant-dns/config"
3
3
 
4
+ require "vagrant-dns/store"
4
5
  require "vagrant-dns/registry"
6
+ require "vagrant-dns/tld_registry"
5
7
  require "vagrant-dns/service"
6
- require "vagrant-dns/installers/mac"
8
+ require "vagrant-dns/installers"
7
9
  require "vagrant-dns/configurator"
8
10
  require "vagrant-dns/middlewares/config_up"
9
11
  require "vagrant-dns/middlewares/config_down"
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.2.3
4
+ version: 2.3.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-04 00:00:00.000000000 Z
12
+ date: 2023-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
@@ -90,6 +90,7 @@ executables: []
90
90
  extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
+ - ".editorconfig"
93
94
  - ".gitignore"
94
95
  - CHANGELOG.md
95
96
  - DEVELOPMENT.md
@@ -102,12 +103,16 @@ files:
102
103
  - lib/vagrant-dns/command.rb
103
104
  - lib/vagrant-dns/config.rb
104
105
  - lib/vagrant-dns/configurator.rb
106
+ - lib/vagrant-dns/installers.rb
107
+ - lib/vagrant-dns/installers/linux.rb
105
108
  - lib/vagrant-dns/installers/mac.rb
106
109
  - lib/vagrant-dns/middlewares/config_down.rb
107
110
  - lib/vagrant-dns/middlewares/config_up.rb
108
111
  - lib/vagrant-dns/middlewares/restart.rb
109
112
  - lib/vagrant-dns/registry.rb
110
113
  - lib/vagrant-dns/service.rb
114
+ - lib/vagrant-dns/store.rb
115
+ - lib/vagrant-dns/tld_registry.rb
111
116
  - lib/vagrant-dns/version.rb
112
117
  - tasks/acceptance.rake
113
118
  - vagrant-dns.gemspec
@@ -131,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
136
  - !ruby/object:Gem::Version
132
137
  version: '0'
133
138
  requirements: []
134
- rubygems_version: 3.3.26
139
+ rubygems_version: 3.1.6
135
140
  signing_key:
136
141
  specification_version: 4
137
142
  summary: vagrant-dns manages DNS records of vagrant machines