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
@@ -11,16 +11,9 @@ module VagrantPlugins
11
11
 
12
12
  private
13
13
 
14
- # @return [Vagrant::Plugin::V2::Config] the configuration
15
- def config
16
- return @config if @config
17
-
18
- # Use only `config.git_proxy`, don't merge with the default config
19
- @config = @machine.config.git_proxy
20
- finalize_config(@config)
21
- end
22
-
23
14
  def configure_machine
15
+ return if !supported?
16
+
24
17
  if config.http
25
18
  @machine.communicate.sudo(
26
19
  "#{git_path} config --system http.proxy #{config.http}")
@@ -29,6 +22,29 @@ module VagrantPlugins
29
22
  "#{git_path} config --system --unset-all http.proxy",
30
23
  error_check: false)
31
24
  end
25
+
26
+ if config.https
27
+ @machine.communicate.sudo(
28
+ "#{git_path} config --system https.proxy #{config.https}")
29
+ else
30
+ @machine.communicate.sudo(
31
+ "#{git_path} config --system --unset-all https.proxy",
32
+ error_check: false)
33
+ end
34
+
35
+ true
36
+ end
37
+
38
+ def unconfigure_machine
39
+ return if !supported?
40
+
41
+ # zero out the configuration
42
+ config.http = nil
43
+ config.https = nil
44
+
45
+ configure_machine
46
+
47
+ true
32
48
  end
33
49
 
34
50
  def git_path
@@ -11,18 +11,24 @@ module VagrantPlugins
11
11
 
12
12
  private
13
13
 
14
- # @return [Vagrant::Plugin::V2::Config] the configuration
15
- def config
16
- # Use global proxy config
17
- @config ||= finalize_config(@machine.config.proxy)
18
- end
19
-
20
14
  def configure_machine
21
15
  set_or_delete_proxy('proxy', config.http)
22
16
  set_or_delete_proxy('https-proxy', config.https)
17
+ set_or_delete_proxy('noproxy', config.no_proxy)
18
+ end
19
+
20
+ def unconfigure_machine
21
+ config.http = nil
22
+ config.https = nil
23
+ config.no_proxy = nil
24
+ configure_machine
25
+
26
+ true
23
27
  end
24
28
 
25
29
  def set_or_delete_proxy(key, value)
30
+ return if !supported?
31
+
26
32
  command = "#{npm_path} config --global "
27
33
  if value
28
34
  command << "set #{key} #{escape(value)}"
@@ -34,6 +40,8 @@ module VagrantPlugins
34
40
  @machine.communicate.sudo("#{npm_path} config --global set #{key} foo")
35
41
  end
36
42
  @machine.communicate.sudo(command)
43
+
44
+ true
37
45
  end
38
46
 
39
47
  def npm_path
@@ -11,17 +11,24 @@ module VagrantPlugins
11
11
 
12
12
  private
13
13
 
14
- # @return [Vagrant::Plugin::V2::Config] the configuration
15
- def config
16
- # Use global proxy config
17
- @config ||= finalize_config(@machine.config.proxy)
18
- end
19
-
20
14
  def configure_machine
15
+ return if !supported?
16
+
17
+ config.http = nil if disabled?
21
18
  proxy = config.http || ''
22
19
 
23
- @machine.communicate.sudo(
24
- "#{pear_path} config-set http_proxy #{escape(proxy)} system")
20
+ @machine.communicate.sudo("#{pear_path} config-set http_proxy #{escape(proxy)} system")
21
+
22
+ true
23
+ end
24
+
25
+ def unconfigure_machine
26
+ return if !supported?
27
+
28
+ config.http = nil
29
+ configure_machine
30
+
31
+ true
25
32
  end
26
33
 
27
34
  def pear_path
@@ -12,17 +12,24 @@ module VagrantPlugins
12
12
 
13
13
  private
14
14
 
