vagrant-proxyconf 1.5.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +11 -14
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +28 -7
  6. data/LICENSE.txt +1 -1
  7. data/README.md +147 -18
  8. data/Rakefile +1 -27
  9. data/development/Dockerfile +45 -0
  10. data/development/README.md +2 -0
  11. data/development/Vagrantfile.example +185 -9
  12. data/development/install-c7.sh +46 -0
  13. data/development/install-debian.sh +55 -0
  14. data/development/tinyproxy.conf +333 -0
  15. data/lib/vagrant-proxyconf/action.rb +15 -7
  16. data/lib/vagrant-proxyconf/action/base.rb +47 -5
  17. data/lib/vagrant-proxyconf/action/configure_apt_proxy.rb +17 -0
  18. data/lib/vagrant-proxyconf/action/configure_chef_proxy.rb +32 -27
  19. data/lib/vagrant-proxyconf/action/configure_docker_proxy.rb +132 -14
  20. data/lib/vagrant-proxyconf/action/configure_env_proxy.rb +58 -11
  21. data/lib/vagrant-proxyconf/action/configure_git_proxy.rb +25 -9
  22. data/lib/vagrant-proxyconf/action/configure_npm_proxy.rb +14 -6
  23. data/lib/vagrant-proxyconf/action/configure_pear_proxy.rb +15 -8
  24. data/lib/vagrant-proxyconf/action/configure_svn_proxy.rb +15 -8
  25. data/lib/vagrant-proxyconf/action/configure_yum_proxy.rb +16 -0
  26. data/lib/vagrant-proxyconf/action/is_enabled.rb +18 -1
  27. data/lib/vagrant-proxyconf/cap/linux/chef_proxy_conf.rb +17 -0
  28. data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
  29. data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
  30. data/lib/vagrant-proxyconf/cap/util.rb +4 -5
  31. data/lib/vagrant-proxyconf/capability.rb +10 -0
  32. data/lib/vagrant-proxyconf/config.rb +20 -0
  33. data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
  34. data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
  35. data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
  36. data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
  37. data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
  38. data/lib/vagrant-proxyconf/version.rb +1 -1
  39. data/locales/en.yml +38 -0
  40. data/resources/yum_config.awk +1 -0
  41. data/spec/spec_helper.rb +27 -9
  42. data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
  43. data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
  44. data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
  45. data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
  46. data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
  47. data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
  48. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
  49. data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +491 -0
  50. data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
  51. data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
  52. data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
  53. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
  54. data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
  55. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
  56. data/spec/unit/vagrant-proxyconf/action/is_enabled_spec.rb +162 -12
  57. data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
  58. data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
  59. data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
  60. data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
  61. data/test/issues/180/.rspec +2 -0
  62. data/test/issues/180/Dockerfile +47 -0
  63. data/test/issues/180/README.md +31 -0
  64. data/test/issues/180/Rakefile +27 -0
  65. data/test/issues/180/Vagrantfile +31 -0
  66. data/test/issues/180/entrypoint.sh +50 -0
  67. data/test/issues/180/spec/default/redhat_spec.rb +15 -0
  68. data/test/issues/180/spec/docker_host/redhat_spec.rb +165 -0
  69. data/test/issues/180/spec/spec_helper.rb +43 -0
  70. data/test/issues/180/tinyproxy.conf +333 -0
  71. data/travis/before_install +26 -0
  72. metadata +44 -4
@@ -31,13 +31,16 @@ module VagrantPlugins
31
31
  def self.configure_after_provisoner
32
32
  Vagrant::Action::Builder.new.tap do |b|
33
33
  b.use Builtin::Call, IsEnabled do |env, b2|
34
- next if !env[:result]
34
+ # next if !env[:result]
35
35
 
36
- b2.use ConfigureDockerProxy
37
- b2.use ConfigureGitProxy
38
- b2.use ConfigureNpmProxy
39
- b2.use ConfigurePearProxy
40
- b2.use ConfigureSvnProxy
36
+ # TODO: Do we really need to configure only specific proxies after the provisioner runs?
37
+ # Shouldn't they already be configured by this point?
38
+ # Cody Lane - Dec 2018
39
+ # b2.use ConfigureDockerProxy
40
+ # b2.use ConfigureGitProxy
41
+ # b2.use ConfigureNpmProxy
42
+ # b2.use ConfigurePearProxy
43
+ # b2.use ConfigureSvnProxy
41
44
  end
