vagrant-goodhosts 1.0.19 → 1.1.0beta

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: 9df62f1e1e6994b0e268f5a4c70e05992d2aa8717359bc843468f7fe209d735c
4
- data.tar.gz: 5de2dbc4f9eefe5dddfed6a74c8db799b9cf5fd8003d111ea5d47e6bb07d68d3
3
+ metadata.gz: 0f6a0225da423c0c803dacaeb97182e8768510d601db33c182a088733d282f60
4
+ data.tar.gz: f2756ce326a5d766baa4fd63f5d4d158c13fb0591c88a9763dc6e9846b377bbc
5
5
  SHA512:
6
- metadata.gz: a80232c8572f03701db820c2ab9be2e37288ab1fa258381c35843ebfc68c121f844c1765b18c6c743c3f9b0da18014e5bc32d7dde6d3b91d03ed6c2de24cff44
7
- data.tar.gz: 69f5149b8e73aaedabc0c4011bade5b0a12f1cda452603b230fef861e774f2fed5eec14ec311ec6157fa4ec4cdb925d292faaf1bc448e6c9fb6e766bee5aaf7b
6
+ metadata.gz: 11d1c0937d56326ebbd390adc477c8c047b6422f0c81c21ad454d297992876941267102811acbc7e7e32e960a2feb2767d055f086a4461b8f6008cd1b81d0581
7
+ data.tar.gz: 528d8f7ff5b81d8a377530a628710ef62ae4432790099f3c8a4673c01e2c3d1ef4032181680e63bc5cd49f8925d01374ed3d8ae919a09bd2849ad0def44022d2
@@ -0,0 +1,15 @@
1
+ name: Linters
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v1
10
+ - name: RuboCop Linter
11
+ uses: andrewmcodes/rubocop-linter-action@v3.3.0
12
+ with:
13
+ exit_on_failure: true
14
+ env:
15
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
data/.rubocop.yml ADDED
@@ -0,0 +1,68 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'Gemfile'
4
+ - 'Rakefile'
5
+ - 'lib/vagrant-goodhosts/config.rb'
6
+
7
+ Naming/FileName:
8
+ Enabled: false
9
+ Naming/AccessorMethodName:
10
+ Enabled: false
11
+ Metrics/MethodLength:
12
+ Enabled: false
13
+ Metrics/PerceivedComplexity:
14
+ Enabled: false
15
+ Metrics/ModuleLength:
16
+ Enabled: false
17
+ Metrics/CyclomaticComplexity:
18
+ Enabled: false
19
+ Metrics/AbcSize:
20
+ Enabled: false
21
+ Style/FrozenStringLiteralComment:
22
+ Enabled: false
23
+ Style/RaiseArgs:
24
+ Enabled: false
25
+ Layout/LineLength:
26
+ Enabled: false
27
+ Style/StringLiterals:
28
+ Enabled: false
29
+ Style/ExpandPathArguments:
30
+ Enabled: false
31
+ Style/RedundantReturn:
32
+ Enabled: false
33
+ Style/SymbolArray:
34
+ Enabled: false
35
+ Style/ClassVars:
36
+ Enabled: false
37
+ Style/YodaCondition:
38
+ Enabled: false
39
+ Style/MethodCallWithoutArgsParentheses:
40
+ Enabled: false
41
+ Style/NumericPredicate:
42
+ Enabled: false
43
+ Style/ParallelAssignment:
44
+ Enabled: false
45
+ Style/Not:
46
+ Enabled: false
47
+ Style/EmptyLiteral:
48
+ Enabled: false
49
+ Style/IfUnlessModifier:
50
+ Enabled: false
51
+ Style/MutableConstant:
52
+ Enabled: false
53
+ Style/SymbolLiteral:
54
+ Enabled: false
55
+ Style/AccessorGrouping:
56
+ Enabled: false
57
+ Style/Next:
58
+ Enabled: false
59
+ Style/MultipleComparison:
60
+ Enabled: false
61
+ Style/FormatStringToken:
62
+ Enabled: false
63
+ Style/SoleNestedConditional:
64
+ Enabled: false
65
+ Style/GuardClause:
66
+ Enabled: false
67
+ Gemspec/RequiredRubyVersion:
68
+ Enabled: false
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ end
7
7
  group :plugins do
