vagrant-goodhosts 1.0.11 → 1.0.16

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: 49d1ef8ce5027c31ed5ec247e6e970c8c4aeaf63768f580a01a8a728c72ab0d7
4
- data.tar.gz: abab4a95a6f01277fcfdaaac8e18a14a8bf8e2c734d2d9e458458f6224a8f73d
3
+ metadata.gz: 6843d62e56a2bd4b265a0b4854bcb69fba17c99b60515ad4bdb23ef1decf384b
4
+ data.tar.gz: dfb62145d87e3d1d3122a6777399d3fb41c620df68f762ed6284c3221066e72b
5
5
  SHA512:
6
- metadata.gz: 300fb83736beb9410f886bc3973e7f3280dfad083b9b0bf995d265f1cd74b53cca9b930255deabc738fcf900768049f102044fe901a069515278a81d77d16435
7
- data.tar.gz: d24e96eafd0d1bf66c00d8ba52625601af178b3f4e87dc2ec9fcfc8316b465cee3b8ec1dc781759465cb48f02afd6be9cf1772366f7f79bd85525f0b1ddfcced
6
+ metadata.gz: 9476f2832c25de5c268f2bcbda6f243f784ed641143c8a5b26fd0511582e9cbd010ff99faa96f53084699c16970a9efb71964309914f4d4e4847dacae2392346
7
+ data.tar.gz: 583d8ccf7c2c5e77feed7980987facb0fe156e1325efd580d19c20518cea2141a4b80e6cb18d8f15a550f945099c9c37755c13dc703d44e72c60b14c30e75104
data/README.md CHANGED
@@ -30,7 +30,7 @@ You currently only need the `hostname` and a `:private_network` network with a f
30
30
 
31
31
  ```ruby
32
32
  config.vm.network :private_network, ip: "192.168.3.10"
33
- config.vm.hostname = "www.testing.de"
33
+ config.vm.hostname = "www.testing.de" # This is not used by the plugin
34
34
  config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
35
35
  ```
36
36
 
@@ -80,13 +80,13 @@ This disables `vagrant-goodhosts` from running on **suspend** and **halt**.
80
80
 
81
81
  ### Disable file hosts clean
82
82
 
83
- If you don't want `/etc/hosts` file cleaned add in your `VagrantFile`:
83
+ If you want `/etc/hosts` file cleaned add in your `VagrantFile`:
84
84
 
85
85
  ```ruby
86
- config.goodhosts.disable_clean = true
86
+ config.goodhosts.disable_clean = false
87
87
  ```
88
88
 
89
- This disables `vagrant-goodhosts` from running the clean command.
89
+ This enable `vagrant-goodhosts` from running the clean command in every call.
90
90
 
91
91
  ## Suppressing prompts for elevating privileges
92
92
 
@@ -0,0 +1,45 @@
1
+ module VagrantPlugins
2
+ module GoodHosts
3
+ module Action
4
+ class BaseAction
5
+ include GoodHosts
6
+
7
+ # Vagrant 2.2.14 has changed the hooks execution policy so they
8
+ # started to be triggered more than once (a lot actually) which
9
+ # is non-performant and floody. With this static property, we
10
+ # control the executions and allowing just one.
11
+ #
12
+ # - https://github.com/hashicorp/vagrant/issues/12070#issuecomment-732271918
13
+ # - https://github.com/hashicorp/vagrant/compare/v2.2.13..v2.2.14#diff-4d1af7c67af870f20d303c3c43634084bab8acc101055b2e53ddc0d07f6f64dcL176-L180
14
+ # - https://github.com/goodhosts/vagrant/issues/25
15
+ @@completed = {}
16
+
17
+ def initialize(app, env)
18
+ @app = app
19
+ @machine = env[:machine]
20
+ @ui = env[:ui]
21
+ end
22
+
23
+ def call(env)
24
+ # Check whether the plugin has been executed for a particular
25
+ # VM as it may happen that a single Vagrantfile defines multiple
26
+ # machines and having a static flag will result in a plugin being
27
+ # executed just once.
28
+ # https://github.com/goodhosts/vagrant/issues/30
29
+ @@completed[@machine.name] = [] unless @@completed.key?(@machine.name)
30
+ unless @@completed[@machine.name].include? self.class.name
31
+ run(env)
32
+ @@completed[@machine.name] << self.class.name
33
+ end
34
+
35
+ @app.call(env)
36
+ end
37
+
38
+ def run(env)
39
+ raise NotImplementedError.new("Must be implemented!")
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,32 +1,20 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
3
  module Action
4
- class RemoveHosts
5
- include GoodHosts
6
- @@updated = false
4
+ class RemoveHosts < BaseAction
7
5
 
8
- def initialize(app, env)
9
- @app = app
10
- @machine = env[:machine]
11
- @ui = env[:ui]
12
- end
13
-
14
- def call(env)
6
+ def run(env)
15
7
  machine_action = env[:machine_action]
16
- if machine_action != :destroy || !@machine.id
17
- if machine_action != :suspend || false != @machine.config.goodhosts.remove_on_suspend
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
26
- end
27
- end
8
+
9
+ return unless @machine.id
10
+ return unless [:destroy, :halt, :suspend].include? machine_action
11
+
12
+ if ([:halt, :suspend].include? machine_action) && (false == @machine.config.goodhosts.remove_on_suspend)
13
+ @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
14
+ else
15
+ @ui.info "[vagrant-goodhosts] Removing hosts"
16
+ removeHostEntries
28
17
  end
