vagrant-proxyconf 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -1
  4. data/CHANGELOG.md +25 -0
  5. data/Gemfile +6 -3
  6. data/LICENSE.txt +1 -1
  7. data/README.md +34 -8
  8. data/Rakefile +2 -0
  9. data/lib/vagrant-proxyconf/action.rb +28 -5
  10. data/lib/vagrant-proxyconf/action/base.rb +26 -19
  11. data/lib/vagrant-proxyconf/action/configure_chef_proxy.rb +15 -15
  12. data/lib/vagrant-proxyconf/action/configure_env_proxy.rb +2 -2
  13. data/lib/vagrant-proxyconf/action/configure_pear_proxy.rb +29 -0
  14. data/lib/vagrant-proxyconf/action/configure_yum_proxy.rb +5 -10
  15. data/lib/vagrant-proxyconf/action/is_enabled.rb +24 -0
  16. data/lib/vagrant-proxyconf/cap/linux/pear_proxy_conf.rb +15 -0
  17. data/lib/vagrant-proxyconf/capability.rb +31 -0
  18. data/lib/vagrant-proxyconf/config.rb +27 -0
  19. data/lib/vagrant-proxyconf/config/apt_proxy.rb +24 -24
  20. data/lib/vagrant-proxyconf/config/env_proxy.rb +8 -1
  21. data/lib/vagrant-proxyconf/config/key_mixin.rb +3 -2
  22. data/lib/vagrant-proxyconf/config/proxy.rb +3 -0
  23. data/lib/vagrant-proxyconf/hook.rb +41 -0
  24. data/lib/vagrant-proxyconf/plugin.rb +42 -70
  25. data/lib/vagrant-proxyconf/version.rb +1 -1
  26. data/locales/en.yml +9 -1
  27. data/spec/spec_helper.rb +11 -9
  28. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +3 -1
  29. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +10 -0
  30. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +5 -1
  31. data/spec/unit/vagrant-proxyconf/action/is_enabled_spec.rb +39 -0
  32. data/spec/unit/vagrant-proxyconf/cap/linux/pear_proxy_conf_spec.rb +25 -0
  33. data/spec/unit/vagrant-proxyconf/config/env_proxy_spec.rb +15 -8
  34. data/spec/unit/vagrant-proxyconf/plugin_spec.rb +54 -15
  35. metadata +19 -15
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccc0113cc7339765e4d71dc0a34b5c4ea9bbf29b
4
+ data.tar.gz: 820756398111a78c3e13eaf1412c5e2dc394657c
5
+ SHA512:
6
+ metadata.gz: cfe68c260b981d6e806c9fd0b49ce502cadac5938697903f634c14b4d85d7d0682e09abd587344e4848ab756dae78475fe72e7e289ab11243f655652ecc1f1c3
7
+ data.tar.gz: f0add4636c11c68fc4b264fd0454113be6091baa0f5581d32cd3b84eb7b4830b217bef0c8e3d03078ae174b40af55550bbf443546af1b866aef222ac8d5a80cf
data/.gitignore CHANGED
@@ -2,5 +2,5 @@
2
2
  /.yardoc
3
3
  /Gemfile.lock
4
4
  /doc
5
- /pkg
6
5
  /tmp
6
+ vagrant-proxyconf-*.gem
@@ -1,4 +1,18 @@
1
1
  language: ruby
2
+
3
+ before_install: gem install bundler --version '>= 1.5.2'
2
4
  bundler_args: --without=development
5
+
3
6
  rvm:
4
- - 1.9.3
7
+ - 2.0.0
8
+ env:
9
+ - VAGRANT_VERSION=v1.4.3
10
+ matrix:
11
+ include:
12
+ - env: VAGRANT_VERSION=v1.3.5
13
+ rvm: 1.9.3
14
+ - env: VAGRANT_VERSION=v1.2.7
15
+ rvm: 1.9.3
16
+ - env: VAGRANT_VERSION=master
17
+ allow_failures:
18
+ - env: VAGRANT_VERSION=master
@@ -1,3 +1,23 @@
1
+ # 1.1.0 / 2014-02-06
2
+
3
+ Features:
4
+
5
+ - Add `config.proxy.enabled` option which can be set to `false` to disable the plugin ([GH-39][])
6
+ - Support for configuring PEAR ([GH-34][])
7
+
8
+ Improvements:
9
+
10
+ - Compatibility with Vagrant v1.5:
11
+ * `Vagrant.require_plugin` deprecated ([GH-44][])
12
+ * Hook before `SyncedFolders` action as it can install NFS client ([GH-45][])
13
+ * Vagrant 1.5.0 is not released at the time of this release, so compatibility can't be guaranteed yet
14
+ - Run Travis tests against all supported Vagrant minor versions with correct Ruby version
15
+ - Decrease noise level, don't print messages when configuring something
16
+
17
+ Bug fixes:
18
+
19
+ - Quote `no_proxy` in _/etc/profile.d/proxy.sh_ to protect it from spaces ([GH-42][])
20
+
1
21
  # 1.0.1 / 2013-12-01
2
22
 
3
23
  - Ensure that Yum configuration includes the (default) port ([GH-36][])
@@ -94,5 +114,10 @@
94
114
  [GH-29]: https://github.com/tmatilai/vagrant-proxyconf/issues/29 "Issue 29"
95
115
  [GH-30]: https://github.com/tmatilai/vagrant-proxyconf/issues/30 "Issue 30"
96
116
  [GH-32]: https://github.com/tmatilai/vagrant-proxyconf/issues/32 "Issue 32"
117
+ [GH-34]: https://github.com/tmatilai/vagrant-proxyconf/issues/34 "Issue 34"
97
118
  [GH-35]: https://github.com/tmatilai/vagrant-proxyconf/issues/35 "Issue 35"
98
119
  [GH-36]: https://github.com/tmatilai/vagrant-proxyconf/issues/36 "Issue 36"
120
+ [GH-39]: https://github.com/tmatilai/vagrant-proxyconf/issues/39 "Issue 39"
121
+ [GH-42]: https://github.com/tmatilai/vagrant-proxyconf/issues/42 "Issue 42"
122
+ [GH-44]: https://github.com/tmatilai/vagrant-proxyconf/issues/44 "Issue 44"
123
+ [GH-45]: https://github.com/tmatilai/vagrant-proxyconf/issues/45 "Issue 45"
data/Gemfile CHANGED
@@ -2,12 +2,15 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'vagrant',
6
+ github: 'mitchellh/vagrant',
7
+ ref: ENV.fetch('VAGRANT_VERSION', 'v1.4.3')
8
+
5
9
  gem 'cane', '~> 2.6'
10
+ gem 'coveralls', require: false
6
11
  gem 'rake'
7
12
  gem 'rspec', '~> 2.11'
8
- gem 'simplecov', '~> 0.7', :require => false
9
- gem 'tailor', '~> 1.2'
10
- gem 'vagrant', github: 'mitchellh/vagrant', ref: 'v1.3.5'
13
+ gem 'tailor', '~> 1.4'
11
14
 
12
15
  group :development do
13
16
  gem 'guard-rspec'
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2013 Teemu Matilainen <teemu.matilainen@iki.fi>
3
+ Copyright (c) 2013-2014 Teemu Matilainen <teemu.matilainen@iki.fi>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -5,12 +5,14 @@
5
5
  [![Build Status](https://travis-ci.org/tmatilai/vagrant-proxyconf.png?branch=master)][travis]
6
6
  [![Dependency Status](https://gemnasium.com/tmatilai/vagrant-proxyconf.png)][gemnasium]
7
7
  [![Code Climate](https://codeclimate.com/github/tmatilai/vagrant-proxyconf.png)][codeclimate]
8
+ [![Coverage Status](https://coveralls.io/repos/tmatilai/vagrant-proxyconf/badge.png)][coveralls]
8
9
  </span>
9
10
 
10
11
  [gem]: https://rubygems.org/gems/vagrant-proxyconf
11
12
  [travis]: https://travis-ci.org/tmatilai/vagrant-proxyconf
12
13
  [gemnasium]: https://gemnasium.com/tmatilai/vagrant-proxyconf
13
14
  [codeclimate]: https://codeclimate.com/github/tmatilai/vagrant-proxyconf
15
+ [coveralls]: https://coveralls.io/r/tmatilai/vagrant-proxyconf
14
16
 
15
17
  A [Vagrant](http://www.vagrantup.com/) plugin that configures the virtual machine to use specified proxies. This is useful for example in case you are behind a corporate proxy server, or you have a caching proxy (for example [polipo](https://github.com/tmatilai/polipo-box)).
16
18
 
@@ -20,6 +22,7 @@ The plugin can set:
20
22
  * default proxy configuration for all Chef provisioners
21
23
  * proxy configuration for Apt
22
24
  * proxy configuration for Yum
25
+ * proxy configuration for PEAR
23
26
 
24
27
  ## Quick start
25
28
 
@@ -33,9 +36,11 @@ To configure all possible software on all Vagrant VMs, add the following to _$HO
33
36
 
34
37
  ```ruby
35
38
  Vagrant.configure("2") do |config|
36
- config.proxy.http = "http://192.168.0.2:3128/"
37
- config.proxy.https = "http://192.168.0.2:3128/"
38
- config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
39
+ if Vagrant.has_plugin?("vagrant-proxyconf")
40
+ config.proxy.http = "http://192.168.0.2:3128/"
41
+ config.proxy.https = "http://192.168.0.2:3128/"
42
+ config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
43
+ end
39
44
  # ... other stuff
40
45
  end
41
46
  ```
@@ -62,6 +67,8 @@ Proxy settings can be configured in Vagrantfile. In the common case that you wan
62
67
 
63
68
  Project specific Vagrantfile overrides global settings. Environment variables override both.
64
69
 
70
+ It is a good practise to wrap plugin specific configuration with `Vagrant.has_plugin?` checks so the user's Vagrantfiles do not break if plugin is uninstalled or Vagrantfile shared with people not having the plugin installed. (For Vagrant 1.2 you have to use `if defined?(VagrantPlugins::ProxyConf)` instead.)
71
+
65
72
  ### Default/global configuration
66
73
 
67
74
  It's a common case that you want all possible connections to pass through the same proxy. This will set the default values for all other proxy configuration keys. It also sets default proxy configuration for all Chef Solo and Chef Client provisioners.
@@ -70,9 +77,11 @@ It's a common case that you want all possible connections to pass through the sa
70
77
 
71
78
  ```ruby
72
79
  Vagrant.configure("2") do |config|
73
- config.proxy.http = "http://192.168.0.2:3128/"
74
- config.proxy.https = "http://192.168.0.2:3128/"
75
- config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
80
+ if Vagrant.has_plugin?("vagrant-proxyconf")
81
+ config.proxy.http = "http://192.168.0.2:3128/"
82
+ config.proxy.https = "http://192.168.0.2:3128/"
83
+ config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
84
+ end
76
85
  # ... other stuff
77
86
  end
78
87
  ```
@@ -105,6 +114,23 @@ For example to spin up a VM, run:
105
114
  VAGRANT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
106
115
  ```
107
116
 
117
+ ### Disabling the plugin
118
+
119
+ The plugin can be totally skipped by setting `config.proxy.enabled` to `false` or empty string (`""`). This can be useful to for example disable it for some provider.
120
+
121
+ #### Example Vagrantfile
122
+
123
+ ```ruby
124
+ Vagrant.configure("2") do |config|
125
+ config.proxy.http = "http://192.168.0.2:3128/"
126
+
127
+ config.vm.provider :my_cloud do |cloud, override|
128
+ override.proxy.enabled = false
129
+ end
130
+ # ... other stuff
131
+ end
132
+ ```
133
+
108
134
  ### Global `*_proxy` environment variables
109
135
 
110
136
  Many programs (wget, curl, yum, etc.) can be configured to use proxies with `http_proxy` or `HTTP_PROXY` etc. environment variables. This configuration will be written to _/etc/profile.d/proxy.sh_ on the guest.
@@ -116,7 +142,7 @@ Also sudo will be configured to preserve the variables. This requires that sudo
116
142
  ```ruby
117
143
  Vagrant.configure("2") do |config|
118
144
  config.env_proxy.http = "http://192.168.33.200:8888/"
119
- config.env_proxy.https = "$http_proxy"
145
+ config.env_proxy.https = "http://192.168.33.200:8888/"
120
146
  config.env_proxy.no_proxy = "localhost,127.0.0.1,.example.com"
121
147
  # ... other stuff
122
148
  end
@@ -174,7 +200,7 @@ end
174
200
  #### Possible values
175
201
 
176
202
  * If all keys are unset or `nil`, no configuration is written or modified.
177
- * A proxy can be specified in the form of _[http://][user:pass@]host[:port]_. So all but the _host_ part are optional. The default port is 3142 and scheme is the same as the key.
203
+ * A proxy can be specified in the form of _http://[user:pass@]host:port_.
178
204
  * Empty string (`""`) or `false` in any key also force the configuration file to be written, but without configuration for that scheme. Can be used to clear the old configuration and/or override a global setting.
179
205
  * `"DIRECT"` can be used to specify that no proxy should be used. This is mostly useful for disabling proxy for HTTPS URIs when HTTP proxy is set (as Apt defaults to the latter).
180
206
  * Please refer to [apt.conf(5)](http://manpages.debian.net/man/5/apt.conf) manual for more information.
data/Rakefile CHANGED
@@ -19,10 +19,12 @@ task :spec => :test
19
19
 
20
20
  Tailor::RakeTask.new do |task|
21
21
  task.file_set('lib/**/*.rb', 'code') do |style|
22
+ style.allow_unnecessary_double_quotes false, level: :off
22
23
  style.max_line_length 100, level: :warn
23
24
  style.max_line_length 140, level: :error
24
25
  end
25
26
  task.file_set('spec/**/*.rb', 'tests') do |style|
27
+ style.allow_unnecessary_double_quotes false, level: :off
26
28
  style.max_line_length 120, level: :warn
27
29
  # allow vertical alignment of `let(:foo) { block }` blocks
28
30
  style.spaces_before_lbrace 1, level: :off
@@ -1,13 +1,19 @@
1
+ require 'vagrant/action/builtin/call'
1
2
  require_relative 'action/configure_apt_proxy'
2
3
  require_relative 'action/configure_chef_proxy'
3
4
  require_relative 'action/configure_env_proxy'
5
+ require_relative 'action/configure_pear_proxy'
4
6
  require_relative 'action/configure_yum_proxy'
7
+ require_relative 'action/is_enabled'
5
8
  require_relative 'action/only_once'
6
9
 
7
10
  module VagrantPlugins
8
11
  module ProxyConf
9
12
  # Middleware stack builders
10
13
  class Action
14
+ # Shortcut
15
+ Builtin = Vagrant::Action::Builtin
16
+
11
17
  # Returns an action middleware stack that configures the VM
12
18
  #
13
19
  # @param opts [Hash] the options to be passed to {OnlyOnce}
@@ -16,16 +22,33 @@ module VagrantPlugins
16
22
  Vagrant::Action::Builder.build(OnlyOnce, opts, &config_actions)
17
23
  end
18
24
 
25
+ # Returns an action middleware stack that configures the VM
26
+ # after provisioner runs.
27
+ def self.configure_after_provisoner
28
+ Vagrant::Action::Builder.new.tap do |b|
29
+ b.use Builtin::Call, IsEnabled do |env, b2|
30
+ next if !env[:result]
31
+
32
+ b2.use ConfigurePearProxy
33
+ end
34
+ end
35
+ end
36
+
19
37
  private
20
38
 
21
39
  # @return [Proc] the block that adds config actions to the specified
22
40
  # middleware builder
23
41
  def self.config_actions
24
- @actions ||= Proc.new do |builder|
25
- builder.use ConfigureAptProxy
26
- builder.use ConfigureChefProxy
27
- builder.use ConfigureEnvProxy
28
- builder.use ConfigureYumProxy
42
+ @config_actions ||= Proc.new do |b|
43
+ b.use Builtin::Call, IsEnabled do |env, b2|
44
+ next if !env[:result]
45
+
46
+ b2.use ConfigureAptProxy
47
+ b2.use ConfigureChefProxy
48
+ b2.use ConfigureEnvProxy
49
+ b2.use ConfigurePearProxy
50
+ b2.use ConfigureYumProxy
51
+ end
29
52
  end
30
53
  end
31
54
  end
@@ -12,16 +12,15 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- machine = env[:machine]
16
- config = config(machine)
15
+ @machine = env[:machine]
17
16
 
18
17
  if !config.enabled?
19
18
  logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_enabled")
20
- elsif !supported?(machine)
21
- env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
19
+ elsif !supported?
20
+ logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
22
21
  else
23
22
  env[:ui].info I18n.t("vagrant_proxyconf.#{config_name}.configuring")
24
- configure_machine(machine, config)
23
+ configure_machine
25
24
  end
26
25
 
27
26
  @app.call env
@@ -40,15 +39,17 @@ module VagrantPlugins
40
39
  end
41
40
 
42
41
  # @return [Vagrant::Plugin::V2::Config] the configuration
43
- def config(machine)
44
- config = machine.config.public_send(config_name.to_sym)
42
+ def config
43
+ return @config if @config
44
+
45
+ config = @machine.config.public_send(config_name.to_sym)
45
46
  finalize_config(config)
46
- config.merge_defaults(default_config(machine))
47
+ @config = config.merge_defaults(default_config)
47
48
  end
48
49
 
49
50
  # @return [Vagrant::Plugin::V2::Config] the default configuration
50
- def default_config(machine)
51
- config = machine.config.proxy
51
+ def default_config
52
+ config = @machine.config.proxy
52
53
  finalize_config(config)
53
54
  end
54
55
 
@@ -61,8 +62,8 @@ module VagrantPlugins
61
62
  end
62
63
 
63
64
  # Configures the VM based on the config
64
- def configure_machine(machine, config)
65
- write_config(machine, config)
65
+ def configure_machine
66
+ write_config(config)
66
67
  end
67
68
 
68
69
  # Writes the config to the VM
@@ -71,13 +72,13 @@ module VagrantPlugins
71
72
  # @option opts [String] :path (#config_path) the path of the configuration file
72
73
  # @option opts [String] :mode ("0644") the mode of the file
73
74
  # @option opts [String] :owner ("root:root") the owner (and group) of the file
74
- def write_config(machine, config, opts = {})
75
+ def write_config(config, opts = {})
75
76
  tmp = "/tmp/vagrant-proxyconf"
76
- path = opts[:path] || config_path(machine)
77
+ path = opts[:path] || config_path
77
78
  local_tmp = tempfile(config)
78
79
 
79
80
  logger.debug "Configuration (#{path}):\n#{config}"
80
- machine.communicate.tap do |comm|
81
+ @machine.communicate.tap do |comm|
81
82
  comm.sudo("rm #{tmp}", error_check: false)
82
83
  comm.upload(local_tmp.path, tmp)
83
84
  comm.sudo("chmod #{opts[:mode] || '0644'} #{tmp}")
@@ -87,6 +88,11 @@ module VagrantPlugins
87
88
  end
88
89
  end
89
90
 
91
+ # @param value [String, nil] the string to escape for shell usage
92
+ def escape(value)
93
+ value.to_s.shellescape
94
+ end
95
+
90
96
  # @return [Tempfile] a temporary file with the specified content
91
97
  def tempfile(content)
92
98
  Tempfile.new("vagrant").tap do |temp|
@@ -100,12 +106,13 @@ module VagrantPlugins
100
106
  "#{config_name}_conf".to_sym
101
107
  end
102
108
 
103
- def supported?(machine)
104
- machine.guest.capability?(cap_name)
109
+ def supported?
110
+ @machine.guest.capability?(cap_name) &&
111
+ @machine.guest.capability(cap_name)
105
112
  end
106
113
 
107
- def config_path(machine)
108
- machine.guest.capability(cap_name)
114
+ def config_path
115
+ @machine.guest.capability(cap_name)
109
116
  end
110
117
  end
111
118
  end
@@ -11,16 +11,15 @@ module VagrantPlugins
11
11
  end
12
12
 
13
13
  def call(env)
14
- machine = env[:machine]
15
- config = config(machine)
14
+ @machine = env[:machine]
16
15
 
17
- if chef_provisioners(machine).empty?
16
+ if chef_provisioners.empty?
18
17
  logger.info I18n.t("vagrant_proxyconf.chef_proxy.no_provisioners")
19
18
  elsif !config.enabled?
20
19
  logger.info I18n.t("vagrant_proxyconf.chef_proxy.not_enabled")
21
20
  else
22
21
  env[:ui].info I18n.t("vagrant_proxyconf.chef_proxy.configuring")
23
- configure_chef_provisioners(machine, config)
22
+ configure_chef_provisioners
24
23
  end
25
24
 
26
25
  @app.call env
@@ -34,29 +33,30 @@ module VagrantPlugins
34
33
  end
35
34
 
36
35
  # @return [Config::Proxy] the `config.proxy` configuration
37
- def config(machine)
38
- config = machine.config.proxy
36
+ def config
37
+ return @config if @config
38
+
39
+ config = @machine.config.proxy
39
40
  config.finalize! if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new('1.2.5')
40
- config
41
+ @config = config
41
42
  end
42
43
 
43
44
  # @return [Array] all Chef provisioners
44
- def chef_provisioners(machine)
45
- machine.config.vm.provisioners.select { |prov| [:chef_solo, :chef_client].include?(prov.name) }
45
+ def chef_provisioners
46
+ @machine.config.vm.provisioners.select do |prov|
47
+ [:chef_solo, :chef_client].include?(prov.name)
48
+ end
46
49
  end
47
50
 
48
51
  # Configures all Chef provisioner based on the default config
49
- #
50
- # @param config [Config::Proxy] the default configuration
51
- def configure_chef_provisioners(machine, config)
52
- chef_provisioners(machine).each { |prov| configure_chef(prov.config, config) }
52
+ def configure_chef_provisioners
53
+ chef_provisioners.each { |prov| configure_chef(prov.config) }
53
54
  end
54
55
 
55
56
  # Configures proxies for a Chef provisioner if they are not set
56
57
  #
57
58
  # @param chef [VagrantPlugins::Chef::Config::Base] the Chef provisioner configuration
58
- # @param config [Config::Proxy] the default configuration
59
- def configure_chef(chef, config)
59
+ def configure_chef(chef)
60
60
  configure_chef_proxy(chef, 'http', config.http)
61
61
  configure_chef_proxy(chef, 'https', config.https)
62
62
  chef.no_proxy ||= config.no_proxy if config.no_proxy
@@ -11,9 +11,9 @@ module VagrantPlugins
11
11
 
12
12
  private
13
13
 
14
- def configure_machine(machine, config)
14
+ def configure_machine
15
15
  super
16
- write_config(machine, sudo_config, path: '/etc/sudoers.d/proxy', mode: '0440')
16
+ write_config(sudo_config, path: '/etc/sudoers.d/proxy', mode: '0440')
17
17
  end
18
18
 
19
19
  def sudo_config