8
8
  gem "vagrant-goodhosts", path: "."
9
9
  end
10
+
11
+ gem 'os'
@@ -1,6 +1,8 @@
1
+ # Action to extend for the plugin needs, detects if it was already executed etc
1
2
  module VagrantPlugins
2
3
  module GoodHosts
3
4
  module Action
5
+ # Extend it!
4
6
  class BaseAction
5
7
  include GoodHosts
6
8
 
@@ -35,10 +37,9 @@ module VagrantPlugins
35
37
  @app.call(env)
36
38
  end
37
39
 
38
- def run(env)
40
+ def run(_env)
39
41
  raise NotImplementedError.new("Must be implemented!")
40
42
  end
41
-
42
43
  end
43
44
  end
44
45
  end
@@ -1,8 +1,9 @@
1
+ # Run when is removing the hosts
1
2
  module VagrantPlugins
2
3
  module GoodHosts
3
4
  module Action
5
+ # Remove hosts
4
6
  class RemoveHosts < BaseAction
5
-
6
7
  def run(env)
7
8
  machine_action = env[:machine_action]
8
9
 
@@ -12,10 +13,9 @@ module VagrantPlugins
12
13
  if ([:halt, :suspend].include? machine_action) && (false == @machine.config.goodhosts.remove_on_suspend)
13
14
  @ui.info "[vagrant-goodhosts] Removing hosts on suspend disabled"
14
15
  else
15
- removeHostEntries
16
+ remove_host_entries
16
17
  end
17
18
  end
18
-
19
19
  end
20
20
  end
21
21
  end
@@ -1,12 +1,12 @@
1
+ # Run when is adding hosts
1
2
  module VagrantPlugins
2
3
  module GoodHosts
3
4
  module Action
5
+ # Update hosts
4
6
  class UpdateHosts < BaseAction
5
-
6
- def run(env)
7
- addHostEntries()
7
+ def run(_env)
8
+ add_host_entries()
8
9
  end
9
-
10
10
  end
11
11
  end
12
12
  end
@@ -1,16 +1,19 @@
1
+ # The core of the plugin
1
2
  require "rbconfig"
2
3
  require "open3"
3
4
  require "resolv"
5
+ require "os"
4
6
 
5
7
  module VagrantPlugins
6
8
  module GoodHosts
9
+ # Plugin module
7
10
  module GoodHosts
8
- def getIps
11
+ def get_ips
9
12
  ips = []
10
13
 
11
- if @machine.config.vm.networks.length == 0
12
- @ui.error("[vagrant-goodhosts] No networks are available yet for this virtual machine to add IP/hosts for")
13
- return ips
14
+ if @machine.config.vm.networks.empty?
15
+ @ui.error("[vagrant-goodhosts] No networks are available yet for this virtual machine to add IP/hosts for")
16
+ return ips
14
17
  end
15
18
 
16
19
  @machine.config.vm.networks.each do |network|
@@ -21,7 +24,7 @@ module VagrantPlugins
21
24
  ip = options[:ip] if (key == :private_network || key == :public_network) && options[:goodhosts] != "skip"
22
25
  ips.push(ip) if ip
23
26
 
24
- @machine.config.vm.provider :hyperv do |v|
27
+ @machine.config.vm.provider :hyperv do
25
28
  timeout = @machine.provider_config.ip_address_timeout
26
29
  @ui.output("[vagrant-goodhosts] Waiting for the guest machine to report its IP address ( this might take some time, have patience )...")
27
30
  @ui.detail("Timeout: #{timeout} seconds")
@@ -30,43 +33,39 @@ module VagrantPlugins
30
33
  vmm_server_address: @machine.provider_config.vmm_server_address,
31
34
  proxy_server_address: @machine.provider_config.proxy_server_address,
32
35
  timeout: timeout,
33
- machine: @machine,
36
+ machine: @machine
34
37
  }
35
38
  network = @machine.provider.driver.read_guest_ip(options)
36
39
  if network["ip"]
37
40
  ips.push(network["ip"]) unless ips.include? network["ip"]
38
41
  end
