vagrant-goodhosts 1.0.10 → 1.0.15

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: b6661999d4e2dfba792e5a925f4674cca24b6b3e523b8f2b3427933ce09570c6
4
- data.tar.gz: c869c926f280627a4198f8cebcfe47aefffc24e1993e6558a637726d0471dd1a
3
+ metadata.gz: 00dc15e9dc6876fb9f1610777d190e21c6bf6397531950a1cae0f35496e1e989
4
+ data.tar.gz: 30f87a2f1855fde5e646148f02f1861d400de9054109920302e04ab29b95b353
5
5
  SHA512:
6
- metadata.gz: ee107d64bdd466fe0d96778dff5f71a9783ebe0e77392909eb0e7f041941fe436987c39a1d1967b89ef4922aed18ae579c117677c5c3b0e08e276be318d3e1e0
7
- data.tar.gz: 5ccb050a4ff37df1db7c0ba61788cf1149d28c6b05d9e470e91263538c3ef9c287ac1777f03500f84ae205c3460ac1793aed94e49bc0506dc4f057501d9230df
6
+ metadata.gz: b9fd306e3cbff7ad32f524ba17f3248b1b5fdd113e59e341f34deb153f52c39212c1da1b97382d78567101e6edf74b1b1559180a3bdfbcadf3cabb7786c8edad
7
+ data.tar.gz: 908da7239733a24b072256659e453d3864c429306b42f3128a6856e7013b635e0c922d3436c5c4ef902c43c9935f1a91f247fa7a0a0b68c1daab8531d931b4d1
data/README.md CHANGED
@@ -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,44 @@
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
+ if not @@completed.key?(@machine.name)
30
+ run(env)
31
+ @@completed[@machine.name] = true
32
+ end
33
+
34
+ @app.call(env)
35
+ end
36
+
37
+ def run(env)
38
+ raise NotImplementedError.new("Must be implemented!")
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ 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
8
  if machine_action != :destroy || !@machine.id
17
9
  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
10
+ if machine_action != :halt || false != @machine.config.goodhosts.remove_on_suspend
11
+ @ui.info "[vagrant-goodhosts] Removing hosts"
12
+ removeHostEntries
13
+ else
14
+ @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
26
15
  end
27
16
  end
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
@@ -9,7 +9,7 @@ module VagrantPlugins
9
9
  attr_accessor :disable_clean
10
10
 
11
11
  def initialize
12
- @disable_clean = false
12
+ @disable_clean = true
13
13
  end
14
14
  end
15
15
  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.10'
3
+ VERSION = '1.0.15'
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.10
4
+ version: 1.0.15
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-04-19 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