vagrant-proxyconf 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.5.0 / 2013-09-11
2
+
3
+ - Set default proxy configuration for all Chef provisioners ([GH-19][], [GH-21][])
4
+
1
5
  # 0.4.0 / 2013-09-04
2
6
 
3
7
  - BREAKING: Environment variables for Apt config renamed to `VAGRANT_APT_HTTP_PROXY` etc. ([GH-15][])
@@ -45,3 +49,5 @@
45
49
  [GH-14]: https://github.com/tmatilai/vagrant-proxyconf/issues/14 "Issue 14"
46
50
  [GH-15]: https://github.com/tmatilai/vagrant-proxyconf/issues/15 "Issue 15"
47
51
  [GH-17]: https://github.com/tmatilai/vagrant-proxyconf/issues/17 "Issue 17"
52
+ [GH-19]: https://github.com/tmatilai/vagrant-proxyconf/issues/19 "Issue 19"
53
+ [GH-21]: https://github.com/tmatilai/vagrant-proxyconf/issues/21 "Issue 21"
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem 'rake'
7
7
  gem 'rspec', '~> 2.11'
8
8
  gem 'simplecov', '~> 0.7', :require => false
9
9
  gem 'tailor', '~> 1.2'
10
- gem 'vagrant', github: 'mitchellh/vagrant', ref: 'v1.2.7'
10
+ gem 'vagrant', github: 'mitchellh/vagrant', ref: 'v1.3.1'
11
11
 
12
12
  group :development do
13
13
  gem 'guard-rspec'
data/README.md CHANGED
@@ -12,12 +12,13 @@
12
12
  [gemnasium]: https://gemnasium.com/tmatilai/vagrant-proxyconf
13
13
  [codeclimate]: https://codeclimate.com/github/tmatilai/vagrant-proxyconf
14
14
 