39
42
  end
40
-
41
43
  end
42
44
  return ips
43
45
  end
44
46
 
45
- # https://stackoverflow.com/a/13586108/1902215
46
47
  def get_os_binary
47
- return os ||= (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)
48
+ if OS.windows?
49
+ return 'cli.exe'
50
+ elsif OS.mac?
51
+ return 'cli_osx'
52
+ elsif OS.linux?
53
+ return 'cli'
54
+ else
55
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
56
+ end
58
57
  end
59
58
 
60
59
  def get_cli
61
60
  binary = get_os_binary
62
- path = File.expand_path(File.dirname(File.dirname(__FILE__))) + "/vagrant-goodhosts/bundle/"
61
+ path = format('%s%s', File.expand_path(File.dirname(File.dirname(__FILE__))), "/vagrant-goodhosts/bundle/")
63
62
  path = "#{path}#{binary}"
64
63
 
65
64
  return path
66
65
  end
67
66
 
68
67
  # Get a hash of hostnames indexed by ip, e.g. { 'ip1': ['host1'], 'ip2': ['host2', 'host3'] }
69
- def getHostnames(ips)
68
+ def get_hostnames(ips)
70
69
  hostnames = Hash.new { |h, k| h[k] = [] }
71
70
 
72
71
  case @machine.config.goodhosts.aliases
@@ -85,54 +84,53 @@ module VagrantPlugins
85
84
  return hostnames
86
85
  end
87
86
 
88
- def disableClean(ip_address)
87
+ def disable_clean(ip_address)
89
88
  unless ip_address.nil?
90
89
  return @machine.config.goodhosts.disable_clean
91
90
  end
91
+
92
92
  return true
93
93
  end
94
94
 
95
- def checkHostnamesToAdd(ip_address, hostnames)
95
+ def check_hostnames_to_add(ip_address, hostnames)
96
96
  hostnames_to_add = Array.new
97
97
  hostnames = hostnames.split
98
98
  # check which hostnames actually need adding
99
99
  hostnames.each do |hostname|
100
- begin
101
- address = Resolv.getaddress(hostname)
102
- if address != ip_address
103
- hostnames_to_add.append( hostname )
104
- end
105
- rescue => exception
100
+ address = Resolv.getaddress(hostname)
101
+ if address != ip_address
106
102
  hostnames_to_add.append(hostname)
107
103
  end
104
+ rescue StandardError => _e
105
+ hostnames_to_add.append(hostname)
108
106
  end
109
107
  return hostnames_to_add
110
108
  end
111
109
 
112
- def addGoodhostEntries(ip_address, hostnames)
110
+ def add_goodhost_entries(ip_address, hostnames)
111
+ cli = get_cli
113
112
  if cli.include? ".exe"
114
113
  clean = "\"--clean\","
115
- if disableClean(ip_address)
116
- clean = ''
114
+ if disable_clean(ip_address)
115
+ clean = ''
117
116
  end
118
117
  stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"add\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
119
118
  else
120
119
  clean = "--clean"
121
- if disableClean(ip_address)
122
- clean = ''
120
+ if disable_clean(ip_address)
121
+ clean = ''
123
122
  end
124
123
  stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' add #{clean} #{ip_address} #{hostnames}")
125
124
  end
126
125
  return stdin, stdout, stderr, wait_thr
127
126
  end
128
127
 
129
- def addHostEntries
128
+ def add_host_entries
130
129
  error = false
131
- errorText = ""
132
- cli = get_cli
133
- hostnames_by_ips = generateHostnamesByIps
130
+ error_text = ""
131
+ hostnames_by_ips = generate_hostnames_by_ips
134
132
 
135
- return if not hostnames_by_ips.any?
133
+ return if hostnames_by_ips.none?
136
134
 
137
135
  @ui.info "[vagrant-goodhosts] Checking for host entries"
138
136
 
@@ -143,42 +141,38 @@ module VagrantPlugins
143
141
  end
144
142
 
145
143
  # filter out the hosts we've already added
146
- hosts_to_add = checkHostnamesToAdd(ip_address, hostnames)
147
- next if not hosts_to_add.any?
144
+ hosts_to_add = check_hostnames_to_add(ip_address, hostnames)
145
+ next if hosts_to_add.none?
148
146
 