15
- # @return [Vagrant::Plugin::V2::Config] the configuration
16
- def config
17
- return @config if @config
15
+ def configure_machine
16
+ return if !supported?
17
+
18
+ write_config(svn_config, path: '/etc/subversion/servers')
18
19
 
19
- # Use only `config.svn_proxy`, don't merge with the default config
20
- @config = @machine.config.svn_proxy
21
- finalize_config(@config)
20
+ true
22
21
  end
23
22
 
24
- def configure_machine
25
- write_config(svn_config, path: '/etc/subversion/servers')
23
+ def unconfigure_machine
24
+ return if !supported?
25
+
26
+ @machine.communicate.tap do |comm|
27
+ comm.sudo("touch /etc/subversion/servers")
28
+ comm.sudo("sed -i.bak -e '/^http-proxy-/d' /etc/subversion/servers")
29
+ comm.sudo("chown root:root /etc/subversion/servers")
30
+ comm.sudo("chmod 0644 /etc/subversion/servers")
31
+ end
32
+ true
26
33
  end
27
34
 
28
35
  def svn_config
@@ -14,6 +14,8 @@ module VagrantPlugins
14
14
  private
15
15
 
16
16
  def configure_machine
17
+ return if !supported?
18
+
17
19
  tmp = "/tmp/vagrant-proxyconf"
18
20
  path = config_path
19
21
 
@@ -27,6 +29,20 @@ module VagrantPlugins
27
29
  comm.sudo("mv -f #{path}.new #{path}")
28
30
  comm.sudo("rm -f #{tmp}")
29
31
  end
32
+
33
+ true
34
+ end
35
+
36
+ def unconfigure_machine
37
+ return if !supported?
38
+
39
+ @machine.communicate.tap do |comm|
40
+ if comm.test("grep '^proxy' #{config_path}")
41
+ comm.sudo("sed -i.bak -e '/^proxy/d' #{config_path}")
42
+ end
43
+ end
44
+
45
+ true
30
46
  end
31
47
 
32
48
  def proxy_params
@@ -15,8 +15,25 @@ module VagrantPlugins
15
15
 
16
16
  private
17
17
 
18
+ def has_proxy_env_var?(var='HTTP_PROXY')
19
+ var_not_in_env = ENV[var].nil? || ENV[var] == ''
20
+ return false if var_not_in_env
21
+
22
+ true
23
+ end
24
+
25
+ def plugin_disabled?(config)
26
+ config.enabled == false || config.enabled == '' || config.enabled.nil? || config.enabled == {}
27
+ end
28
+
18
29
  def plugin_enabled?(config)
19
- config.enabled != false && config.enabled != ''
30
+ return false if plugin_disabled?(config)
31
+
32
+ # check for existence of HTTP_PROXY and HTTPS_PROXY environment variables
33
+ has_proxy_var = has_proxy_env_var?('HTTP_PROXY') || has_proxy_env_var?('HTTPS_PROXY')
34
+ return false if has_proxy_var == false
35
+
36
+ true
20
37
  end
21
38
  end
22
39
  end
@@ -0,0 +1,17 @@
1
+ require_relative '../util'
2
+
3
+ module VagrantPlugins
4
+ module ProxyConf
5
+ module Cap
6
+ module Linux
7
+ # Capability for chef proxy configuration
8
+ module ChefProxyConf
9
+ # @return [String, false] the path to chef or `false` if not found
10
+ def self.chef_proxy_conf(machine)
11
+ Util.which(machine, 'chef-client')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -13,7 +13,7 @@ module VagrantPlugins
13
13
 
14
14
  return false if docker_command.nil?
15
15
 
16
- if machine.communicate.test('cat /etc/redhat-release')
16
+ if machine.communicate.test('[ -f /etc/redhat-release ]')
17
17
  "/etc/sysconfig/#{docker_command}"
18
18
  elsif machine.communicate.test('ls /var/lib/boot2docker/')
19
19
  "/var/lib/boot2docker/profile"