15
- A [Vagrant](http://www.vagrantup.com/) plugin that configures the virtual machine to use specified proxies.
15
+ 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, or you have a caching proxy.
16
16
 
17
17
  At this state we support:
18
18
 
19
19
  * Generic `*_proxy` environment variables that many programs support
20
20
  * APT proxy/cacher
21
+ * Setting default proxy configuration for all Chef provisioners
21
22
 
22
23
  Support is planned for other package managers (at least yum).
23
24
 
@@ -54,7 +55,7 @@ Project specific Vagrantfile overrides global settings. Environment variables ov
54
55
 
55
56
  ### Default/global configuration
56
57
 
57
- 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.
58
+ 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.
58
59
 
59
60
  #### Example Vagrantfile
60
61
 
@@ -71,7 +72,7 @@ end
71
72
 
72
73
  * `config.proxy.http` - The proxy for HTTP URIs
73
74
  * `config.proxy.https` - The proxy for HTTPS URIs
74
- * `config.proxy.ftp` - The proxy for FTS URIs
75
+ * `config.proxy.ftp` - The proxy for FTP URIs
75
76
  * `config.proxy.no_proxy` - A comma separated list of hosts or domains which do not use proxies.
76
77
 
77
78
  #### Possible values
@@ -114,7 +115,7 @@ end
114
115
 
115
116
  * `config.env_proxy.http` - The proxy for HTTP URIs
116
117
  * `config.env_proxy.https` - The proxy for HTTPS URIs
117
- * `config.env_proxy.ftp` - The proxy for FTS URIs
118
+ * `config.env_proxy.ftp` - The proxy for FTP URIs
118
119
  * `config.env_proxy.no_proxy` - A comma separated list of hosts or domains which do not use proxies.
119
120
 
120
121
  #### Possible values
data/Rakefile CHANGED
@@ -30,6 +30,7 @@ Tailor::RakeTask.new do |task|
30
30
  end
31
31
 
32
32
  Cane::RakeTask.new(:cane) do |task|
33
+ task.abc_max = 16
33
34
  task.style_measure = 140
34
35
  task.options[:color] = true
35
36
  end
@@ -0,0 +1,72 @@
1
+ module VagrantPlugins
2
+ module ProxyConf
3
+ class Action
4
+ # Action for configuring Chef provisioners
5
+ class ConfigureChefProxy
6
+ attr_reader :logger
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new('vagrant::proxyconf')
11
+ end
12
+
13
+ def call(env)
14
+ @app.call env
15
+
16
+ machine = env[:machine]
17
+ config = config(machine)
18
+
19
+ if chef_provisioners(machine).empty?
20
+ logger.debug I18n.t("vagrant_proxyconf.chef_proxy.no_provisioners")
21
+ elsif !config.enabled?
22
+ logger.debug I18n.t("vagrant_proxyconf.chef_proxy.not_enabled")
23
+ else
24
+ env[:ui].info I18n.t("vagrant_proxyconf.chef_proxy.configuring")
25
+ configure_chef_provisioners(machine, config)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ # @return [Config::Proxy] the `config.proxy` configuration
32
+ def config(machine)
33
+ config = machine.config.proxy
34
+ config.finalize! if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new('1.2.5')
35
+ config
36
+ end
37
+
38
+ # @return [Array] all Chef provisioners
39
+ def chef_provisioners(machine)
40
+ machine.config.vm.provisioners.select { |prov| [:chef_solo, :chef_client].include?(prov.name) }
41
+ end
42
+
43
+ # Configures all Chef provisioner based on the default config
44
+ #
45
+ # @param config [Config::Proxy] the default configuration
46
+ def configure_chef_provisioners(machine, config)
47
+ chef_provisioners(machine).each { |prov| configure_chef(prov.config, config) }
48
+ end
49
+
50
+ # Configures proxies for the Chef provisioner if they are not set
51
+ #
52
+ # @param chef [VagrantPlugins::Chef::Config::Base] the Chef provisioner configuration
53
+ # @param config [Config::Proxy] the default configuration
54
+ def configure_chef(chef, config)
55
+ if chef.http_proxy.nil?
56
+ chef.http_proxy = config.http
57
+ chef.http_proxy_user = config.http_user
58
+ chef.http_proxy_pass = config.http_pass
59
+ end
60
+ if chef.https_proxy.nil?
61
+ chef.https_proxy = config.https
62
+ chef.https_proxy_user = config.https_user
63
+ chef.https_proxy_pass = config.https_pass
64
+ end
65
+ if chef.no_proxy.nil?
66
+ chef.no_proxy = config.no_proxy
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'vagrant'
2
3
  require_relative 'key_mixin'
3
4
 
@@ -27,6 +28,35 @@ module VagrantPlugins
27
28
  # @return [String] a comma separated list of hosts or domains which do not use proxies
28
29
  key :no_proxy, env_var: 'VAGRANT_NO_PROXY'
29
30
 
31
+ # @return [String] username for the HTTP proxy
32
+ def http_user
33
+ user(http)
34
+ end
35
+
36
+ # @return [String] password for the HTTP proxy
37
+ def http_pass
38
+ pass(http)
39
+ end
40
+
41
+ # @return [String] username for the HTTPS proxy
42
+ def https_user
43
+ user(https)
44
+ end
45
+
46
+ # @return [String] password for the HTTPS proxy
47
+ def https_pass
48
+ pass(https)
49
+ end
50
+
51
+ private
52
+
53
+ def user(uri)
54
+ URI.parse(uri).user if !uri.nil?
55
+ end
56
+
57
+ def pass(uri)
58
+ URI.parse(uri).password if !uri.nil?
59
+ end
30
60
  end
31
61
  end
32
62
  end
@@ -29,9 +29,11 @@ module VagrantPlugins
29
29
 
30
30
  def self.register_hooks(hook, provision_action)
31
31
  require_relative 'action/configure_apt_proxy'
32
+ require_relative 'action/configure_chef_proxy'
32
33
  require_relative 'action/configure_env_proxy'
33
34
 
34
35
  hook.after provision_action, Action::ConfigureAptProxy
36
+ hook.after provision_action, Action::ConfigureChefProxy
35
37
  hook.after provision_action, Action::ConfigureEnvProxy
36
38
  end
37
39
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProxyConf
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -8,6 +8,14 @@ en:
8
8
  configuring: |-
9
9
  Configuring proxy for Apt...
10
10
 
11
+ chef_proxy:
12
+ no_provisioners: |-
13
+ No Chef provisioners configured.
14
+ not_enabled: |-
15
+ Default proxy not enabled or configured. Skipping Chef provisioner configuration.
16
+ configuring: |-
17
+ Configuring proxy for Chef provisioners...
18
+
11
19
  env_proxy:
12
20
  not_enabled: |-
13
21
  env_proxy not enabled or configured
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-proxyconf/action/configure_chef_proxy'
3
+ require 'ostruct'
4
+
5
+ describe VagrantPlugins::ProxyConf::Action::ConfigureChefProxy do
6
+
7
+ describe '#configure_chef' do
8
+ let(:chef) { OpenStruct.new }
9
+ let(:config) { OpenStruct.new }
10
+
11
+ def configure_chef
12
+ described_class.new(nil, nil).send(:configure_chef, chef, config)
13
+ end
14
+
15
+ context "with no configurations" do
16
+ it "leaves all to nil" do
17
+ configure_chef
18
+ expect(chef.http_proxy).to be_nil
19
+ expect(chef.http_proxy_user).to be_nil
20
+ expect(chef.http_proxy_pass).to be_nil
21
+ expect(chef.https_proxy).to be_nil
22
+ expect(chef.https_proxy_user).to be_nil
23
+ expect(chef.https_proxy_pass).to be_nil
24
+ expect(chef.no_proxy).to be_nil
25
+ end
26
+ end
27
+
28
+ context "with specified default configurations" do
29
+ before :each do
30
+ config.http = 'http://foo:1234'
31
+ config.http_user = 'bar'
32
+
33
+ configure_chef
34
+ end
35
+
36
+ it "configures chef" do
37
+ expect(chef.http_proxy).to eq 'http://foo:1234'
38
+ expect(chef.http_proxy_user).to eq 'bar'
39
+ expect(chef.http_proxy_pass).to be_nil
40
+ end
41
+ end
42
+
43
+ context "with specified chef configurations" do
44
+ before :each do
45
+ chef.http_proxy = 'http://proxy:8080/'
46
+ chef.no_proxy = 'localhost'
47
+
48
+ config.http = 'http://default:7070/'
49
+ config.http_user = 'foo'
50
+ config.https = 'http://sslproxy:3128/'
51
+
52
+ configure_chef
53
+ end
54
+
55
+ it "won't override chef config" do
56
+ expect(chef.http_proxy).to eq 'http://proxy:8080/'
57
+ expect(chef.http_proxy_user).to be_nil
58
+ expect(chef.http_proxy_pass).to be_nil
59
+ expect(chef.no_proxy).to eq 'localhost'
60
+ end
61
+
62
+ it "configures unset proxies" do
63
+ expect(chef.https_proxy).to eq 'http://sslproxy:3128/'
64
+ end
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-proxyconf/cap/linux/env_proxy_conf'
3
+
4
+ describe VagrantPlugins::ProxyConf::Cap::Linux::EnvProxyConf do
5
+
6
+ describe '.env_proxy_conf' do
7
+ let(:subject) { described_class.env_proxy_conf(double) }
8
+ it { should eq '/etc/profile.d/proxy.sh' }
9
+ end
10
+
11
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-proxyconf/config/proxy'
3
+
4
+ describe VagrantPlugins::ProxyConf::Config::Proxy do
5
+ before :each do
6
+ # Ensure tests are not affected by environment variables
7
+ %w[HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY].each do |var|
8
+ ENV.delete("VAGRANT_#{var}")
9
+ end
10
+ end
11
+
12
+ subject do
13
+ described_class.new.tap do |config|
14
+ config.http = http_proxy
15
+ config.https = https_proxy
16
+ end
17
+ end
18
+ let(:http_proxy) { nil }
19
+ let(:https_proxy) { nil }
20
+
21
+ context "defaults" do
22
+ its(:http_user) { should be_nil }
23
+ its(:http_pass) { should be_nil }
24
+ its(:https_user) { should be_nil }
25
+ its(:https_pass) { should be_nil }
26
+ end
27
+
28
+ context "without userinfo" do
29
+ let(:http_proxy) { 'http://proxy.example.com:8123/' }
30
+ let(:https_proxy) { '' }
31
+
32
+ its(:http_user) { should be_nil }
33
+ its(:http_pass) { should be_nil }
34
+ its(:https_user) { should be_nil }
35
+ its(:https_pass) { should be_nil }
36
+ end
37
+
38
+ context "with username" do
39
+ let(:http_proxy) { 'http://foo@proxy.example.com:8123/' }
40
+ let(:https_proxy) { 'http://bar@localhost' }
41
+
42
+ its(:http_user) { should eq 'foo' }
43
+ its(:http_pass) { should be_nil }
44
+ its(:https_user) { should eq 'bar' }
45
+ its(:https_pass) { should be_nil }
46
+ end
47
+
48
+ context "with userinfo" do
49
+ let(:http_proxy) { 'http://foo:bar@proxy.example.com:8123/' }
50
+ let(:https_proxy) { 'http://:baz@localhost' }
51
+
52
+ its(:http_user) { should eq 'foo' }
53
+ its(:http_pass) { should eq 'bar' }
54
+ its(:https_user) { should eq '' }
55
+ its(:https_pass) { should eq 'baz' }
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-proxyconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-04 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Vagrant plugin that configures the virtual machine to use proxies
15
15
  email:
@@ -33,6 +33,7 @@ files:
33
33
  - lib/vagrant-proxyconf.rb
34
34
  - lib/vagrant-proxyconf/action/base.rb
35
35
  - lib/vagrant-proxyconf/action/configure_apt_proxy.rb
36
+ - lib/vagrant-proxyconf/action/configure_chef_proxy.rb
36
37
  - lib/vagrant-proxyconf/action/configure_env_proxy.rb
37
38
  - lib/vagrant-proxyconf/cap/debian/apt_proxy_conf.rb
38
39
  - lib/vagrant-proxyconf/cap/linux/env_proxy_conf.rb
@@ -47,12 +48,15 @@ files:
47
48
  - spec/spec_helper.rb
48
49
  - spec/unit/support/shared/apt_proxy_config.rb
49
50
  - spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb
51
+ - spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb
50
52
  - spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb
51
53
  - spec/unit/vagrant-proxyconf/cap/debian/apt_proxy_conf_spec.rb
54
+ - spec/unit/vagrant-proxyconf/cap/linux/env_proxy_conf_spec.rb
52
55
  - spec/unit/vagrant-proxyconf/config/apt_proxy_spec.rb
53
56
  - spec/unit/vagrant-proxyconf/config/env_proxy_spec.rb
54
57
  - spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb
55
58
  - spec/unit/vagrant-proxyconf/config/key_spec.rb
59
+ - spec/unit/vagrant-proxyconf/config/proxy_spec.rb
56
60
  - spec/unit/vagrant-proxyconf/plugin_spec.rb
57
61
  - vagrant-proxyconf.gemspec
58
62
  homepage: http://tmatilai.github.io/vagrant-proxyconf/
@@ -70,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
74
  version: '0'
71
75
  segments:
72
76
  - 0
73
- hash: 4185901625898732467
77
+ hash: -2294529706068279185
74
78
  required_rubygems_version: !ruby/object:Gem::Requirement
75
79
  none: false
76
80
  requirements:
@@ -79,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  version: '0'
80
84
  segments:
81
85
  - 0
82
- hash: 4185901625898732467
86
+ hash: -2294529706068279185
83
87
  requirements: []
84
88
  rubyforge_project:
85
89
  rubygems_version: 1.8.23
@@ -90,11 +94,14 @@ test_files:
90
94
  - spec/spec_helper.rb
91
95
  - spec/unit/support/shared/apt_proxy_config.rb
92
96
  - spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb
97
+ - spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb
93
98
  - spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb
94
99
  - spec/unit/vagrant-proxyconf/cap/debian/apt_proxy_conf_spec.rb
100
+ - spec/unit/vagrant-proxyconf/cap/linux/env_proxy_conf_spec.rb
95
101
  - spec/unit/vagrant-proxyconf/config/apt_proxy_spec.rb
96
102
  - spec/unit/vagrant-proxyconf/config/env_proxy_spec.rb
97
103
  - spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb
98
104
  - spec/unit/vagrant-proxyconf/config/key_spec.rb
105
+ - spec/unit/vagrant-proxyconf/config/proxy_spec.rb
99
106
  - spec/unit/vagrant-proxyconf/plugin_spec.rb
100
107
  has_rdoc: