vagrant-goodhosts 1.0.4 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d08aeb238e55a6b9c10399ed2bb6cdf227e223bbde08e4a6dfb11366e67e5ee
4
- data.tar.gz: 59169325206bd3f62a0b040d259fe14dc42dd3fa310822e5bccd4fc04beb15c0
3
+ metadata.gz: b6661999d4e2dfba792e5a925f4674cca24b6b3e523b8f2b3427933ce09570c6
4
+ data.tar.gz: c869c926f280627a4198f8cebcfe47aefffc24e1993e6558a637726d0471dd1a
5
5
  SHA512:
6
- metadata.gz: 4be9ec9e1d21b768de7c7a711f49daebec9606d28bdaf0a897f6deacb45faa76c1c6aec786a1701f119b5e6f4a4152a39315b58bfef77e9fd6dfa14744656519
7
- data.tar.gz: 2a3e60b74d59745cea020b37dbd946ab0a1a14cbd77041727b20c0f55d9879871704512540578cbe8a247a86d55608c72692b016b061438569d231d4606e14b8
6
+ metadata.gz: ee107d64bdd466fe0d96778dff5f71a9783ebe0e77392909eb0e7f041941fe436987c39a1d1967b89ef4922aed18ae579c117677c5c3b0e08e276be318d3e1e0
7
+ data.tar.gz: 5ccb050a4ff37df1db7c0ba61788cf1149d28c6b05d9e470e91263538c3ef9c287ac1777f03500f84ae205c3460ac1793aed94e49bc0506dc4f057501d9230df
data/.gitignore CHANGED
@@ -1,16 +1,35 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # editors
5
+ *.swp
6
+
7
+ # Bundler/Rubygems
1
8
  *.gem
9
+ .bundle
10
+ pkg/*
11
+ tags
12
+ Gemfile.lock
13
+
14
+ # Vagrant
15
+ .vagrant
16
+ Vagrantfile
17
+ !example_box/Vagrantfile
18
+
19
+ # RVM files for gemset/ruby setting
20
+ .ruby-*
21
+ .rvmrc
22
+
2
23
  .idea
3
24
  *.rbc
4
25
  .bundle
5
26
  .config
6
27
  .yardoc
7
- Gemfile.lock
8
28
  InstalledFiles
9
29
  _yardoc
10
30
  coverage
11
31
  doc/
12
32
  lib/bundler/man
13
- pkg
14
33
  rdoc
15
34
  spec/reports
16
35
  test/tmp
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.6.2'
4
+ gem "vagrant", git: "https://github.com/hashicorp/vagrant.git"
5
5
  end
6
6
 
7
7
  group :plugins do
8
- gemspec
9
- end
8
+ gem "vagrant-goodhosts", path: "."
9
+ end
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Vagrant::Goodhosts
2
2
 
3
- This vagrant plugin adds host file entries to the host pointing to the guest VM, using the [GoodHosts](https://github.com/goodhosts/cli) cli tool. This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) and aims to be compatible with the same config parameters.
3
+ This vagrant plugin adds host file entries to the host pointing to the guest VM, using the [GoodHosts](https://github.com/goodhosts/cli) cli tool. This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) and aims to be compatible with the same config parameters.
4
4
 
5
5
  On **up**, **resume** and **reload** commands, it tries to add the hosts if they do not already exist in your hosts file. If it needs to be added, you will be asked for the `sudo` password to make the necessary edits.
6
6
 
7
- On **halt**, **destroy**, and **suspend**, those entries will be removed again. By setting the `config.goodhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
7
+ On **halt**, **destroy**, and **suspend**, those entries will be removed again. By setting the `config.goodhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
8
8
 
9
9
  ## Installation
10
10
 
@@ -38,7 +38,7 @@ This IP address and the hostname will be used for the entry in the `/etc/hosts`
38
38
 
39
39
  ### vagrant-hostsupdater conflicts
40
40
 
41
- The original plugin has the issue of be executed in any vagrant environment, also that is not using and will add a rule in the hosts file that is not generated by this one.
41
+ The original plugin has the issue of be executed in any vagrant environment, also that is not using and will add a rule in the hosts file that is not generated by this one.
42
42
  To avoid issues is better to remove that plugin and in case update accordingly the Vagrantfile if use it. Require just a change of the reference of the plugin name as the example above.
43
43
 
44
44
  ### Multiple private network adapters
@@ -78,15 +78,24 @@ config.goodhosts.remove_on_suspend = false
78
78
 
79
79
  This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
80
80
 
81
+ ### Disable file hosts clean
82
+
83
+ If you don't want `/etc/hosts` file cleaned add in your `VagrantFile`:
84
+
85
+ ```ruby
86
+ config.goodhosts.disable_clean = true
87
+ ```
88
+
89
+ This disables `vagrant-goodhosts` from running the clean command.
81
90
 
82
91
  ## Suppressing prompts for elevating privileges
83
92
 
84
- These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
93
+ These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
85
94
  If you understand the risks that go with supressing them, here's how to do it.
86
95
 
87
96
  ### Linux/OS X: Passwordless sudo
88
97
 
89
- To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. `sudo visudo -f /etc/sudoers.d/vagrant_goodhosts`.
98
+ To allow vagrant to automatically update the hosts file without asking for a sudo password, add one of the following snippets to a new sudoers file include, i.e. `sudo visudo -f /etc/sudoers.d/vagrant_goodhosts`.
90
99
  The command path is printed when there are errors with sudo.
91
100
 
92
101
  For Ubuntu and most Linux environments:
@@ -96,15 +105,15 @@ For Ubuntu and most Linux environments:
96
105
  For MacOS:
97
106
 
98
107
  %admin ALL=(root) NOPASSWD: [the-path]
99
-
108
+
100
109
  Replace in both %sudo/%admin with the username it if it is not working for you.
101
110
 
102
111
  ### Windows: UAC Prompt
103
112
 
104
- You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
113
+ You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
105
114
  You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
106
115
 
107
- cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
116
+ cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
108
117
 
109
118
  ## Installing The Development Version
110
119
 
@@ -113,7 +122,6 @@ If you would like to install `vagrant-goodhosts` to make contributions or change
113
122
  ```shell
114
123
  git clone https://github.com/goodhosts/vagrant vagrant-goodhosts
115
124
  cd vagrant-goodhosts
116
- git checkout develop
117
125
  ./package.sh
118
126
  vagrant plugin install vagrant-goodhosts-*.gem
119
127
  ```
data/Rakefile CHANGED
@@ -1,3 +1,14 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Change to the directory of this file.
10
+ Dir.chdir(File.expand_path("../", __FILE__))
11
+
12
+ # This installs the tasks that help with gem creation and
13
+ # publishing.
3
14
  Bundler::GemHelper.install_tasks
@@ -3,6 +3,7 @@ module VagrantPlugins
3
3
  module Action
4
4
  class RemoveHosts
5
5
  include GoodHosts
6
+ @@updated = false
6
7
 
7
8
  def initialize(app, env)
8
9
  @app = app
@@ -14,11 +15,14 @@ module VagrantPlugins
14
15
  machine_action = env[:machine_action]
15
16
  if machine_action != :destroy || !@machine.id
16
17
  if machine_action != :suspend || false != @machine.config.goodhosts.remove_on_suspend
17
- if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
18
- @ui.info "[vagrant-goodhosts] Removing hosts"
19
- removeHostEntries
20
- else
21
- @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
18
+ unless @@updated
19
+ @@updated = true
20
+ if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
21
+ @ui.info "[vagrant-goodhosts] Removing hosts"
22
+ removeHostEntries
23
+ else
24
+ @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -4,7 +4,7 @@ module VagrantPlugins
4
4
  module Action
5
5
  class UpdateHosts
6
6
  include GoodHosts
7
-
7
+ @@updated = false
8
8
 
9
9
  def initialize(app, env)
10
10
  @app = app
@@ -13,8 +13,11 @@ module VagrantPlugins
13
13
  end
14
14
 
15
15
  def call(env)
16
- @ui.info "[vagrant-goodhosts] Checking for host entries"
17
- addHostEntries()
16
+ unless @@updated
17
+ @@updated = true
18
+ @ui.info "[vagrant-goodhosts] Checking for host entries"
19
+ addHostEntries()
20
+ end
18
21
  @app.call(env)
19
22
  end
20
23
 
@@ -5,10 +5,6 @@ module VagrantPlugins
5
5
  module GoodHosts
6
6
  module GoodHosts
7
7
  def getIps
8
- if Vagrant.has_plugin?("vagrant-hostsupdater")
9
- @ui.warn "[vagrant-goodhosts] Warning: The vagrant-hostsupdater plugin is installed, hostsupdater always adds the VM name even if the VagrantFile says not to. This shouldn't cause issues, but if it does, uninstall hostsupdater"
10
- end
11
-
12
8
  ips = []
13
9
 
14
10
  @machine.config.vm.networks.each do |network|
@@ -16,7 +12,7 @@ module VagrantPlugins
16
12
  ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
17
13
  ips.push(ip) if ip
18
14
  if options[:goodhosts] == "skip"
19
- @ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
15
+ @ui.info '[vagrant-goodhosts] Skipped adding host entries (config.vm.network goodhosts: "skip" is set)'
20
16
  end
21
17
 
22
18
  @machine.config.vm.provider :hyperv do |v|
@@ -36,7 +32,7 @@ module VagrantPlugins
36
32
  end
37
33
  end
38
34
 
39
-
35
+
40
36
  end
41
37
  return ips
42
38
  end
@@ -81,32 +77,40 @@ module VagrantPlugins
81
77
  end
82
78
  end
83
79
 
84
- # handle default hostname(s) if not already specified in the aliases
85
- Array(@machine.config.vm.hostname).each do |host|
86
- if hostnames.none? { |k, v| v.include?(host) }
87
- ips.each do |ip|
88
- hostnames[ip].unshift host
89
- end
90
- end
91
- end
92
-
93
80
  return hostnames
94
81
  end
82
+
83
+ def shouldClean(ip_address)
84
+ unless ip_address.nil?
85
+ return @machine.config.goodhosts.disable_clean
86
+ end
87
+ return true
88
+ end
95
89
 
96
90
  def addHostEntries
97
91
  error = false
98
92
  errorText = ""
99
93
  cli = get_cli
100
94
  hostnames_by_ips = generateHostnamesByIps
95
+
96
+ return if not hostnames_by_ips.any?
97
+
101
98
  hostnames_by_ips.each do |ip_address, hostnames|
102
99
  if ip_address.nil?
103
100
  @ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
104
101
  next
105
102
  end
103
+ clean = ''
106
104
  if cli.include? ".exe"
107
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", ip_address, hostnames)
105
+ if not shouldClean(ip_address)
106
+ clean = "\"--clean\","
107
+ end
108
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
108
109
  else
109
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", ip_address, hostnames)
110
+ if not shouldClean(ip_address)
111
+ clean = "--clean"
112
+ end
113
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", clean, ip_address, hostnames)
110
114
  end
111
115
  if !wait_thr.value.success?
112
116
  error = true
@@ -121,15 +125,24 @@ module VagrantPlugins
121
125
  errorText = ""
122
126
  cli = get_cli
123
127
  hostnames_by_ips = generateHostnamesByIps
128
+
129
+ return if not hostnames_by_ips.any?
130
+
124
131
  hostnames_by_ips.each do |ip_address, hostnames|
125
132
  if ip_address.nil?
126
133
  @ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
127
134
  next
128
135
  end
129
136
  if cli.include? ".exe"
130
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "remove", ip_address, hostnames)
137
+ if not shouldClean(ip_address)
138
+ clean = "\"--clean\","
139
+ end
140
+ stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
131
141
  else
132
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", ip_address, hostnames)
142
+ if not shouldClean(ip_address)
143
+ clean = "--clean"
144
+ end
145
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", clean, ip_address, hostnames)
133
146
  end
134
147
  if !wait_thr.value.success?
135
148
  error = true
@@ -156,25 +169,32 @@ module VagrantPlugins
156
169
  def generateHostnamesByIps()
157
170
  hostnames_by_ips = []
158
171
  ips = getIps
172
+ if ips.count() < 1
173
+ return hostnames_by_ips
174
+ end
159
175
  hostnames = getHostnames(ips)
160
176
  if ips.count() > 1
161
177
  ips.each do |ip|
162
178
  ip_address = ip
163
- hostnames[ip].each do |hostname|
164
- if !ip_address.nil?
165
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
179
+ if hostnames[ip].count() > 1
180
+ hostnames[ip].each do |hostname|
181
+ if !ip_address.nil?
182
+ @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
183
+ end
166
184
  end
185
+ hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
167
186
  end
168
- hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
169
187
  end
170
188
  else
171
189
  ip_address = ips[0]
172
- hostnames[ip_address].each do |hostname|
173
- if !ip_address.nil?
174
- @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
190
+ if hostnames[ip_address].count() > 1
191
+ hostnames[ip_address].each do |hostname|
192
+ if !ip_address.nil?
193
+ @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
194
+ end
175
195
  end
196
+ hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
176
197
  end
177
- hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
178
198
  end
179
199
 
180
200
  return hostnames_by_ips
@@ -6,6 +6,11 @@ module VagrantPlugins
6
6
  attr_accessor :aliases
7
7
  attr_accessor :id
8
8
  attr_accessor :remove_on_suspend
9
+ attr_accessor :disable_clean
10
+
11
+ def initialize
12
+ @disable_clean = false
13
+ end
9
14
  end
10
15
  end
11
16
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.10'
4
4
  end
5
5
  end
@@ -3,22 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'vagrant-goodhosts/version'
5
5
 
6
- Gem::Specification.new do |spec|
7
- spec.name = 'vagrant-goodhosts'
8
- spec.version = VagrantPlugins::GoodHosts::VERSION
9
- spec.authors = ['Daniele Scasciafratte']
10
- spec.email = ['mte90net@gmail.com']
11
- spec.description = %q{Enables Vagrant to update hosts file on the host machine with goodhosts}
12
- spec.summary = spec.description
13
- spec.homepage = 'https://github.com/goodhosts/vagrant'
14
- spec.license = 'MIT'
6
+ Gem::Specification.new do |s|
7
+ s.name = 'vagrant-goodhosts'
8
+ s.version = VagrantPlugins::GoodHosts::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Daniele Scasciafratte']
11
+ s.email = ['mte90net@gmail.com']
12
+ s.description = "Enables Vagrant to update hosts file on the host machine with goodhosts"
13
+ s.summary = s.description
14
+ s.homepage = 'https://github.com/goodhosts/vagrant'
15
+ s.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.files += Dir.glob("lib/vagrant-goodhosts/bundle/*")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ['lib']
17
+ s.files = `git ls-files`.split($/)
18
+ s.files += Dir.glob("lib/vagrant-goodhosts/bundle/*")
19
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
+ s.require_paths = ['lib']
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.3'
23
- spec.add_development_dependency 'rake'
23
+ s.add_development_dependency 'bundler', '~> 1.3'
24
+ s.add_development_dependency 'rake'
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-goodhosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniele Scasciafratte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2021-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.1.2
84
+ rubygems_version: 3.2.5
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Enables Vagrant to update hosts file on the host machine with goodhosts