@@ -21,6 +21,7 @@ module VagrantPlugins
21
21
  "/etc/default/#{docker_command}"
22
22
  end
23
23
  end
24
+
24
25
  end
25
26
  end
26
27
  end
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module ProxyConf
3
+ module Cap
4
+ module Linux
5
+ # Capability for Yum proxy configuration
6
+ module YumProxyConf
7
+ # @return [String] the path to the configuration file
8
+ def self.yum_proxy_conf(machine)
9
+ machine.communicate.tap do |comm|
10
+ return '/etc/yum.conf' if comm.test('[ -f /etc/yum.conf ]')
11
+ return '/etc/yum/yum.conf' if comm.test('[ -f /etc/yum/yum.conf ]')
12
+ end
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -6,11 +6,10 @@ module VagrantPlugins
6
6
  # Returns path to the command on the machine, or false if it's not found
7
7
  def self.which(machine, cmd)
8
8
  path = false
9
- status = machine.communicate.execute(
10
- "which #{cmd}", error_check: false) do |type, data|
11
- # search for the command to work around `ssh.pty = true`
12
- path = data.chomp if type == :stdout && data =~ /#{cmd}$/
13
- end
9
+ status = machine.communicate.execute("command -v #{cmd}", error_check: false) do |type, data|
10
+ # search for the command to work around `ssh.pty = true`
11
+ path = data.chomp if type == :stdout && data =~ /#{cmd}$/
12
+ end
14
13
  status == 0 && path
15
14
  end
16
15
  end
@@ -13,6 +13,11 @@ module VagrantPlugins
13
13
  Cap::Linux::DockerProxyConf
14
14
  end
15
15
 
16
+ guest_capability 'linux', 'chef_proxy_conf' do
17
+ require_relative 'cap/linux/chef_proxy_conf'
18
+ Cap::Linux::ChefProxyConf
19
+ end
20
+
16
21
  guest_capability 'coreos', 'docker_proxy_conf' do
17
22
  require_relative 'cap/coreos/docker_proxy_conf'
18
23
  Cap::CoreOS::DockerProxyConf
@@ -57,6 +62,11 @@ module VagrantPlugins
57
62
  require_relative 'cap/redhat/yum_proxy_conf'
58
63
  Cap::Redhat::YumProxyConf
59
64
  end
65
+
66
+ guest_capability 'linux', 'yum_proxy_conf' do
67
+ require_relative 'cap/linux/yum_proxy_conf'
68
+ Cap::Linux::YumProxyConf
69
+ end
60
70
  end
61
71
  end
62
72
  end
@@ -8,6 +8,16 @@ module VagrantPlugins
8
8
  Config::AptProxy
9
9
  end
10
10
 
11
+ config 'chef_proxy' do
12
+ require_relative 'config/chef_proxy'
13
+ Config::ChefProxy
14
+ end
15
+
16
+ config 'docker_proxy' do
17
+ require_relative 'config/docker_proxy'
18
+ Config::DockerProxy
19
+ end
20
+
11
21
  config 'env_proxy' do
12
22
  require_relative 'config/env_proxy'
13
23
  Config::EnvProxy
@@ -18,6 +28,16 @@ module VagrantPlugins
18
28
  Config::GitProxy
19
29
  end
20
30
 
31
+ config 'npm_proxy' do
32
+ require_relative 'config/npm_proxy'
33
+ Config::NpmProxy
34
+ end
35
+
36
+ config 'pear_proxy' do
37
+ require_relative 'config/pear_proxy'
38
+ Config::PearProxy
39
+ end
40
+
21
41
  config 'proxy' do
22
42
  require_relative 'config/proxy'
23
43
  Config::Proxy