29
- @app.call(env)
30
18
  end
31
19
 
32
20
  end
@@ -1,24 +1,11 @@
1
- require_relative "../GoodHosts"
2
1
  module VagrantPlugins
3
2
  module GoodHosts
4
3
  module Action
5
- class UpdateHosts
6
- include GoodHosts
7
- @@updated = false
4
+ class UpdateHosts < BaseAction
8
5
 
9
- def initialize(app, env)
10
- @app = app
11
- @machine = env[:machine]
12
- @ui = env[:ui]
13
- end
14
-
15
- def call(env)
16
- unless @@updated
17
- @@updated = true
18
- @ui.info "[vagrant-goodhosts] Checking for host entries"
19
- addHostEntries()
20
- end
21
- @app.call(env)
6
+ def run(env)
7
+ @ui.info "[vagrant-goodhosts] Checking for host entries"
8
+ addHostEntries()
22
9
  end
23
10
 
24
11
  end
@@ -7,6 +7,11 @@ module VagrantPlugins
7
7
  def getIps
8
8
  ips = []
9
9
 
10
+ if @machine.config.vm.networks.length == 0
11
+ @ui.error("[vagrant-goodhosts] No ip address found for this virtual machine")
12
+ exit
13
+ end
14
+
10
15
  @machine.config.vm.networks.each do |network|
11
16
  key, options = network[0], network[1]
12
17
  ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
@@ -80,7 +85,7 @@ module VagrantPlugins
80
85
  return hostnames
81
86
  end
82
87
 
83
- def shouldClean(ip_address)
88
+ def disableClean(ip_address)
84
89
  unless ip_address.nil?
85
90
  return @machine.config.goodhosts.disable_clean
86
91
  end
@@ -100,17 +105,18 @@ module VagrantPlugins
100
105
  @ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
101
106
  next
102
107
  end
103
- clean = ''
104
108
  if cli.include? ".exe"
105
- if not shouldClean(ip_address)
106
- clean = "\"--clean\","
109
+ clean = "\"--clean\","
110
+ if disableClean(ip_address)
111
+ clean = ''
107
112
  end
108
113
  stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
109
114
  else
110
- if not shouldClean(ip_address)
111
- clean = "--clean"
115
+ clean = "--clean"
116
+ if disableClean(ip_address)
117
+ clean = ''
112
118
  end
113
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} add #{clean} #{ip_address} #{hostnames}")
119
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
114
120
  end
115
121
  if !wait_thr.value.success?
116
122
  error = true
@@ -134,15 +140,17 @@ module VagrantPlugins
134
140
  next
135
141
  end
136
142
  if cli.include? ".exe"
137
- if not shouldClean(ip_address)
138
- clean = "\"--clean\","
143
+ clean = "\"--clean\","
144
+ if disableClean(ip_address)
145
+ clean = ''
139
146
  end
140
147
  stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
141
148
  else
142
- if not shouldClean(ip_address)
143
- clean = "--clean"
149
+ clean = "\"--clean\","
150
+ if disableClean(ip_address)
151
+ clean = ''
144
152
  end
145
- stdin, stdout, stderr, wait_thr = Open3.popen3("sudo #{cli} remove #{clean} #{ip_address} #{hostnames}")
153
+ stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
146
154
  end
147
155
  if !wait_thr.value.success?
148
156
  error = true
@@ -176,7 +184,7 @@ module VagrantPlugins
176
184
  if ips.count() > 1
177
185
  ips.each do |ip|
178
186
  ip_address = ip
179
- if hostnames[ip].count() > 1
187
+ if hostnames[ip].count() > 0
180
188
  hostnames[ip].each do |hostname|
181
189
  if !ip_address.nil?
182
190
  @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
@@ -187,7 +195,7 @@ module VagrantPlugins
187
195
  end
188
196
  else
189
197
  ip_address = ips[0]
190
- if hostnames[ip_address].count() > 1
198
+ if hostnames[ip_address].count() > 0
191
199
  hostnames[ip_address].each do |hostname|
192
200
  if !ip_address.nil?
193
201
  @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
@@ -9,7 +9,8 @@ module VagrantPlugins
9
9
  attr_accessor :disable_clean
10
10
 
11
11
  def initialize
12
- @disable_clean = false
12
+ @remove_on_suspend = true
13
+ @disable_clean = true
13
14
  end
14
15
  end
15
16
  end
@@ -1,5 +1,7 @@
1
- require "vagrant-goodhosts/Action/UpdateHosts"
2
- require "vagrant-goodhosts/Action/RemoveHosts"
1
+ require_relative "GoodHosts"
2
+ require_relative "Action/BaseAction"
3
+ require_relative "Action/UpdateHosts"
4
+ require_relative "Action/RemoveHosts"
3
5
 
4
6
  module VagrantPlugins
5
7
  module GoodHosts
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.11'
3
+ VERSION = '1.0.16'
4
4
  end
5
5
  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.11
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniele Scasciafratte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-18 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/vagrant-goodhosts.rb
54
+ - lib/vagrant-goodhosts/Action/BaseAction.rb
54
55
  - lib/vagrant-goodhosts/Action/RemoveHosts.rb
55
56
  - lib/vagrant-goodhosts/Action/UpdateHosts.rb
56
57
  - lib/vagrant-goodhosts/GoodHosts.rb