149
- stdin, stdout, stderr, wait_thr = addGoodhostEntries(ip_address, hosts_to_add)
150
- if !wait_thr.value.success?
147
+ _stdin, _stdout, stderr, wait_thr = add_goodhost_entries(ip_address, hosts_to_add)
148
+ unless wait_thr.value.success?
151
149
  error = true
152
- errorText = stderr.read.strip
150
+ error_text = stderr.read.strip
153
151
  end
154
152
  end
155
- printReadme(error, errorText)
153
+ print_readme(error, error_text)
156
154
  end
157
155
 
158
- def removeGoodhostEntries(ip_address, hostnames)
156
+ def remove_goodhost_entries(ip_address, hostnames)
157
+ cli = get_cli
158
+ clean = "\"--clean\","
159
+ if disable_clean(ip_address)
160
+ clean = ''
161
+ end
159
162
  if cli.include? ".exe"
160
- clean = "\"--clean\","
161
- if disableClean(ip_address)
162
- clean = ''
163
- end
164
163
  stdin, stdout, stderr, wait_thr = Open3.popen3("powershell", "-Command", "Start-Process '#{cli}' -ArgumentList \"remove\",#{clean}\"#{ip_address}\",\"#{hostnames}\" -Verb RunAs")
165
164
  else
166
- clean = "\"--clean\","
167
- if disableClean(ip_address)
168
- clean = ''
169
- end
170
165
  stdin, stdout, stderr, wait_thr = Open3.popen3("sudo '#{cli}' remove #{clean} #{ip_address} #{hostnames}")
171
166
  end
172
167
  return stdin, stdout, stderr, wait_thr
173
168
  end
174
169
 
175
- def removeHostEntries
170
+ def remove_host_entries
176
171
  error = false
177
- errorText = ""
178
- cli = get_cli
179
- hostnames_by_ips = generateHostnamesByIps
172
+ error_text = ""
173
+ hostnames_by_ips = generate_hostnames_by_ips
180
174
 
181
- return if not hostnames_by_ips.any?
175
+ return if hostnames_by_ips.none?
182
176
 
183
177
  @ui.info "[vagrant-goodhosts] Removing hosts"
184
178
 
@@ -188,43 +182,45 @@ module VagrantPlugins
188
182
  next
189
183
  end
190
184
 
191
- stdin, stdout, stderr, wait_thr = removeGoodhostEntries(ip_address, hostnames)
192
- if !wait_thr.value.success?
185
+ _stdin, _stdout, stderr, wait_thr = remove_goodhost_entries(ip_address, hostnames)
186
+ unless wait_thr.value.success?
193
187
  error = true
194
- errorText = stderr.read.strip
188
+ error_text = stderr.read.strip
195
189
  end
196
190
  end
197
- printReadme(error, errorText)
191
+ print_readme(error, error_text)
198
192
  end
199
193
 
200
- def printReadme(error, errorText)
201
- if error
202
- cli = get_cli
203
- @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{errorText}"
204
- @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
205
- if cli.include? ".exe"
206
- @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
207
- exit
208
- else
209
- @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#passwordless-sudo"
210
- end
194
+ def print_readme(error, error_text)
195
+ unless error
196
+ return false
197
+ end
198
+
199
+ cli = get_cli
200
+ @ui.error "[vagrant-goodhosts] Issue executing goodhosts CLI: #{error_text}"
201
+ @ui.error "[vagrant-goodhosts] Cli path: #{cli}"
202
+ if cli.include? ".exe"
203
+ @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#windows-uac-prompt"
204
+ exit
205
+ else
206
+ @ui.error "[vagrant-goodhosts] Check the readme at https://github.com/goodhosts/vagrant#passwordless-sudo"
211
207
  end
212
208
  end
213
209
 
214
- def generateHostnamesByIps()
210
+ def generate_hostnames_by_ips
215
211
  hostnames_by_ips = []
216
- ips = getIps
212
+ ips = get_ips
217
213
  if ips.count() < 1
218
214
  @ui.error("[vagrant-goodhosts] No ip address found for this virtual machine")
219
215
  return hostnames_by_ips
220
216
  end
221
- hostnames = getHostnames(ips)
217
+ hostnames = get_hostnames(ips)
222
218
  if ips.count() > 1
223
219
  ips.each do |ip|
224
220
  ip_address = ip
225
221
  if hostnames[ip].count() > 0
226
222
  hostnames[ip].each do |hostname|
227
- if !ip_address.nil?
223
+ unless ip_address.nil?
228
224
  @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
229
225
  end
230
226
  end
@@ -235,7 +231,7 @@ module VagrantPlugins
235
231
  ip_address = ips[0]
236
232
  if hostnames[ip_address].count() > 0
237
233
  hostnames[ip_address].each do |hostname|
238
- if !ip_address.nil?
234
+ unless ip_address.nil?
239
235
  @ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
240
236
  end
241
237
  end
@@ -2,16 +2,17 @@ require "vagrant"
2
2
 
3
3
  module VagrantPlugins
4
4
  module GoodHosts
5
+ # Vagrant plugin definition
5
6
  class Config < Vagrant.plugin("2", :config)
6
- attr_accessor :aliases
7
- attr_accessor :id
8
- attr_accessor :remove_on_suspend
9
- attr_accessor :disable_clean
10
-
11
- def initialize
12
- @remove_on_suspend = true
13
- @disable_clean = true
14
- end
7
+ attr_accessor :aliases
8
+ attr_accessor :id
9
+ attr_accessor :remove_on_suspend
10
+ attr_accessor :disable_clean
11
+
12
+ def initialize
13
+ @remove_on_suspend = true
14
+ @disable_clean = true
15
+ end
15
16
  end
16
17
  end
17
18
  end
@@ -5,6 +5,7 @@ require_relative "Action/RemoveHosts"
5
5
 
6
6
  module VagrantPlugins
7
7
  module GoodHosts
8
+ # Various Vagrant hooks
8
9
  class Plugin < Vagrant.plugin('2')
9
10
  name 'GoodHosts'
10
11
  description <<-DESC
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module GoodHosts
3
- VERSION = '1.0.19'
3
+ VERSION = '1.1.0beta'
4
4
  end
5
5
  end
@@ -1,11 +1,13 @@
1
+ # Root file of the plugin
1
2
  require "vagrant-goodhosts/version"
2
3
  require "vagrant-goodhosts/plugin"
3
4
 
5
+ # Extend Vagrant Plugins
4
6
  module VagrantPlugins
7
+ # Load our plugin
5
8
  module GoodHosts
6
9
  def self.source_root
7
10
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
8
11
  end
9
12
  end
10
13
  end
11
-
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'vagrant-goodhosts/version'
@@ -14,7 +13,7 @@ Gem::Specification.new do |s|
14
13
  s.homepage = 'https://github.com/goodhosts/vagrant'
15
14
  s.license = 'MIT'
16
15
 
17
- s.files = `git ls-files`.split($/)
16
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
17
  s.files += Dir.glob("lib/vagrant-goodhosts/bundle/*")
19
18
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -22,4 +21,6 @@ Gem::Specification.new do |s|
22
21
 
23
22
  s.add_development_dependency 'bundler', '~> 1.3'
24
23
  s.add_development_dependency 'rake'
24
+
25
+ s.add_runtime_dependency "os"
25
26
  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.19
4
+ version: 1.1.0beta
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-10-12 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: os
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Enables Vagrant to update hosts file on the host machine with goodhosts
42
56
  email:
43
57
  - mte90net@gmail.com
@@ -45,7 +59,9 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
62
+ - ".github/workflows/default.yml"
48
63
  - ".gitignore"
64
+ - ".rubocop.yml"
49
65
  - Gemfile
50
66
  - LICENSE.txt
51
67
  - README.md
@@ -78,9 +94,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
94
  version: '0'
79
95
  required_rubygems_version: !ruby/object:Gem::Requirement
80
96
  requirements:
81
- - - ">="
97
+ - - ">"
82
98
  - !ruby/object:Gem::Version
83
- version: '0'
99
+ version: 1.3.1
84
100
  requirements: []
85
101
  rubygems_version: 3.2.27
86
102
  signing_key: