vagrant-proxyconf 1.5.2 → 2.0.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -14
  4. data/CHANGELOG.md +19 -0
  5. data/Gemfile +25 -7
  6. data/LICENSE.txt +1 -1
  7. data/README.md +117 -18
  8. data/Rakefile +1 -27
  9. data/development/Dockerfile +40 -0
  10. data/development/README.md +2 -0
  11. data/development/Vagrantfile.example +156 -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 +113 -12
  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/cap/linux/chef_proxy_conf.rb +17 -0
  27. data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
  28. data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
  29. data/lib/vagrant-proxyconf/cap/util.rb +4 -5
  30. data/lib/vagrant-proxyconf/capability.rb +10 -0
  31. data/lib/vagrant-proxyconf/config.rb +20 -0
  32. data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
  33. data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
  34. data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
  35. data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
  36. data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
  37. data/lib/vagrant-proxyconf/version.rb +1 -1
  38. data/locales/en.yml +38 -0
  39. data/resources/yum_config.awk +1 -0
  40. data/spec/spec_helper.rb +27 -9
  41. data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
  42. data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
  43. data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
  44. data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
  45. data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
  46. data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
  47. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
  48. data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +489 -0
  49. data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
  50. data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
  51. data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
  52. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
  53. data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
  54. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
  55. data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
  56. data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
  57. data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
  58. data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
  59. data/travis/before_install +26 -0
  60. metadata +24 -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProxyConf
3
- VERSION = '1.5.2'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
@@ -7,6 +7,10 @@ en:
7
7
  Skipping Apt proxy config as the machine does not support it
8
8
  configuring: |-
9
9
  Configuring proxy for Apt...
10
+ skip: |-
11
+ Skipping configuration of apt_proxy
12
+ unconfiguring: |-
13
+ Unconfiguring proxy for Apt...
10
14
 
11
15
  docker_proxy:
12
16
  not_enabled: |-
@@ -15,6 +19,10 @@ en:
15
19
  Skipping Docker proxy config as the machine does not support it
16
20
  configuring: |-
17
21
  Configuring proxy for Docker...
22
+ skip: |-
23
+ Skipping configuration of docker_proxy
24
+ unconfiguring: |-
25
+ Unconfiguring proxy for Docker...
18
26
 
19
27
  chef_proxy:
20
28
  no_provisioners: |-
@@ -23,6 +31,10 @@ en:
23
31
  Default proxy not enabled or configured. Skipping Chef provisioner configuration.
24
32
  configuring: |-
25
33
  Configuring proxy for Chef provisioners...
34
+ skip: |-
35
+ Skipping configuration of chef_proxy
36
+ unconfiguring: |-
37
+ Unconfiguring proxy for Chef provisioners...
26
38
 
27
39
  env_proxy:
28
40
  not_enabled: |-
@@ -31,6 +43,10 @@ en:
31
43
  Skipping environment variable based proxy config as the machine does not support it
32
44
  configuring: |-
33
45
  Configuring proxy environment variables...
46
+ skip: |-
47
+ Skipping configuration of env_proxy
48
+ unconfiguring: |-
49
+ Unconfiguring proxy environment variables...
34
50
 
35
51
  git_proxy:
36
52
  not_enabled: |-
@@ -39,6 +55,10 @@ en:
39
55
  Skipping Git proxy config as `git` is not found
40
56
  configuring: |-
41
57
  Configuring proxy for Git...
58
+ skip: |-
59
+ Skipping configuration of git_proxy
60
+ unconfiguring: |-
61
+ Unconfiguring proxy for Git...
42
62
 
43
63
  npm_proxy:
44
64
  not_enabled: |-
@@ -47,6 +67,10 @@ en:
47
67
  Skipping npm proxy config as `npm` is not found
48
68
  configuring: |-
49
69
  Configuring proxy for npm...
70
+ skip: |-
71
+ Skipping configuration of npm_proxy
72
+ unconfiguring: |-
73
+ Unconfiguring proxy for npm...
50
74
 
51
75
  pear_proxy:
52
76
  not_enabled: |-
@@ -55,6 +79,10 @@ en:
55
79
  Skipping PEAR proxy config as `pear` is not found
56
80
  configuring: |-
57
81
  Configuring proxy for PEAR...
82
+ skip: |-
83
+ Skipping configuration of pear_proxy
84
+ unconfiguring: |-
85
+ Unconfiguring proxy for PEAR...
58
86
 
59
87
  svn_proxy:
60
88
  not_enabled: |-
@@ -63,6 +91,10 @@ en:
63
91
  Skipping Subversion proxy config as the machine does not support it
64
92
  configuring: |-
65
93
  Configuring proxy for Subversion...
94
+ skip: |-
95
+ Skipping configuration of svn_proxy
96
+ unconfiguring: |-
97
+ Unconfiguring proxy for Subversion...
66
98
 
67
99
  yum_proxy:
68
100
  not_enabled: |-
@@ -71,6 +103,12 @@ en:
71
103
  Skipping Yum proxy config as the machine does not support it
72
104
  configuring: |-
73
105
  Configuring proxy for Yum...
106
+ skip: |-
107
+ Skipping configuration of yum_proxy
108
+ unconfiguring: |-
109
+ Unconfiguring proxy for Yum...
110
+
111
+ errors:
74
112
 
75
113
  errors:
76
114
  vagrant_version: |-