@@ -0,0 +1,25 @@
1
+ require 'vagrant'
2
+ require_relative 'key_mixin'
3
+
4
+ module VagrantPlugins
5
+ module ProxyConf
6
+ module Config
7
+ # Configuration for generic `<protocol>_proxy` environment variables
8
+ #
9
+ # @!parse class ChefProxy < Vagrant::Plugin::V2::Config; end
10
+ class ChefProxy < Vagrant.plugin('2', :config)
11
+ include KeyMixin
12
+ # @!parse extend KeyMixin::ClassMethods
13
+
14
+ # @return [String] the HTTP proxy
15
+ key :http, env_var: 'VAGRANT_CHEF_HTTP_PROXY'
16
+
17
+ # @return [String] the HTTPS proxy
18
+ key :https, env_var: 'VAGRANT_CHEF_HTTPS_PROXY'
19
+
20
+ # @return [String] a comma separated list of hosts or domains which do not use proxies
21
+ key :no_proxy, env_var: 'VAGRANT_CHEF_NO_PROXY'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'vagrant'
2
+ require_relative 'key_mixin'
3
+
4
+ module VagrantPlugins
5
+ module ProxyConf
6
+ module Config
7
+ # Configuration for generic `<protocol>_proxy` environment variables
8
+ #
9
+ # @!parse class DockerProxy < Vagrant::Plugin::V2::Config; end
10
+ class DockerProxy < Vagrant.plugin('2', :config)
11
+ include KeyMixin
12
+ # @!parse extend KeyMixin::ClassMethods
13
+
14
+ # @return [String] the HTTP proxy
15
+ key :http, env_var: 'VAGRANT_DOCKER_HTTP_PROXY'
16
+
17
+ # @return [String] the HTTPS proxy
18
+ key :https, env_var: 'VAGRANT_DOCKER_HTTPS_PROXY'
19
+
20
+ # @return [String] a comma separated list of hosts or domains which do not use proxies
21
+ key :no_proxy, env_var: 'VAGRANT_DOCKER_NO_PROXY'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -13,6 +13,9 @@ module VagrantPlugins
13
13
 
14
14
  # @return [String] the HTTP proxy
15
15
  key :http, env_var: 'VAGRANT_GIT_HTTP_PROXY'
16
+
17
+ # @return [String] the HTTPS proxy
18
+ key :https, env_var: 'VAGRANT_GIT_HTTPS_PROXY'
16
19
  end
17
20
  end
18
21
  end
@@ -0,0 +1,25 @@
1
+ require 'vagrant'
2
+ require_relative 'key_mixin'
3
+
4
+ module VagrantPlugins
5
+ module ProxyConf
6
+ module Config
7
+ # Proxy configuration for npm
8
+ #
9
+ # @!parse class NpmProxy < Vagrant::Plugin::V2::Config; end
10
+ class NpmProxy < Vagrant.plugin('2', :config)
11
+ include KeyMixin
12
+ # @!parse extend KeyMixin::ClassMethods
13
+
14
+ # @return [String] the HTTP proxy
15
+ key :http, env_var: 'VAGRANT_NPM_HTTP_PROXY'
16
+
17
+ # @return [String] the HTTPS proxy
18
+ key :https, env_var: 'VAGRANT_NPM_HTTPS_PROXY'
19
+
20
+ # @return [String] the HTTPS proxy
21
+ key :no_proxy, env_var: 'VAGRANT_NPM_NO_PROXY'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ require 'vagrant'
2
+ require_relative 'key_mixin'
3
+
4
+ module VagrantPlugins
5
+ module ProxyConf
6
+ module Config
7
+ # Proxy configuration for pear
8
+ #
9
+ # @!parse class PearProxy < Vagrant::Plugin::V2::Config; end
10
+ class PearProxy < Vagrant.plugin('2', :config)
11
+ include KeyMixin
12
+ # @!parse extend KeyMixin::ClassMethods
13
+
14
+ # @return [String] the HTTP proxy
15
+ key :http, env_var: 'VAGRANT_PEAR_HTTP_PROXY'
16
+ end
17
+ end
18
+ end
19
+ end