42
45
  end
43
46
  end
@@ -49,8 +52,13 @@ module VagrantPlugins
49
52
  def self.config_actions
50
53
  @config_actions ||= Proc.new do |b|
51
54
  b.use Builtin::Call, IsEnabled do |env, b2|
52
- next if !env[:result]
55
+ # next if !env[:result]
53
56
 
57
+ # IsEnabled doesn't seem to be quiet right becuse it only seems to check if the proxy has been disabled
58
+ # globally which isn't always what we want. We don't want to skip configuring a service or services
59
+ # because of a disable toggle. Instead we defer to each action class because the implementation for
60
+ # skipping over a service or checking if it is disabled is implmeneted there. To be more clear the real
61
+ # implementation is actually in action/base.rb#call
54
62
  b2.use ConfigureAptProxy
55
63
  b2.use ConfigureChefProxy
56
64
  b2.use ConfigureDockerProxy
@@ -14,10 +14,15 @@ module VagrantPlugins
14
14
  def call(env)
15
15
  @machine = env[:machine]
16
16
 
17
- if disabled? || !config.enabled?
18
- logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_enabled")
17
+ if skip?
18
+ logger.info I18n.t("vagrant_proxyconf.#{config_name}.skip")
19
+ env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.skip")
19
20
  elsif !supported?
20
21
  logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
22
+ elsif disabled?
23
+ logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_enabled")
24
+ env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.unconfiguring") if supported?
25
+ unconfigure_machine
21
26
  else
22
27
  env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.configuring")
23
28
  configure_machine
@@ -66,6 +71,10 @@ module VagrantPlugins
66
71
  write_config(config)
67
72
  end
68
73
 
74
+ # Unconfigures the VM, expected to be added to overriden
75
+ def unconfigure_machine
76
+ end
77
+
69
78
  # Writes the config to the VM
70
79
  #
71
80
  # @param opts [Hash] optional file options
@@ -109,16 +118,49 @@ module VagrantPlugins
109
118
  def disabled?
110
119
  enabled = @machine.config.proxy.enabled
111
120
  return true if enabled == false || enabled == ''
121
+ return false if enabled == true
122
+
123
+ app_name = config_name.gsub(/_proxy/, '').to_sym
124
+
125
+ if enabled.respond_to?(:key)
126
+ return false if enabled.has_key?(app_name) == false
127
+
128
+ # if boolean value, return original behavior as mentioned in Readme
129
+ return enabled[app_name] == false if [true, false].include?(enabled[app_name])
130
+
131
+ return false if enabled[app_name].has_key?(:skip) == false
132
+
133
+ # otherwise assume new behavior using :enabled as a new hash key
134
+ return enabled[app_name][:enabled] == false
135
+ end
136
+
137
+ false
138
+ end
139
+
140
+ def skip?
141
+ enabled = @machine.config.proxy.enabled
142
+ return true if enabled == false || enabled == ''
143
+ return false if enabled == true
112
144
 
113
145
  app_name = config_name.gsub(/_proxy/, '').to_sym
114
- return enabled[app_name] == false if enabled.respond_to?(:key)
146
+
147
+ if enabled.respond_to?(:key)
148
+ return false if enabled.has_key?(app_name) == false
149
+
150
+ # if boolean value, return original behavior as mentioned in Readme
151
+ return enabled[app_name] == false if [true, false].include?(enabled[app_name])
152
+
153
+ return false if enabled[app_name].has_key?(:skip) == false
154
+
155
+ # otherwise assume new behavior using :enabled as a new hash key
156
+ return enabled[app_name][:skip] == true
157
+ end
115
158
 
116
159
  false
117
160
  end
118
161
 
119
162
  def supported?
120
- @machine.guest.capability?(cap_name) &&
121
- @machine.guest.capability(cap_name)
163
+ @machine.guest.capability?(cap_name) && @machine.guest.capability(cap_name)
122
164
  end
123
165
 
124
166
  def config_path
@@ -8,6 +8,23 @@ module VagrantPlugins
8
8
  def config_name
9
9
  'apt_proxy'
10
10
  end
