vagrant-virtual-hostsupdater 1.1.2 → 1.2.0

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
  SHA1:
3
- metadata.gz: 6aca82124501a1c94a59ccee3849e3c43bfa5049
4
- data.tar.gz: 8bf2e43df77ad8a3951e95ce848267aaae4f1993
3
+ metadata.gz: 484094d0c9217c204473dbad628d58a04699c125
4
+ data.tar.gz: 0d368c5389f895809770f0301c511df46ed03f15
5
5
  SHA512:
6
- metadata.gz: 6224d8d17cbdcc211aee1848357e8b12506946202ebdc92998bde5ec0ae5ee86923ebdc8de175727796255ad88e6de8973a2f8b36443d9aa7f9d54e8aba113cf
7
- data.tar.gz: 16796cfb0cdd4870028ff230ef783a144ebc06fd398ca0b27a873c7a6146251fa0bbc6195d2c06ebd186c7bf2ccafd3592aae4e03aa5e1844c8ef1a1b94c47af
6
+ metadata.gz: d5ee77bf87d578c12babcc426557f630cc34cee7311819c5d37272d7ba57516c816686f95bc5fa0e9011ac4415e96a2293a829b039264157111152e33dfa5af2
7
+ data.tar.gz: af72c79dba1f957dcad761934960f22af8984bb9ea13f40d4bded0b984ed79047af1d8d256740cb122a5cbe72ec1cd37c86e8cdfe8870224701f31457459ada4
@@ -1,4 +1,4 @@
1
- Copyright 2018 Chris Smith
1
+ Copyright (c) 2016 Falk Kühnel
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -10,10 +10,10 @@
10
10
 
11
11
  This plugin adds an entry to your /etc/hosts file on the host system.
12
12
 
13
- On **up**, **resume** and **reload** commands, it tries to add the information, if it does not already exist in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
13
+ On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
14
14
 
15
15
  On **halt**, **destroy**, and **suspend**, those entries will be removed again.
16
- By setting the `config.hostsupdater.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
16
+ By setting the `config.virtualhostsupdater.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
17
17
 
18
18
 
19
19
  ## Installation
@@ -34,7 +34,7 @@ You currently only need the `hostname` and a `:private_network` network with a f
34
34
 
35
35
  config.vm.network :private_network, ip: "192.168.3.10"
36
36
  config.vm.hostname = "www.testing.de"
37
- config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
37
+ config.virtualhostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
38
38
 
39
39
  This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
40
40
 
@@ -47,7 +47,7 @@ If you have multiple network adapters i.e.:
47
47
 
48
48
  you can specify which hostnames are bound to which IP by passing a hash mapping the IP of the network to an array of hostnames to create, e.g.:
49
49
 
50
- config.hostsupdater.aliases = {
50
+ config.virtualhostsupdater.aliases = {
51
51
  '10.0.0.1' => ['foo.com', 'bar.com'],
52
52
  '10.0.0.2' => ['baz.com', 'bat.com']
53
53
  }
@@ -77,65 +77,22 @@ Example:
77
77
 
78
78
  To keep your /etc/hosts file unchanged simply add the line below to your `VagrantFile`:
79
79
 
80
- config.hostsupdater.remove_on_suspend = false
80
+ config.virtualhostsupdater.remove_on_suspend = false
81
81
 
82
82
  This disables vagrant-hostsupdater from running on **suspend** and **halt**.
83
83
 
84
84
 
85
- ## Suppressing prompts for elevating privileges
85
+ ## Passwordless sudo
86
86
 
87
- These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
88
- If you understand the risks that go with supressing them, here's how to do it.
89
-
90
- ### Linux/OS X: Passwordless sudo
91
-
92
- 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_hostsupdater`.
93
-
94
- For Ubuntu and most Linux environments:
95
-
96
- # Allow passwordless startup of Vagrant with vagrant-hostsupdater.
97
- Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
98
- Cmnd_Alias VAGRANT_HOSTS_REMOVE = /bin/sed -i -e /*/ d /etc/hosts
99
- %sudo ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
100
-
101
- For MacOS:
87
+ Add the following snippet to the top of the sudoers file using `sudo visudo`. It will make vagrant
88
+ stop asking password when updating hosts file:
102
89
 
103
90
  # Allow passwordless startup of Vagrant with vagrant-hostsupdater.
104
91
  Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
105
92
  Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
106
93
  %admin ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
107
94
 
108
- - If vagrant still asks for a password on commands that trigger the `VAGRANT_HOSTS_ADD` alias above (like **up**), you might need to wrap the echo statement in quotes, i.e. `Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c 'echo "*" >> /etc/hosts'`. This seems to be a problem with older versions of Linux and MacOS.
109
- - If vagrant still asks for a password on commands that trigger the `VAGRANT_HOSTS_REMOVE` alias above (like
110
- **halt** or **suspend**), this might indicate that the location of **sed** in the `VAGRANT_HOSTS_REMOVE` alias is
111
- pointing to the wrong location. The solution is to find the location of **sed** (ex. `which sed`) and
112
- replace that location in the `VAGRANT_HOSTS_REMOVE` alias.
113
-
114
- ### Windows: UAC Prompt
115
-
116
- You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
117
- You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
118
-
119
- cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
120
-
121
- ## Using AWS as a Provider
122
-
123
- If you'd like AWS as a provider using [vagrant-aws](https://github.com/mitchellh/vagrant-aws) or other plugin,
124
- this plugin will detect the instance public IP by the tag infomations.
125
- For example, [vagrant-aws](https://github.com/mitchellh/vagrant-aws) configures a tag infomations like the following.
126
-
127
- config.vm.provider :aws do |aws, override|
128
- aws.tags = {
129
- "Name" => "vagrant",
130
- ...
131
- }
132
- aws.elastic_ip = true
133
- ...
134
- end
135
-
136
- * [AWS CLI](https://aws.amazon.com/cli/) is required
137
- * The tag informations be unique for the instance
138
- * Enable Elastic IP for the instance
95
+
139
96
 
140
97
  ## Installing development version
141
98
 
@@ -160,21 +117,8 @@ vagrant plugin install vagrant-hostsupdater-*.gem
160
117
 
161
118
  ## Versions
162
119
 
163
- ### 1.1.2
164
- TODO: gseng
165
-
166
- ### 1.1.1
167
- * Bugfix: AWS Feature broke part of the code [#155](/../../issues/155)
168
-
169
- ### 1.1.0
170
- * Feature: Added AWS support [#74](/../../pull/74)
171
- * Feature: Added libvirt provider [#122](/../../pull/122)
172
- * Feature: Add support for multiple private network adapters [#96](/../../pull/96)
173
- * Feature: Add support for VMs without private/public networking [#23](/../../issues/23)
174
- * Feature: Add Docker support [#149](/../../pull/149)
175
- * Bugfix: Windows users get UAC prompt [#40](/../../issues/40)
176
- * Bugfix: Documentation update and type fix
177
- * Misc: Added a note about suppressing UAC prompts
120
+ ### 1.2.0
121
+ * Have multiple private network support working cross-platform
178
122
 
179
123
  ### 1.0.2
180
124
  * Feature: Added `remove_on_suspend` for `vagrant_halt` [#71](/../../issues/71)
@@ -223,4 +167,4 @@ TODO: gseng
223
167
  * fixed problem with removing hosts entries on destroy command (Thanks to Andy Bohne)
224
168
 
225
169
  ### 0.0.3
226
- * added aliases config option to define additional hostnames
170
+ * added aliases config option to define additional hostnames
@@ -1,14 +1,7 @@
1
- require 'open3'
2
-
3
1
  module VagrantPlugins
4
2
  module VirtualHostsUpdater
5
3
  module VirtualHostsUpdater
6
- if ENV['VAGRANT_HOSTSUPDATER_PATH']
7
- @@hosts_path = ENV['VAGRANT_HOSTSUPDATER_PATH']
8
- else
9
- @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
10
- end
11
- @isWindowsHost = Vagrant::Util::Platform.windows?
4
+ @@hosts_path = Vagrant::Util::Platform.windows? ? File.expand_path('system32/drivers/etc/hosts', ENV['windir']) : '/etc/hosts'
12
5
 
13
6
  # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
14
7
  def getHostnames()
@@ -20,8 +13,6 @@ module VagrantPlugins
20
13
  # complex definition of aliases for various ips
21
14
  @machine.config.virtualhostsupdater.aliases.each do |ip, hosts|
22
15
  hostnames[ip] += Array(hosts)
23
- # else
24
- # @ui.error "[vagrant-virtual-hostsupdater] this version only supports the hash format!"
25
16
  end
26
17
  end
27
18
 
@@ -64,7 +55,7 @@ module VagrantPlugins
64
55
  uuid = @machine.id || @machine.config.virtualhostsupdater.id
65
56
  hashedId = Digest::MD5.hexdigest(uuid)
66
57
  if hostsContents.match(/#{hashedId}/)
67
- removeFromHosts
58
+ removeFromHosts
68
59
  end
69
60
  end
70
61
 
@@ -89,24 +80,15 @@ module VagrantPlugins
89
80
 
90
81
  @ui.info "[vagrant-virtual-hostsupdater] Writing the following entries to (#@@hosts_path)"
91
82
  @ui.info "[vagrant-virtual-hostsupdater] " + entries.join("\n[vagrant-virtual-hostsupdater] ")
83
+ @ui.info "[vagrant-virtual-hostsupdater] This operation requires administrative access. You may " +
84
+ "skip it by manually adding equivalent entries to the hosts file."
92
85
  if !File.writable_real?(@@hosts_path)
93
- @ui.info "[vagrant-virtual-hostsupdater] This operation requires administrative access. You may " +
94
- "skip it by manually adding equivalent entries to the hosts file."
95
86
  if !sudo(%Q(sh -c 'echo "#{content}" >> #@@hosts_path'))
96
87
  @ui.error "[vagrant-virtual-hostsupdater] Failed to add hosts, could not use sudo"
97
88
  adviseOnSudo
98
89
  end
99
- elsif Vagrant::Util::Platform.windows?
100
- require 'tmpdir'
101
- uuid = @machine.id || @machine.config.virtualhostsupdater.id
102
- tmpPath = File.join(Dir.tmpdir, 'hosts-' + uuid + '.cmd')
103
- File.open(tmpPath, "w") do |tmpFile|
104
- entries.each { |line| tmpFile.puts(">>\"#{@@hosts_path}\" echo #{line}") }
105
- end
106
- sudo(tmpPath)
107
- File.delete(tmpPath)
108
90
  else
109
- content = "\n" + content + "\n"
91
+ content = "\n" + content
110
92
  hostsFile = File.open(@@hosts_path, "a")
111
93
  hostsFile.write(content)
112
94
  hostsFile.close()
@@ -116,7 +98,7 @@ module VagrantPlugins
116
98
  def removeFromHosts(options = {})
117
99
  uuid = @machine.id || @machine.config.virtualhostsupdater.id
118
100
  hashedId = Digest::MD5.hexdigest(uuid)
119
- if !File.writable_real?(@@hosts_path) || Vagrant::Util::Platform.windows?
101
+ if !File.writable_real?(@@hosts_path)
120
102
  if !sudo(%Q(sed -i -e '/#{hashedId}/ d' #@@hosts_path))
121
103
  @ui.error "[vagrant-virtual-hostsupdater] Failed to remove hosts, could not use sudo"
122
104
  adviseOnSudo
@@ -126,13 +108,14 @@ module VagrantPlugins
126
108
  File.open(@@hosts_path).each do |line|
127
109
  hosts << line unless line.include?(hashedId)
128
110
  end
129
- hosts.strip!
130
111
  hostsFile = File.open(@@hosts_path, "w")
131
112
  hostsFile.write(hosts)
132
113
  hostsFile.close()
133
114
  end
134
115
  end
135
116
 
117
+
118
+
136
119
  def signature(name, uuid = self.uuid)
137
120
  hashedId = Digest::MD5.hexdigest(uuid)
138
121
  %Q(# VAGRANT: #{hashedId} (#{name}) / #{uuid})
@@ -141,11 +124,7 @@ module VagrantPlugins
141
124
  def sudo(command)
142
125
  return if !command
143
126
  if Vagrant::Util::Platform.windows?
144
- require 'win32ole'
145
- args = command.split(" ")
146
- command = args.shift
147
- sh = WIN32OLE.new('Shell.Application')
148
- sh.ShellExecute(command, args.join(" "), '', 'runas', 0)
127
+ `#{command}`
149
128
  else
150
129
  return system("sudo #{command}")
151
130
  end
@@ -153,25 +132,7 @@ module VagrantPlugins
153
132
 
154
133
  def adviseOnSudo
155
134
  @ui.error "[vagrant-virtual-hostsupdater] Consider adding the following to your sudoers file:"
156
- @ui.error "[vagrant-virtual-hostsupdater] https://github.com/cogitatio/vagrant-hostsupdater#suppressing-prompts-for-elevating-privileges"
157
- end
158
-
159
- def getAwsPublicIp
160
- return nil if ! Vagrant.has_plugin?("vagrant-aws")
161
- aws_conf = @machine.config.vm.get_provider_config(:aws)
162
- return nil if ! aws_conf.is_a?(VagrantPlugins::AWS::Config)
163
- filters = ( aws_conf.tags || [] ).map {|k,v| sprintf('"Name=tag:%s,Values=%s"', k, v) }.join(' ')
164
- return nil if filters == ''
165
- cmd = 'aws ec2 describe-instances --filter '+filters
166
- stdout, stderr, stat = Open3.capture3(cmd)
167
- @ui.error sprintf("Failed to execute '%s' : %s", cmd, stderr) if stderr != ''
168
- return nil if stat.exitstatus != 0
169
- begin
170
- return JSON.parse(stdout)["Reservations"].first()["Instances"].first()["PublicIpAddress"]
171
- rescue => e
172
- @ui.error sprintf("Failed to get IP from the result of '%s' : %s", cmd, e.message)
173
- return nil
174
- end
135
+ @ui.error "[vagrant-virtual-hostsupdater] https://github.com/gokhansengun/vagrant-virtual-hostsupdater#passwordless-sudo"
175
136
  end
176
137
  end
177
138
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module VirtualHostsUpdater
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'vagrant-virtual-hostsupdater'
8
8
  spec.version = VagrantPlugins::VirtualHostsUpdater::VERSION
9
9
  spec.authors = ['Falk Kühnel', 'Chris Smith', 'Gökhan Şengün']
10
- spec.email = ['fk@cogitatio.de', 'chris@cgsmith.net']
10
+ spec.email = ['fk@cogitatio.de', 'chris@cgsmith.net', 'gokhansengun@gmail.com']
11
11
  spec.description = %q{Enables Vagrant to update hosts file on the host machine}
12
12
  spec.summary = spec.description
13
13
  spec.homepage = 'https://github.com/gokhansengun/vagrant-hostsupdater'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-virtual-hostsupdater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Falk Kühnel
@@ -44,6 +44,7 @@ description: Enables Vagrant to update hosts file on the host machine
44
44
  email:
45
45
  - fk@cogitatio.de
46
46
  - chris@cgsmith.net
47
+ - gokhansengun@gmail.com
47
48
  executables: []
48
49
  extensions: []
49
50
  extra_rdoc_files: []