vagrant-goodhosts 1.0.6 → 1.0.11

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: 77a1b25e87a6f494d365411f2094bf55b3bb44d52a760aea2cccf81147f326f2
4
- data.tar.gz: a8212f3941c4fd3e55ddc6ce50c1d0a92fb892bf94f2be58f71b89d817c1f972
3
+ metadata.gz: 49d1ef8ce5027c31ed5ec247e6e970c8c4aeaf63768f580a01a8a728c72ab0d7
4
+ data.tar.gz: abab4a95a6f01277fcfdaaac8e18a14a8bf8e2c734d2d9e458458f6224a8f73d
5
5
  SHA512:
6
- metadata.gz: c2d1047db323f73cf93dd19c96f19df9ca4f0226151dab857f0a4e73d87a828cd1edc984cf76adc2ab4115ffc9844801679fe0517b674db88052354421a286e6
7
- data.tar.gz: 17ff9509b9b35ea2adfc423754f549c9edffc15809e3cdc74e24f780bb9976d43d4428a2a1dff9dbc3f6a59ad333e8b84ab9cec2057493dfa6796fd198f6ccc7
6
+ metadata.gz: 300fb83736beb9410f886bc3973e7f3280dfad083b9b0bf995d265f1cd74b53cca9b930255deabc738fcf900768049f102044fe901a069515278a81d77d16435
7
+ data.tar.gz: d24e96eafd0d1bf66c00d8ba52625601af178b3f4e87dc2ec9fcfc8316b465cee3b8ec1dc781759465cb48f02afd6be9cf1772366f7f79bd85525f0b1ddfcced
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,6 +4,7 @@ module VagrantPlugins
4
4
  module Action
5
5
  class UpdateHosts
6
6
  include GoodHosts
7
+ @@updated = false
7
8
 
8
9
  def initialize(app, env)
9
10
  @app = app
@@ -12,8 +13,11 @@ module VagrantPlugins
12
13
  end
13
14
 
14
15
  def call(env)
15
- @ui.info "[vagrant-goodhosts] Checking for host entries"
16
- addHostEntries()
16
+ unless @@updated
17
+ @@updated = true
18
+ @ui.info "[vagrant-goodhosts] Checking for host entries"
19
+ addHostEntries()
20
+ end
17
21
  @app.call(env)
18
22
  end
19
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
@@ -83,21 +79,38 @@ module VagrantPlugins
83
79
 
84
80
  return hostnames
85
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
86
89
 
87
90
  def addHostEntries
88
91
  error = false
89
92
  errorText = ""
90
93
  cli = get_cli
91
94
  hostnames_by_ips = generateHostnamesByIps
95
+
96
+ return if not hostnames_by_ips.any?
97
+
92
98
  hostnames_by_ips.each do |ip_address, hostnames|
93
99
  if ip_address.nil?
94
100
  @ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
95
101
  next
96
102
  end
103
+ clean = ''
97
104
  if cli.include? ".exe"
98
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", "cl", 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")
99
109
  else
100
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "add", "cl", 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}")
101
114
  end
102
115
  if !wait_thr.value.success?
103
116
  error = true
@@ -112,15 +125,24 @@ module VagrantPlugins
112
125
  errorText = ""
113
126
  cli = get_cli
114
127
  hostnames_by_ips = generateHostnamesByIps
128
+
129
+ return if not hostnames_by_ips.any?
130
+
115
131
  hostnames_by_ips.each do |ip_address, hostnames|
116
132
  if ip_address.nil?
117
133
  @ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
118
134
  next
119
135
  end
120
136
  if cli.include? ".exe"
121
- stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "remove", "cl", 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")
122
141
  else
123
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo", cli, "remove", "cl", 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}")
124
146
  end
125
147
  if !wait_thr.value.success?
126
148
  error = true
@@ -147,25 +169,32 @@ module VagrantPlugins
147
169
  def generateHostnamesByIps()
148
170
  hostnames_by_ips = []
149
171
  ips = getIps
172
+ if ips.count() < 1
173
+ return hostnames_by_ips
174
+ end
150
175
  hostnames = getHostnames(ips)
151
176
  if ips.count() > 1
152
177
  ips.each do |ip|
153
178
  ip_address = ip
154
- hostnames[ip].each do |hostname|
155
- if !ip_address.nil?
156
- @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
157
184
  end
185
+ hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
158
186
  end
159
- hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
160
187
  end
161
188
  else
162
189
  ip_address = ips[0]
163
- hostnames[ip_address].each do |hostname|
164
- if !ip_address.nil?
165
- @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
166
195
  end
196
+ hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
167
197
  end
168
- hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
169
198
  end
170
199
 
171
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.6'
3
+ VERSION = '1.0.11'
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.6
4
+ version: 1.0.11
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-10-19 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.4
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