11
+
12
+ private
13
+
14
+ def unconfigure_machine
15
+ if !supported?
16
+ logger.info "apt_proxy is not supported on '#{@machine.guest.name}'"
17
+ return false
18
+ end
19
+
20
+ logger.info "apt_proxy is supported on '#{@machine.guest.name}'"
21
+
22
+ # if we get here then machine should support unconfiguring
23
+ @machine.communicate.sudo("rm -f #{config_path}")
24
+
25
+ true
26
+ end
27
+
11
28
  end
12
29
  end
13
30
  end
@@ -1,48 +1,34 @@
1
1
  require_relative '../logger'
2
2
  require_relative '../userinfo_uri'
3
+ require_relative 'base'
3
4
 
4
5
  module VagrantPlugins
5
6
  module ProxyConf
6
7
  class Action
7
8
  # Action for configuring Chef provisioners
8
- class ConfigureChefProxy
9
+ class ConfigureChefProxy < Base
9
10
 
10
11
  # Array of Chef provisioner types which include proxy configuration
11
12
  CHEF_PROVISIONER_TYPES = [:chef_client, :chef_solo, :chef_zero]
12
13
 
13
- def initialize(app, env)
14
- @app = app
14
+ def config_name
15
+ 'chef_proxy'
15
16
  end
16
17
 
17
- def call(env)
18
- @machine = env[:machine]
19
-
20
- if chef_provisioners.empty?
21
- logger.info I18n.t("vagrant_proxyconf.chef_proxy.no_provisioners")
22
- elsif !config.enabled?
23
- logger.info I18n.t("vagrant_proxyconf.chef_proxy.not_enabled")
24
- else
25
- env[:ui].info I18n.t("vagrant_proxyconf.chef_proxy.configuring")
26
- configure_chef_provisioners
27
- end
18
+ private
28
19
 
29
- @app.call env
20
+ def configure_machine
21
+ configure_chef_provisioners
30
22
  end
31
23
 
32
- private
24
+ def unconfigure_machine
25
+ configure_chef_provisioners
33
26
 
34
- # @return [Log4r::Logger]
35
- def logger
36
- ProxyConf.logger
27
+ true
37
28
  end
38
29
 
39
- # @return [Config::Proxy] the `config.proxy` configuration
40
- def config
41
- return @config if @config
42
-
43
- config = @machine.config.proxy
44
- config.finalize! if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new('1.2.5')
45
- @config = config
30
+ def supported?
31
+ super && !chef_provisioners.empty?
46
32
  end
47
33
 
48
34
  # @return [Array] all Chef provisioners
@@ -67,6 +53,14 @@ module VagrantPlugins
67
53
  #
68
54
  # @param chef [VagrantPlugins::Chef::Config::Base] the Chef provisioner configuration
69
55
  def configure_chef(chef)
56
+ if disabled?
57
+ logger.info("chef_proxy is not enabled so we should unconfigure it")
58
+ unconfigure_chef_proxy(chef, 'http')
59
+ unconfigure_chef_proxy(chef, 'https')
60
+ return
61
+ end
62
+
63
+ logger.info("chef_proxy is enabled so we should configure it")
70
64
  configure_chef_proxy(chef, 'http', config.http)
71
65
  configure_chef_proxy(chef, 'https', config.https)
72
66
  chef.no_proxy ||= config.no_proxy if config.no_proxy
@@ -76,13 +70,24 @@ module VagrantPlugins
76
70
  # @param scheme [String] the http protocol (http or https)
77
71
  # @param uri [String] the URI with optional userinfo
78
72
  def configure_chef_proxy(chef, scheme, uri)
79
- if uri && !chef.public_send("#{scheme}_proxy")
73
+ if uri && !chef.public_send("#{scheme}_proxy") && !disabled?
80
74
  u = UserinfoURI.new(uri)
81
75
  chef.public_send("#{scheme}_proxy_user=", u.user)
82
76
  chef.public_send("#{scheme}_proxy_pass=", u.pass)
83
77
  chef.public_send("#{scheme}_proxy=", u.uri)
78
+ logger.info("chef_proxy has been successfully configured")
84
79
  end
85
80
  end
81
+
82
+ # @param chef [VagrantPlugins::Chef::Config::Base] the Chef provisioner configuration
83
+ # @param scheme [String] the http protocol (http or https)
84
+ def unconfigure_chef_proxy(chef, scheme)
85
+ chef.public_send("#{scheme}_proxy_user=", nil)
86
+ chef.public_send("#{scheme}_proxy_pass=", nil)
87
+ chef.public_send("#{scheme}_proxy=", nil)
88
+ chef.no_proxy = nil
89
+ logger.info("chef_proxy has been successfully unconfigured")
90
+ end
86
91
  end
87
92
  end
88
93
  end
@@ -13,15 +13,100 @@ module VagrantPlugins
13
13
 
14
14
  private
15
15
 
16
- def config
17
- # Use global proxy config
18
- @config ||= finalize_config(@machine.config.proxy)
19
- end
20
-
21
16
  def configure_machine
17
+ return if !supported?
18
+
22
19
  logger.info('Writing the proxy configuration to docker config')
23
20
  detect_export
24
21
  write_docker_config
22
+ update_docker_client_config
23
+
24
+ true
25
+ end
26
+
27
+ def unconfigure_machine
28
+ return if !supported?
29
+
30
+ config.http = nil
31
+ config.https = nil
32
+ config.no_proxy = nil
33
+
34
+ write_docker_config
35
+ update_docker_client_config
36
+
37
+ true
38
+ end
39
+
40
+ def docker_client_config_path
41
+ return @docker_client_config_path if @docker_client_config_path
42
+ return if !supports_config_json?
43
+
44
+ @docker_client_config_path = tempfile(Hash.new)
45
+
46
+ @machine.communicate.tap do |comm|
47
+ if comm.test("[ -f /etc/docker/config.json ]")
48
+ logger.info('Downloading file /etc/docker/config.json')
49
+ comm.sudo("chmod 0644 /etc/docker/config.json")
50
+ comm.download("/etc/docker/config.json", @docker_client_config_path.path)
51
+ logger.info("Downloaded /etc/docker/config.json to #{@docker_client_config_path.path}")
52
+ end
53
+ end
54
+
55
+ @docker_client_config_path = @docker_client_config_path.path
56
+ end
57
+
58
+ def update_docker_client_config
59
+ return if !supports_config_json? || !docker_client_config_path
60
+
61
+ content = File.read(@docker_client_config_path)
62
+ data = JSON.load(content)
63
+
64
+ if disabled?
65
+ data['proxies'] = {
66
+ 'default' => {}
67
+ }
68
+ else
69
+
70
+ data['proxies'] = {} unless data.key?('proxies')
71
+ data['proxies']['default'] = {} unless data['proxies'].key?('default')
72
+
73
+ data['proxies']['default'].delete('httpProxy')
74
+ data['proxies']['default'].delete('httpsProxy')
75
+ data['proxies']['default'].delete('noProxy')
76
+
77
+ unless config.http == false || config.http == "" || config.http.nil?
78
+ data['proxies']['default']['httpProxy'] = config.http
79
+ end
80
+
81
+ unless config.https == false || config.https == "" || config.https.nil?
82
+ data['proxies']['default']['httpsProxy'] = config.https
83
+ end
84
+
85
+ unless config.no_proxy == false || config.no_proxy == "" || config.no_proxy.nil?
86
+ data['proxies']['default']['noProxy'] = config.no_proxy
87
+ end
88
+
89
+ end
90
+
91
+ config_json = JSON.pretty_generate(data)
92
+
93
+ @docker_client_config_path = tempfile(config_json)
94
+
95
+ @machine.communicate.tap do |comm|
96
+ comm.upload(@docker_client_config_path.path, "/tmp/vagrant-proxyconf-docker-config.json")
97
+ comm.sudo("mkdir -p /etc/docker")
98
+ comm.sudo("chown root:root /etc/docker")
99
+ comm.sudo("mv /tmp/vagrant-proxyconf-docker-config.json /etc/docker/config.json")
100
+ comm.sudo("chown root:root /etc/docker/config.json")
101
+ comm.sudo("rm -f /tmp/vagrant-proxyconf-docker-config.json")
102
+
103
+ comm.sudo("sed -i.bak -e '/^DOCKER_CONFIG/d' /etc/environment")
104
+ if !disabled?
105
+ comm.sudo("echo DOCKER_CONFIG=/etc/docker >> /etc/environment")
106
+ end
107
+ end
108
+
109
+ config_json
25
110
  end
26
111
 
27
112
  def docker
@@ -32,13 +117,39 @@ module VagrantPlugins
32
117
  end
33
118
  end
34
119
 
120
+ def docker_version
121
+ return if !supported?
122
+ return @version if @version
123
+
124
+ @version = nil
125
+ @machine.communicate.execute('docker --version') do |type, data|
126
+ version = data.sub(',', '').split(' ').select {|i| i.match /^\d+\.\d+/}
127
+ @version = version[0].split(".").map {|i| i.to_i} unless version.empty?
128
+ end
129
+
130
+ return @version
131
+ end
132
+
133
+ def supports_config_json?
134
+ return false if !supported? || !docker_version
135
+
136
+ major, minor, patch = @version
137
+
138
+ # https://docs.docker.com/network/proxy/#configure-the-docker-client
139
+ # if docker version >= 17.07 it supports config.json
140
+ return true if major >= 17 && minor >= 7
141
+
142
+ # docker version < 17.07 so it does not support config.json
143
+ return false
144
+ end
145
+
35
146
  def write_docker_config
36
147
  tmp = "/tmp/vagrant-proxyconf"
37
148
  path = config_path
38
149
 
39
150
  @machine.communicate.tap do |comm|
40
151
  sed_script = docker_sed_script
41
- local_tmp = tempfile(docker_config)
152
+ local_tmp = !disabled? ? tempfile(docker_config) : tempfile("")
42
153
 
43
154
  comm.sudo("rm -f #{tmp}", error_check: false)
44
155
  comm.upload(local_tmp.path, tmp)
@@ -62,31 +173,38 @@ module VagrantPlugins
62
173
 
63
174
  def detect_export
64
175
  @machine.communicate.tap do |comm|
65
- comm.test('which systemctl') ? @export = '' : @export = 'export '
176
+ comm.test('command -v systemctl') ? @export = '' : @export = 'export '
66
177
  end
67
178
  end
68
179
 
69
180
  def service_restart_command
70
- ["systemctl restart #{docker}",
181
+ [
182
+ "kill -HUP `pgrep -f '#{docker}'`",
183
+ "systemctl restart #{docker}",
71
184
  "service #{docker} restart",
72
- "/etc/init.d/#{docker} restart"].join(' || ')
185
+ "/etc/init.d/#{docker} restart",
186
+ ].join(' || ')
73
187
  end
74
188
 
75
189
  def docker_sed_script
76
190
  <<-SED.gsub(/^\s+/, '')
77
191
  /^#{@export}HTTP_PROXY=/ d
78
- /^#{@export}NO_PROXY=/ d
79
192
  /^#{@export}http_proxy=/ d
193
+ /^#{@export}HTTPS_PROXY=/ d
194
+ /^#{@export}https_proxy=/ d
195
+ /^#{@export}NO_PROXY=/ d
80
196
  /^#{@export}no_proxy=/ d
81
197
  SED
82
198
  end
83
199
 
84
200
  def docker_config
85
201
  <<-CONFIG.gsub(/^\s+/, '')
86
- #{@export}HTTP_PROXY=#{config.http || ''}
87
- #{@export}NO_PROXY=#{config.no_proxy || ''}
88
- #{@export}http_proxy=#{config.http || ''}
89
- #{@export}no_proxy=#{config.no_proxy || ''}
202
+ #{@export}HTTP_PROXY=\"#{config.http || ''}\"
203
+ #{@export}http_proxy=\"#{config.http || ''}\"
204
+ #{@export}HTTPS_PROXY=\"#{config.https || ''}\"
205
+ #{@export}https_proxy=\"#{config.https || ''}\"
206
+ #{@export}NO_PROXY=\"#{config.no_proxy || ''}\"
207
+ #{@export}no_proxy=\"#{config.no_proxy || ''}\"
90
208
  CONFIG
91
209
  end
92
210
  end
@@ -23,11 +23,30 @@ module VagrantPlugins
23
23
  end
24
24
  end
25
25
 
26
+ def unconfigure_machine
27
+ if windows_guest?
28
+ raise NotImplementedError, 'Sorry but I do not know how to disable a windows proxy yet, please open a feature request'
29
+ end
30
+
31
+ logger.info('Unconfiguring and or removing proxy configuration files')
32
+ unconfigure_linux
33
+ end
34
+
35
+ def unconfigure_linux
36
+ @machine.communicate.tap do |comm|
37
+ comm.sudo("rm -f /etc/sudoers.d/proxy")
38
+ comm.sudo("rm -f #{config_path}")
39
+ end
40
+
41
+ write_environment_config
42
+ end
43
+
26
44
  def configure_machine_windows
