vagrant-goodhosts 1.0.0.pre.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 13ef1e50681184f9636c42cb63ef886051aab4f19c388f913f81e3ccee5c9c61
4
+ data.tar.gz: 60da586ec22b7387b3b7ca20641ec49316e3ecd4ed10e672c82fc48f1c8bb8d0
5
+ SHA512:
6
+ metadata.gz: f140337609b3baae16139812a8013c7bb2396765340db63b8bb8ad740a115ee62fc089327bf9366113029cbc17419b418cc1309c5cfa176e0f863298ac5b75e0
7
+ data.tar.gz: da008e6cc94397d22242e2b75a5d4c3e15c9c6d0cc7bc7a4a3b508361572304ab0a949211dea4430ce1b5c7b3f68cf8ee3b8f213dac9043d50715953b34025f2
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ .idea
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ bundle/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git', :tag => 'v1.6.2'
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright 2018 Chris Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Vagrant::Goodhosts
2
+
3
+ This plugin adds an entry to your /etc/hosts file on the host system using [GoodHosts](https://github.com/goodhosts/cli). This plugin is based on [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater) to be compatible with the same config parameters.
4
+
5
+ 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.
6
+
7
+ On **halt**, **destroy**, and **suspend**, those entries will be removed again.
8
+ By setting the `config.goodhosts.remove_on_suspend = false`, **suspend** and **halt** will not remove them.
9
+
10
+
11
+ ## Installation
12
+
13
+ $ vagrant plugin install vagrant-goodhosts
14
+
15
+ Uninstall it with:
16
+
17
+ $ vagrant plugin uninstall vagrant-goodhosts
18
+
19
+ Update the plugin with:
20
+
21
+ $ vagrant plugin update vagrant-goodhosts
22
+
23
+ ## Usage
24
+
25
+ You currently only need the `hostname` and a `:private_network` network with a fixed IP address.
26
+
27
+ config.vm.network :private_network, ip: "192.168.3.10"
28
+ config.vm.hostname = "www.testing.de"
29
+ config.goodhosts.aliases = ["alias.testing.de", "alias2.somedomain.com"]
30
+
31
+ This IP address and the hostname will be used for the entry in the `/etc/hosts` file.
32
+
33
+ ### Multiple private network adapters
34
+
35
+ If you have multiple network adapters i.e.:
36
+
37
+ config.vm.network :private_network, ip: "10.0.0.1"
38
+ config.vm.network :private_network, ip: "10.0.0.2"
39
+
40
+ 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.:
41
+
42
+ config.goodhosts.aliases = {
43
+ '10.0.0.1' => ['foo.com', 'bar.com'],
44
+ '10.0.0.2' => ['baz.com', 'bat.com']
45
+ }
46
+
47
+ This will produce `/etc/hosts` entries like so:
48
+
49
+ 10.0.0.1 foo.com
50
+ 10.0.0.1 bar.com
51
+ 10.0.0.2 baz.com
52
+ 10.0.0.2 bat.com
53
+
54
+ ### Keeping Host Entries After Suspend/Halt
55
+
56
+ To keep your /etc/hosts file unchanged simply add the line below to your `VagrantFile`:
57
+
58
+ config.goodhosts.remove_on_suspend = false
59
+
60
+ This disables vagrant-goodhosts from running on **suspend** and **halt**.
61
+
62
+
63
+ ## Suppressing prompts for elevating privileges
64
+
65
+ These prompts exist to prevent anything that is being run by the user from inadvertently updating the hosts file.
66
+ If you understand the risks that go with supressing them, here's how to do it.
67
+
68
+ ### Linux/OS X: Passwordless sudo
69
+
70
+ 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`.
71
+ Change the cli path as printed in the vagrant output.
72
+
73
+ For Ubuntu and most Linux environments:
74
+
75
+ %sudo ALL=(root) NOPASSWD: [the-path]
76
+
77
+ For MacOS:
78
+
79
+ %admin ALL=(root) NOPASSWD: [the-path]
80
+
81
+ ### Windows: UAC Prompt
82
+
83
+ You can use `cacls` or `icacls` to grant your user account permanent write permission to the system's hosts file.
84
+ You have to open an elevated command prompt; hold `❖ Win` and press `X`, then choose "Command Prompt (Admin)"
85
+
86
+ cacls %SYSTEMROOT%\system32\drivers\etc\hosts /E /G %USERNAME%:W
87
+
88
+ ## Installing development version
89
+
90
+ If you would like to install vagrant-goodhosts on the development version perform the following:
91
+
92
+ ```
93
+ git clone https://github.com/goodhosts/vagrant
94
+ cd vagrant-goodhosts
95
+ git checkout develop
96
+ ./package.sh
97
+ vagrant plugin install vagrant-goodhosts-*.gem
98
+ ```
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require "vagrant-goodhosts/version"
2
+ require "vagrant-goodhosts/plugin"
3
+
4
+ module VagrantPlugins
5
+ module GoodHosts
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,31 @@
1
+ module VagrantPlugins
2
+ module GoodHosts
3
+ module Action
4
+ class RemoveHosts
5
+ include GoodHosts
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @machine = env[:machine]
10
+ @ui = env[:ui]
11
+ end
12
+
13
+ def call(env)
14
+ machine_action = env[:machine_action]
15
+ if machine_action != :destroy || !@machine.id
16
+ 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"
22
+ end
23
+ end
24
+ end
25
+ @app.call(env)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "../GoodHosts"
2
+ module VagrantPlugins
3
+ module GoodHosts
4
+ module Action
5
+ class UpdateHosts
6
+ include GoodHosts
7
+
8
+
9
+ def initialize(app, env)
10
+ @app = app
11
+ @machine = env[:machine]
12
+ @ui = env[:ui]
13
+ end
14
+
15
+ def call(env)
16
+ @ui.info "[vagrant-goodhosts] Checking for host entries"
17
+ addHostEntries()
18
+ @app.call(env)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,162 @@
1
+ require 'rbconfig'
2
+ require 'open3'
3
+
4
+ module VagrantPlugins
5
+ module GoodHosts
6
+ module GoodHosts
7
+
8
+ def getIps
9
+ if Vagrant.has_plugin?("vagrant-hostsupdater")
10
+ @ui.error "The Vagrant plugin vagrant-hostsupdater is installed but is executed always also when is not configured in your Vagrantfile!"
11
+ end
12
+
13
+ ips = []
14
+
15
+ @machine.config.vm.networks.each do |network|
16
+ key, options = network[0], network[1]
17
+ ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
18
+ ips.push(ip) if ip
19
+ if options[:goodhosts] == 'skip'
20
+ @ui.info '[vagrant-goodhosts] Skipping adding host entries (config.vm.network goodhosts: "skip" is set)'
21
+ end
22
+
23
+ @machine.config.vm.provider :hyperv do |v|
24
+ timeout = @machine.provider_config.ip_address_timeout
25
+ @ui.output("Waiting for the machine to report its IP address(might take some time, have a patience)...")
26
+ @ui.detail("Timeout: #{timeout} seconds")
27
+
28
+ options = {
29
+ vmm_server_address: @machine.provider_config.vmm_server_address,
30
+ proxy_server_address: @machine.provider_config.proxy_server_address,
31
+ timeout: timeout,
32
+ machine: @machine
33
+ }
34
+ network = @machine.provider.driver.read_guest_ip(options)
35
+ if network["ip"]
36
+ ips.push( network["ip"] ) unless ips.include? network["ip"]
37
+ end
38
+ end
39
+
40
+ return ips
41
+ end
42
+ end
43
+
44
+ # https://stackoverflow.com/a/13586108/1902215
45
+ def get_OS
46
+ return os ||= (
47
+ host_os = RbConfig::CONFIG['host_os']
48
+ case host_os
49
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
50
+ :'cli.exe'
51
+ when /darwin|mac os/
52
+ :'cli_osx'
53
+ when /linux/
54
+ :'cli'
55
+ else
56
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
57
+ end
58
+ )
59
+ end
60
+
61
+ def get_cli
62
+ cli = get_OS
63
+ path = File.expand_path(File.dirname(File.dirname(__FILE__))) + '/vagrant-goodhosts/bundle/'
64
+ path = "#{path}#{cli}"
65
+
66
+ return path
67
+ end
68
+
69
+ # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
70
+ def getHostnames(ips)
71
+ hostnames = Hash.new { |h, k| h[k] = [] }
72
+
73
+ case @machine.config.goodhosts.aliases
74
+ when Array
75
+ # simple list of aliases to link to all ips
76
+ ips.each do |ip|
77
+ hostnames[ip] += @machine.config.goodhosts.aliases
78
+ end
79
+ when Hash
80
+ # complex definition of aliases for various ips
81
+ @machine.config.goodhosts.aliases.each do |ip, hosts|
82
+ hostnames[ip] += Array(hosts)
83
+ end
84
+ end
85
+
86
+ # handle default hostname(s) if not already specified in the aliases
87
+ Array(@machine.config.vm.hostname).each do |host|
88
+ if hostnames.none? { |k, v| v.include?(host) }
89
+ ips.each do |ip|
90
+ hostnames[ip].unshift host
91
+ end
92
+ end
93
+ end
94
+
95
+ return hostnames
96
+ end
97
+
98
+ def addHostEntries
99
+ ips = getIps
100
+ hostnames = getHostnames(ips)
101
+ error = false
102
+ errorText = ""
103
+ cli = get_cli
104
+ ips.each do |ip|
105
+ hostnames[ip].each do |hostname|
106
+ ip_address = ip
107
+ if !ip_address.nil?
108
+ @ui.info "[vagrant-goodhosts] found entry for: #{ip_address} #{hostname}"
109
+ if cli.include? ".exe"
110
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "a", ip_address, hostname)
111
+ else
112
+ stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "a", ip_address, hostname)
113
+ end
114
+ if !wait_thr.value.success?
115
+ error = true
116
+ errorText = stderr.read.strip
117
+ end
118
+ end
119
+ end
120
+ end
121
+ printReadme(error, errorText)
122
+ end
123
+
124
+ def removeHostEntries
125
+ ips = getIps
126
+ hostnames = getHostnames(ips)
127
+ error = false
128
+ errorText = ""
129
+ cli = get_cli
130
+ ips.each do |ip|
131
+ hostnames[ip].each do |hostname|
132
+ ip_address = ip
133
+ if !ip_address.nil?
134
+ @ui.info "[vagrant-goodhosts] remove entry for: #{ip_address} #{hostname}"
135
+ if cli.include? ".exe"
136
+ stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "r", ip_address, hostname)
137
+ else
138
+ stdin, stdout, stderr, wait_thr = Open3.popen3('sudo', cli, "r", ip_address, hostname)
139
+ end
140
+ if !wait_thr.value.success?
141
+ error = true
142
+ errorText = stderr.read.strip
143
+ end
144
+ end
145
+ end
146
+ end
147
+ printReadme(error, errorText)
148
+ end
149
+
150
+ def printReadme(error, errorText)
151
+ if error
152
+ cli = get_cli
153
+ @ui.error "[vagrant-goodhosts] Issue on executing goodhosts: #{errorText}"
154
+ @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
155
+ @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/Mte90/vagrant-goodhosts#passwordless-sudo"
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,10 @@
1
+ module VagrantPlugins
2
+ module GoodHosts
3
+ class Command < Vagrant.plugin('2', :command)
4
+
5
+ def execute
6
+ puts "ran command"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GoodHosts
5
+ class Config < Vagrant.plugin("2", :config)
6
+ attr_accessor :aliases
7
+ attr_accessor :id
8
+ attr_accessor :remove_on_suspend
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,54 @@
1
+ require "vagrant-goodhosts/Action/UpdateHosts"
2
+ require "vagrant-goodhosts/Action/RemoveHosts"
3
+
4
+ module VagrantPlugins
5
+ module GoodHosts
6
+ class Plugin < Vagrant.plugin('2')
7
+ name 'GoodHosts'
8
+ description <<-DESC
9
+ This plugin manages the /etc/hosts file for the host machine. An entry is
10
+ created for the hostname attribute in the vm.config.
11
+ DESC
12
+
13
+ config(:goodhosts) do
14
+ require_relative 'config'
15
+ Config
16
+ end
17
+
18
+ action_hook(:goodhosts, :machine_action_up) do |hook|
19
+ hook.append(Action::UpdateHosts)
20
+ end
21
+
22
+ action_hook(:goodhosts, :machine_action_provision) do |hook|
23
+ hook.before(Vagrant::Action::Builtin::Provision, Action::UpdateHosts)
24
+ end
25
+
26
+ action_hook(:goodhosts, :machine_action_halt) do |hook|
27
+ hook.append(Action::RemoveHosts)
28
+ end
29
+
30
+ action_hook(:goodhosts, :machine_action_suspend) do |hook|
31
+ hook.append(Action::RemoveHosts)
32
+ end
33
+
34
+ action_hook(:goodhosts, :machine_action_destroy) do |hook|
35
+ hook.append(Action::RemoveHosts)
36
+ end
37
+
38
+ action_hook(:goodhosts, :machine_action_reload) do |hook|
39
+ hook.prepend(Action::RemoveHosts)
40
+ hook.append(Action::UpdateHosts)
41
+ end
42
+
43
+ action_hook(:goodhosts, :machine_action_resume) do |hook|
44
+ hook.prepend(Action::RemoveHosts)
45
+ hook.append(Action::UpdateHosts)
46
+ end
47
+
48
+ command(:goodhosts) do
49
+ require_relative 'command'
50
+ Command
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module GoodHosts
3
+ VERSION = '1.0.0-beta4'
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+
3
+ mkdir -p ./lib/vagrant-goodhosts/bundle
4
+ cd ./lib/vagrant-goodhosts/bundle
5
+ # Download
6
+ curl -s https://api.github.com/repos/goodhosts/cli/releases/latest | jq --raw-output '.assets[] | .browser_download_url' | xargs wget -i
7
+ # Extract
8
+ tar -zxvf goodhosts_darwin_amd64.tar.gz goodhosts && mv goodhosts cli_osx
9
+ tar -zxvf goodhosts_linux_amd64.tar.gz goodhosts && mv goodhosts cli
10
+ tar -zxvf goodhosts_windows_amd64.tar.gz goodhosts.exe && mv goodhosts.exe cli.exe
11
+ rm -f ./*.tar.gz
12
+ rm -f ./*.txt
13
+ # Generate
14
+ cd ../../../
15
+ gem build vagrant-goodhosts.gemspec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-goodhosts/version'
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/mte90/vagrant-goodhosts'
14
+ spec.license = 'MIT'
15
+
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']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-goodhosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.beta4
5
+ platform: ruby
6
+ authors:
7
+ - Daniele Scasciafratte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Enables Vagrant to update hosts file on the host machine with goodhosts
42
+ email:
43
+ - mte90net@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/vagrant-goodhosts.rb
54
+ - lib/vagrant-goodhosts/Action/RemoveHosts.rb
55
+ - lib/vagrant-goodhosts/Action/UpdateHosts.rb
56
+ - lib/vagrant-goodhosts/GoodHosts.rb
57
+ - lib/vagrant-goodhosts/bundle/cli
58
+ - lib/vagrant-goodhosts/bundle/cli.exe
59
+ - lib/vagrant-goodhosts/bundle/cli_osx
60
+ - lib/vagrant-goodhosts/command.rb
61
+ - lib/vagrant-goodhosts/config.rb
62
+ - lib/vagrant-goodhosts/plugin.rb
63
+ - lib/vagrant-goodhosts/version.rb
64
+ - package.sh
65
+ - vagrant-goodhosts.gemspec
66
+ homepage: https://github.com/mte90/vagrant-goodhosts
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.1
84
+ requirements: []
85
+ rubygems_version: 3.1.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Enables Vagrant to update hosts file on the host machine with goodhosts
89
+ test_files: []