landrush 1.1.0.beta.1 → 1.1.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +5 -14
- data/.travis.yml +1 -1
- data/README.md +29 -5
- data/lib/landrush.rb +0 -2
- data/lib/landrush/action/setup.rb +2 -12
- data/lib/landrush/cap/{all → guest/all}/read_host_visible_ip_address.rb +0 -0
- data/lib/landrush/cap/{debian → guest/debian}/install_iptables.rb +0 -0
- data/lib/landrush/cap/{debian → guest/debian}/iptables_installed.rb +0 -0
- data/lib/landrush/cap/{linux → guest/linux}/add_iptables_rule.rb +1 -1
- data/lib/landrush/cap/{linux → guest/linux}/configured_dns_servers.rb +0 -0
- data/lib/landrush/cap/{linux → guest/linux}/redirect_dns.rb +0 -0
- data/lib/landrush/cap/{redhat → guest/redhat}/install_iptables.rb +0 -0
- data/lib/landrush/cap/{redhat → guest/redhat}/iptables_installed.rb +0 -0
- data/lib/landrush/cap/host/darwin/configure_visibility_on_host.rb +62 -0
- data/lib/landrush/cap/host/debian/dnsmasq_installed.rb +11 -0
- data/lib/landrush/cap/host/debian/host.rb +11 -0
- data/lib/landrush/cap/host/debian/install_dnsmasq.rb +12 -0
- data/lib/landrush/cap/host/debian/restart_dnsmasq.rb +11 -0
- data/lib/landrush/cap/host/linux/configure_visibility_on_host.rb +18 -0
- data/lib/landrush/cap/host/linux/create_dnsmasq_config.rb +65 -0
- data/lib/landrush/cap/host/redhat/dnsmasq_installed.rb +11 -0
- data/lib/landrush/cap/host/redhat/install_dnsmasq.rb +14 -0
- data/lib/landrush/cap/host/redhat/restart_dnsmasq.rb +23 -0
- data/lib/landrush/cap/host/ubuntu/host.rb +12 -0
- data/lib/landrush/cap/host/windows/configure_visibility_on_host.rb +187 -0
- data/lib/landrush/config.rb +22 -15
- data/lib/landrush/plugin.rb +68 -8
- data/lib/landrush/version.rb +1 -1
- data/test/landrush/action/setup_test.rb +4 -34
- data/test/landrush/cap/{all → guest/all}/read_host_visible_ip_address_test.rb +1 -1
- data/test/landrush/cap/{linux → guest/linux}/configured_dns_servers_test.rb +1 -1
- data/test/landrush/cap/{linux → guest/linux}/redirect_dns_test.rb +2 -5
- data/test/landrush/cap/host/darwin/configure_visibility_on_host_test.rb +56 -0
- data/test/landrush/cap/host/linux/configure_visibility_on_host_test.rb +34 -0
- data/test/landrush/cap/host/windows/configure_visibility_on_host_test.rb +70 -0
- data/test/test_helper.rb +28 -17
- metadata +34 -26
- data/lib/landrush/resolver_config.rb +0 -68
- data/lib/landrush/win_network_config.rb +0 -185
- data/test/landrush/resolver_config_test.rb +0 -19
- data/test/landrush/win_network_config_test.rb +0 -70
- data/test/support/fake_resolver_config.rb +0 -25
- data/test/support/fake_ui.rb +0 -5
@@ -1,14 +1,11 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../../../../test_helper'
|
2
2
|
|
3
3
|
describe Landrush::Cap::Linux::RedirectDns do
|
4
4
|
let(:machine) { fake_machine }
|
5
5
|
|
6
6
|
describe 'redirect_dns' do
|
7
7
|
it 'fetches the dns servers from the machine, and adds one iptables rule per server' do
|
8
|
-
machine.guest.stubs(:capability).with(:configured_dns_servers).returns(
|
9
|
-
'1.2.3.4',
|
10
|
-
'4.5.6.7'
|
11
|
-
])
|
8
|
+
machine.guest.stubs(:capability).with(:configured_dns_servers).returns(%w(1.2.3.4 4.5.6.7))
|
12
9
|
|
13
10
|
machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p tcp -d 1.2.3.4 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
|
14
11
|
machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p udp -d 1.2.3.4 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
|
3
|
+
module Landrush
|
4
|
+
module Cap
|
5
|
+
module Darwin
|
6
|
+
describe ConfigureVisibilityOnHost do
|
7
|
+
let(:env) { Vagrant::Environment.new }
|
8
|
+
|
9
|
+
CONFIG = <<-EOF.gsub(/^ +/, '')
|
10
|
+
# Generated by landrush, a vagrant plugin
|
11
|
+
nameserver 127.0.0.1
|
12
|
+
port #{Server.port}
|
13
|
+
EOF
|
14
|
+
|
15
|
+
describe 'configure_visibility_on_host' do
|
16
|
+
it 'writes a resolver config on the host' do
|
17
|
+
Dir.mktmpdir('landrush-test-dir-') do |dir|
|
18
|
+
# puts "Using #{dir} for testing"
|
19
|
+
Dir["#{dir}/*"].empty?.must_equal true
|
20
|
+
|
21
|
+
# stub some internal methods to make sure config gets written into tmp directory
|
22
|
+
ConfigureVisibilityOnHost.stubs(:config_dir).returns(Pathname(dir))
|
23
|
+
# also disable 'sudo'
|
24
|
+
ConfigureVisibilityOnHost.stubs(:sudo).returns('')
|
25
|
+
|
26
|
+
ConfigureVisibilityOnHost.configure_visibility_on_host(env)
|
27
|
+
|
28
|
+
Dir["#{dir}/*"].empty?.must_equal false
|
29
|
+
File.exist?(File.join(dir, 'vagrant.test')).must_equal true
|
30
|
+
Pathname(File.join(dir, 'vagrant.test')).read.must_equal CONFIG
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'the config file is named after the configured tld' do
|
35
|
+
Dir.mktmpdir('landrush-test-dir-') do |dir|
|
36
|
+
# puts "Using #{dir} for testing"
|
37
|
+
Dir["#{dir}/*"].empty?.must_equal true
|
38
|
+
|
39
|
+
# stub some internal methods to make sure config gets written into tmp directory
|
40
|
+
ConfigureVisibilityOnHost.stubs(:config_dir).returns(Pathname(dir))
|
41
|
+
# also disable 'sudo'
|
42
|
+
ConfigureVisibilityOnHost.stubs(:sudo).returns('')
|
43
|
+
|
44
|
+
env.vagrantfile.config.landrush.tld = 'foo.bar'
|
45
|
+
ConfigureVisibilityOnHost.configure_visibility_on_host(env)
|
46
|
+
|
47
|
+
Dir["#{dir}/*"].empty?.must_equal false
|
48
|
+
File.exist?(File.join(dir, 'foo.bar')).must_equal true
|
49
|
+
Pathname(File.join(dir, 'foo.bar')).read.must_equal CONFIG
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
|
3
|
+
module Landrush
|
4
|
+
module Cap
|
5
|
+
module Linux
|
6
|
+
describe ConfigureVisibilityOnHost do
|
7
|
+
TEST_IP = '10.42.42.42'.freeze
|
8
|
+
TEST_TLD = 'landrush.test'.freeze
|
9
|
+
TEST_CONFIG = "/etc/dnsmasq.d/vagrant-landrush-#{TEST_TLD}".freeze
|
10
|
+
|
11
|
+
CONFIG = <<-EOF.gsub(/^ +/, '')
|
12
|
+
# Generated by landrush, a vagrant plugin
|
13
|
+
server=/landrush.test/127.0.0.1#10053
|
14
|
+
EOF
|
15
|
+
|
16
|
+
after do
|
17
|
+
system("sudo rm #{TEST_CONFIG}") if Pathname(TEST_CONFIG).exist?
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'dnsmasq' do
|
21
|
+
it 'creates dnsmasq config' do
|
22
|
+
skip('Only supported on Linux') unless Vagrant::Util::Platform.linux?
|
23
|
+
File.exist?(TEST_CONFIG).must_equal false
|
24
|
+
|
25
|
+
Landrush::Cap::Linux::ConfigureVisibilityOnHost.configure_visibility_on_host(fake_environment, TEST_IP, TEST_TLD)
|
26
|
+
|
27
|
+
File.exist?(TEST_CONFIG).must_equal true
|
28
|
+
Pathname(TEST_CONFIG).read.must_equal CONFIG
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative '../../../../test_helper'
|
2
|
+
|
3
|
+
module Landrush
|
4
|
+
module Cap
|
5
|
+
module Windows
|
6
|
+
describe ConfigureVisibilityOnHost do
|
7
|
+
TEST_IP = '10.42.42.42'.freeze
|
8
|
+
|
9
|
+
before do
|
10
|
+
@vboxmanage_found = !Vagrant::Util::Which.which('VBoxManage').nil?
|
11
|
+
@has_admin_privileges = Landrush::Cap::Windows::ConfigureVisibilityOnHost.admin_mode?
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'modify DNS settings of network adapter' do
|
15
|
+
it 'sets 127.0.0.1 as DNS server on the interface' do
|
16
|
+
skip('Only supported on Windows') unless Vagrant::Util::Platform.windows? && @vboxmanage_found && @has_admin_privileges
|
17
|
+
|
18
|
+
# VBoxManage uses the network description for its commands whereas netsh uses the name
|
19
|
+
# We need to get both
|
20
|
+
begin
|
21
|
+
old_network_state = network_state
|
22
|
+
network_description = create_test_interface
|
23
|
+
new_network_state = network_state
|
24
|
+
network_name = get_network_name(old_network_state, new_network_state)
|
25
|
+
|
26
|
+
get_dns_for_name(network_name).must_be_nil
|
27
|
+
Landrush::Cap::Windows::ConfigureVisibilityOnHost.configure_visibility_on_host(fake_environment, TEST_IP, 'landrush.test')
|
28
|
+
get_dns_for_name(network_name).must_equal '127.0.0.1'
|
29
|
+
rescue
|
30
|
+
delete_test_interface network_description
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def network_state
|
36
|
+
`netsh interface ip show config`.split(/\n/).reject(&:empty?)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_network_name(old_network_state, new_network_state)
|
40
|
+
new_network_state.reject! { |line| old_network_state.include? line }
|
41
|
+
new_network_state[0].match(/.*\"(.*)\"$/).captures[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates a test interface using VBoxMange and sets a known test IP
|
45
|
+
def create_test_interface
|
46
|
+
cmd_out = `VBoxManage hostonlyif create`
|
47
|
+
network_description = cmd_out.match(/.*'(.*)'.*/).captures[0]
|
48
|
+
`VBoxManage.exe hostonlyif ipconfig \"#{network_description}\" --ip #{TEST_IP}`
|
49
|
+
sleep 3
|
50
|
+
network_description
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_test_interface(name)
|
54
|
+
`VBoxManage hostonlyif remove \"#{name}\"`
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_dns_for_name(name)
|
58
|
+
cmd_out = `netsh interface ip show config name=\"#{name}\"`
|
59
|
+
dns = cmd_out.split(/\n/).select { |settings| settings.match(/Statically Configured DNS Servers/m) }
|
60
|
+
# TODO: better error handling
|
61
|
+
begin
|
62
|
+
dns[0].match(/.* (\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}).*/).captures[0]
|
63
|
+
rescue
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -4,10 +4,12 @@ require 'bundler/setup'
|
|
4
4
|
require 'minitest/spec'
|
5
5
|
|
6
6
|
require 'landrush'
|
7
|
-
require 'landrush/cap/linux/configured_dns_servers'
|
8
|
-
require 'landrush/cap/linux/redirect_dns'
|
9
|
-
require 'landrush/cap/all/read_host_visible_ip_address'
|
10
|
-
require 'landrush/
|
7
|
+
require 'landrush/cap/guest/linux/configured_dns_servers'
|
8
|
+
require 'landrush/cap/guest/linux/redirect_dns'
|
9
|
+
require 'landrush/cap/guest/all/read_host_visible_ip_address'
|
10
|
+
require 'landrush/cap/host/darwin/configure_visibility_on_host'
|
11
|
+
require 'landrush/cap/host/windows/configure_visibility_on_host'
|
12
|
+
require 'landrush/cap/host/linux/configure_visibility_on_host'
|
11
13
|
require 'landrush/util/retry'
|
12
14
|
|
13
15
|
require 'minitest/autorun'
|
@@ -17,19 +19,33 @@ require 'mocha/mini_test'
|
|
17
19
|
# Putting include/exclude out of order is kind of the point though ;)
|
18
20
|
def fake_addresses
|
19
21
|
[
|
20
|
-
{
|
21
|
-
{
|
22
|
-
{
|
23
|
-
{
|
24
|
-
{
|
25
|
-
{
|
22
|
+
{'name' => 'exclude1', 'ipv4' => '172.28.128.1', 'ipv6' => '::1'},
|
23
|
+
{'name' => 'include1', 'ipv4' => '172.28.128.2', 'ipv6' => '::2'},
|
24
|
+
{'name' => 'include2', 'ipv4' => '172.28.128.3', 'ipv6' => '::3'},
|
25
|
+
{'name' => 'include3', 'ipv4' => '172.28.128.4', 'ipv6' => '::4'},
|
26
|
+
{'name' => 'exclude2', 'ipv4' => '172.28.128.5', 'ipv6' => '::5'},
|
27
|
+
{'name' => 'exclude3', 'ipv4' => '172.28.128.6', 'ipv6' => '::6'}
|
26
28
|
]
|
27
29
|
end
|
28
30
|
|
29
|
-
def fake_environment(options = {
|
31
|
+
def fake_environment(options = {enabled: true})
|
30
32
|
# For the home_path we want the base Vagrant directory
|
31
33
|
vagrant_test_home = Pathname(Landrush::Server.working_dir).parent.parent
|
32
|
-
|
34
|
+
env = Vagrant::Environment.new
|
35
|
+
{machine: fake_machine(options), host: env.host, ui: FakeUI.new, home_path: vagrant_test_home}
|
36
|
+
end
|
37
|
+
|
38
|
+
class FakeUI
|
39
|
+
attr_reader :received_info_messages
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@received_info_messages = []
|
43
|
+
end
|
44
|
+
|
45
|
+
def info(*args)
|
46
|
+
# puts "#{args}"
|
47
|
+
@received_info_messages << args[0]
|
48
|
+
end
|
33
49
|
end
|
34
50
|
|
35
51
|
class RecordingCommunicator
|
@@ -136,11 +152,6 @@ end
|
|
136
152
|
|
137
153
|
# order is important on these
|
138
154
|
require_relative 'support/create_fake_working_dir'
|
139
|
-
|
140
155
|
require_relative 'support/clear_dependent_vms'
|
141
|
-
|
142
|
-
require_relative 'support/fake_ui'
|
143
156
|
require_relative 'support/test_server_daemon'
|
144
|
-
require_relative 'support/fake_resolver_config'
|
145
|
-
|
146
157
|
require_relative 'support/delete_fake_working_dir'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: landrush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.beta.
|
4
|
+
version: 1.1.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Hinze
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubydns
|
@@ -101,41 +101,50 @@ files:
|
|
101
101
|
- lib/landrush/action/redirect_dns.rb
|
102
102
|
- lib/landrush/action/setup.rb
|
103
103
|
- lib/landrush/action/teardown.rb
|
104
|
-
- lib/landrush/cap/all/read_host_visible_ip_address.rb
|
105
|
-
- lib/landrush/cap/debian/install_iptables.rb
|
106
|
-
- lib/landrush/cap/debian/iptables_installed.rb
|
107
|
-
- lib/landrush/cap/linux/add_iptables_rule.rb
|
108
|
-
- lib/landrush/cap/linux/configured_dns_servers.rb
|
109
|
-
- lib/landrush/cap/linux/redirect_dns.rb
|
110
|
-
- lib/landrush/cap/redhat/install_iptables.rb
|
111
|
-
- lib/landrush/cap/redhat/iptables_installed.rb
|
104
|
+
- lib/landrush/cap/guest/all/read_host_visible_ip_address.rb
|
105
|
+
- lib/landrush/cap/guest/debian/install_iptables.rb
|
106
|
+
- lib/landrush/cap/guest/debian/iptables_installed.rb
|
107
|
+
- lib/landrush/cap/guest/linux/add_iptables_rule.rb
|
108
|
+
- lib/landrush/cap/guest/linux/configured_dns_servers.rb
|
109
|
+
- lib/landrush/cap/guest/linux/redirect_dns.rb
|
110
|
+
- lib/landrush/cap/guest/redhat/install_iptables.rb
|
111
|
+
- lib/landrush/cap/guest/redhat/iptables_installed.rb
|
112
|
+
- lib/landrush/cap/host/darwin/configure_visibility_on_host.rb
|
113
|
+
- lib/landrush/cap/host/debian/dnsmasq_installed.rb
|
114
|
+
- lib/landrush/cap/host/debian/host.rb
|
115
|
+
- lib/landrush/cap/host/debian/install_dnsmasq.rb
|
116
|
+
- lib/landrush/cap/host/debian/restart_dnsmasq.rb
|
117
|
+
- lib/landrush/cap/host/linux/configure_visibility_on_host.rb
|
118
|
+
- lib/landrush/cap/host/linux/create_dnsmasq_config.rb
|
119
|
+
- lib/landrush/cap/host/redhat/dnsmasq_installed.rb
|
120
|
+
- lib/landrush/cap/host/redhat/install_dnsmasq.rb
|
121
|
+
- lib/landrush/cap/host/redhat/restart_dnsmasq.rb
|
122
|
+
- lib/landrush/cap/host/ubuntu/host.rb
|
123
|
+
- lib/landrush/cap/host/windows/configure_visibility_on_host.rb
|
112
124
|
- lib/landrush/command.rb
|
113
125
|
- lib/landrush/config.rb
|
114
126
|
- lib/landrush/dependent_vms.rb
|
115
127
|
- lib/landrush/plugin.rb
|
116
|
-
- lib/landrush/resolver_config.rb
|
117
128
|
- lib/landrush/server.rb
|
118
129
|
- lib/landrush/store.rb
|
119
130
|
- lib/landrush/util/retry.rb
|
120
131
|
- lib/landrush/version.rb
|
121
|
-
- lib/landrush/win_network_config.rb
|
122
132
|
- test/landrush/action/setup_test.rb
|
123
133
|
- test/landrush/action/teardown_test.rb
|
124
|
-
- test/landrush/cap/all/read_host_visible_ip_address_test.rb
|
125
|
-
- test/landrush/cap/linux/configured_dns_servers_test.rb
|
126
|
-
- test/landrush/cap/linux/redirect_dns_test.rb
|
134
|
+
- test/landrush/cap/guest/all/read_host_visible_ip_address_test.rb
|
135
|
+
- test/landrush/cap/guest/linux/configured_dns_servers_test.rb
|
136
|
+
- test/landrush/cap/guest/linux/redirect_dns_test.rb
|
137
|
+
- test/landrush/cap/host/darwin/configure_visibility_on_host_test.rb
|
138
|
+
- test/landrush/cap/host/linux/configure_visibility_on_host_test.rb
|
139
|
+
- test/landrush/cap/host/windows/configure_visibility_on_host_test.rb
|
127
140
|
- test/landrush/config_test.rb
|
128
141
|
- test/landrush/dependent_vms_test.rb
|
129
|
-
- test/landrush/resolver_config_test.rb
|
130
142
|
- test/landrush/server_test.rb
|
131
143
|
- test/landrush/store_test.rb
|
132
144
|
- test/landrush/util/rety_test.rb
|
133
|
-
- test/landrush/win_network_config_test.rb
|
134
145
|
- test/support/clear_dependent_vms.rb
|
135
146
|
- test/support/create_fake_working_dir.rb
|
136
147
|
- test/support/delete_fake_working_dir.rb
|
137
|
-
- test/support/fake_resolver_config.rb
|
138
|
-
- test/support/fake_ui.rb
|
139
148
|
- test/support/test_server_daemon.rb
|
140
149
|
- test/test_helper.rb
|
141
150
|
homepage: https://github.com/vagrant-landrush/landrush
|
@@ -170,20 +179,19 @@ test_files:
|
|
170
179
|
- features/support/env.rb
|
171
180
|
- test/landrush/action/setup_test.rb
|
172
181
|
- test/landrush/action/teardown_test.rb
|
173
|
-
- test/landrush/cap/all/read_host_visible_ip_address_test.rb
|
174
|
-
- test/landrush/cap/linux/configured_dns_servers_test.rb
|
175
|
-
- test/landrush/cap/linux/redirect_dns_test.rb
|
182
|
+
- test/landrush/cap/guest/all/read_host_visible_ip_address_test.rb
|
183
|
+
- test/landrush/cap/guest/linux/configured_dns_servers_test.rb
|
184
|
+
- test/landrush/cap/guest/linux/redirect_dns_test.rb
|
185
|
+
- test/landrush/cap/host/darwin/configure_visibility_on_host_test.rb
|
186
|
+
- test/landrush/cap/host/linux/configure_visibility_on_host_test.rb
|
187
|
+
- test/landrush/cap/host/windows/configure_visibility_on_host_test.rb
|
176
188
|
- test/landrush/config_test.rb
|
177
189
|
- test/landrush/dependent_vms_test.rb
|
178
|
-
- test/landrush/resolver_config_test.rb
|
179
190
|
- test/landrush/server_test.rb
|
180
191
|
- test/landrush/store_test.rb
|
181
192
|
- test/landrush/util/rety_test.rb
|
182
|
-
- test/landrush/win_network_config_test.rb
|
183
193
|
- test/support/clear_dependent_vms.rb
|
184
194
|
- test/support/create_fake_working_dir.rb
|
185
195
|
- test/support/delete_fake_working_dir.rb
|
186
|
-
- test/support/fake_resolver_config.rb
|
187
|
-
- test/support/fake_ui.rb
|
188
196
|
- test/support/test_server_daemon.rb
|
189
197
|
- test/test_helper.rb
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
module Landrush
|
4
|
-
class ResolverConfig
|
5
|
-
class << self
|
6
|
-
attr_writer :sudo, :config_dir
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.sudo
|
10
|
-
@sudo ||= 'sudo'
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.config_dir
|
14
|
-
@config_dir ||= Pathname('/etc/resolver')
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(env={})
|
18
|
-
@env = env
|
19
|
-
end
|
20
|
-
|
21
|
-
def info(msg)
|
22
|
-
@env[:ui].info("[landrush] #{msg}")
|
23
|
-
end
|
24
|
-
|
25
|
-
def desired_contents; <<-EOS.gsub(/^ /, '')
|
26
|
-
# Generated by landrush, a vagrant plugin
|
27
|
-
nameserver 127.0.0.1
|
28
|
-
port #{Server.port}
|
29
|
-
EOS
|
30
|
-
end
|
31
|
-
|
32
|
-
def config_dir
|
33
|
-
self.class.config_dir
|
34
|
-
end
|
35
|
-
|
36
|
-
def config_file
|
37
|
-
config_dir.join(@env[:machine].config.landrush.tld)
|
38
|
-
end
|
39
|
-
|
40
|
-
def contents_match?
|
41
|
-
config_file.exist? && File.read(config_file) == desired_contents
|
42
|
-
end
|
43
|
-
|
44
|
-
def write_config!
|
45
|
-
info 'Momentarily using sudo to put the host config in place...'
|
46
|
-
system "#{self.class.sudo} mkdir #{config_dir}" unless config_dir.directory?
|
47
|
-
Tempfile.open('vagrant_landrush_host_config') do |f|
|
48
|
-
f.write(desired_contents)
|
49
|
-
f.close
|
50
|
-
system "#{sudo} cp #{f.path} #{config_file}"
|
51
|
-
system "#{sudo} chmod 644 #{config_file}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def ensure_config_exists!
|
56
|
-
if contents_match?
|
57
|
-
info 'Host DNS resolver config looks good.'
|
58
|
-
else
|
59
|
-
info 'Need to configure the host.'
|
60
|
-
write_config!
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def sudo
|
65
|
-
self.class.sudo
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|