27
45
  set_windows_proxy('http_proxy', config.http)
28
46
  set_windows_proxy('https_proxy', config.https)
29
47
  set_windows_proxy('ftp_proxy', config.ftp)
30
48
  set_windows_proxy('no_proxy', config.no_proxy)
49
+ set_windows_system_proxy(config.http)
31
50
  end
32
51
 
33
52
  def set_windows_proxy(key, value)
@@ -40,6 +59,26 @@ module VagrantPlugins
40
59
  end
41
60
  end
42
61
 
62
+ def set_windows_system_proxy(proxy)
63
+ if proxy
64
+ path = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
65
+
66
+ proxy1 = "cmd.exe /C reg add \"#{path}\" /v ProxyEnable /t REG_DWORD /d 1 /f"
67
+ proxy2 = "cmd.exe /C reg add \"#{path}\" /v ProxyServer /t REG_SZ /d #{config.http.inspect} /f"
68
+ proxy3 = "cmd.exe /C reg add \"#{path}\" /v ProxyOverride /t REG_SZ /d #{config.no_proxy.inspect} /f"
69
+ proxy4 = "cmd.exe /C reg add \"#{path}\" /v AutoDetect /t REG_DWORD /d 0 /f"
70
+
71
+ logger.info('Setting system proxy settings')
72
+
73
+ @machine.communicate.sudo(proxy1)
74
+ @machine.communicate.sudo(proxy2)
75
+ @machine.communicate.sudo(proxy3)
76
+ @machine.communicate.sudo(proxy4)
77
+ else
78
+ logger.info("Not setting system proxy settings")
79
+ end
80
+ end
81
+
43
82
  def windows_guest?
44
83
  @machine.config.vm.guest.eql?(:windows)
45
84
  end
@@ -62,13 +101,15 @@ module VagrantPlugins
62
101
  comm.sudo("rm -f #{tmp}", error_check: false)
63
102
  comm.upload(local_tmp.path, tmp)
64
103
  comm.sudo("touch #{path}")
65
- comm.sudo("sed -e '#{sed_script}' #{path} > #{path}.new")
104
+ comm.sudo("sed -e '#{sed_script}' -e '/^$/d' #{path} > #{path}.new")
66
105
  comm.sudo("cat #{tmp} >> #{path}.new")
67
106
  comm.sudo("chmod 0644 #{path}.new")
68
107
  comm.sudo("chown root:root #{path}.new")
69
108
  comm.sudo("mv -f #{path}.new #{path}")
70
109
  comm.sudo("rm -f #{tmp}")
71
110
  end
111
+
112
+ true
72
113
  end
73
114
 
74
115
  def environment_sed_script
@@ -85,16 +126,22 @@ module VagrantPlugins
85
126
  end
86
127
 
87
128
  def environment_config
88
- <<-CONFIG.gsub(/^\s+/, '')
89
- HTTP_PROXY=#{config.http || ''}
90
- HTTPS_PROXY=#{config.https || ''}
91
- FTP_PROXY=#{config.ftp || ''}
92
- NO_PROXY=#{config.no_proxy || ''}
93
- http_proxy=#{config.http || ''}
94
- https_proxy=#{config.https || ''}
95
- ftp_proxy=#{config.ftp || ''}
96
- no_proxy=#{config.no_proxy || ''}
97
- CONFIG
129
+ return "" if disabled?
130
+
131
+ env_config = Hash.new
132
+ env_config["FTP_PROXY"] = config.ftp if config.ftp
133
+ env_config["HTTP_PROXY"] = config.http if config.http
134
+ env_config["HTTPS_PROXY"] = config.https if config.https
135
+ env_config["NO_PROXY"] = config.no_proxy if config.no_proxy
136
+
137
+ config_items = env_config.map do |k,v|
138
+ <<-CONFIG.gsub(/^\s+/, '')
139
+ #{k.upcase}="#{v}"
140
+ #{k.downcase}="#{v}"
141
+ CONFIG
142
+ end
143
+
144
+ config_items.join("\n")
98
145
  end
99
146
  end
100
147
  end