Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable specific applications #93

Merged
merged 4 commits into from
Nov 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,21 @@ VAGRANT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up

### Disabling the plugin

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.
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.
Specific applications can be skipped by setting `config.proxy.enabled` to
a hash( like `{ svn: false }`).
This disabling keeps proxy configurations for applications on the guest.
The configurations must be cleared before disabling if needed.

```ruby
config.proxy.enabled # => all applications enabled(default)
config.proxy.enabled = true # => all applications enabled
config.proxy.enabled = { svn: false, docker: false }
# => specific applications disabled
config.proxy.enabled = "" # => all applications disabled
config.proxy.enabled = false # => all applications disabled
```

#### Example Vagrantfile

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Tailor::RakeTask.new do |task|
style.max_line_length 120, level: :warn
# allow vertical alignment of `let(:foo) { block }` blocks
style.spaces_before_lbrace 1, level: :off
style.indentation_spaces 2, level: :off
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/vagrant-proxyconf/action/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(app, env)
def call(env)
@machine = env[:machine]

if !config.enabled?
if disabled?
logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_enabled")
elsif !supported?
logger.info I18n.t("vagrant_proxyconf.#{config_name}.not_supported")
Expand Down Expand Up @@ -106,6 +106,16 @@ def cap_name
"#{config_name}_conf".to_sym
end

def disabled?
enabled = @machine.config.proxy.enabled
return true if enabled == false || enabled == ''

app_name = config_name.gsub(/_proxy/, '').to_sym
return enabled[app_name] == false if enabled.respond_to?(:key)

!config.enabled?
end

def supported?
@machine.guest.capability?(cap_name) &&
@machine.guest.capability(cap_name)
Expand Down
74 changes: 74 additions & 0 deletions spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,78 @@
it { is_expected.to eq 'env_proxy' }
end

describe '#disabled?' do
subject do
conf = described_class.new(double, double)
allow(conf).to receive_message_chain(:config, :enabled?)
.and_return(@config_enabled)
machine = double('machine')
allow(machine).to receive_message_chain(:config, :proxy, :enabled)
.and_return(@config_proxy_enabled)
conf.instance_variable_set(:@machine, machine)
conf.send(:disabled?)
end

context 'when both config and proxy are enabled' do
it do
@config_enabled = true
@config_proxy_enabled = true
is_expected.to eq false
end
end
context 'when config is enabled and config proxy is not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = false
is_expected.to eq true
end
end
context 'when config is enabled and config proxy is empty string' do
it do
@config_enabled = true
@config_proxy_enabled = ''
is_expected.to eq true
end
end
context 'when config is not enabled and proxy is enabled' do
it do
@config_enabled = false
@config_proxy_enabled = true
is_expected.to eq true
end
end

context 'when both config and target proxy are enabled' do
it do
@config_enabled = true
@config_proxy_enabled = { env: true }
is_expected.to eq false
end
end
context 'when config is enabled and target proxy target is not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = { env: false }
is_expected.to eq true
end
end
context 'when config is enabled and other proxy are not enabled' do
it do
@config_enabled = true
@config_proxy_enabled = {
svn: false,
apt: false,
chef: false,
docker: false,
git: false,
npm: false,
pear: false,
svn: false,
yum: false
}
is_expected.to eq false
end

end
end
end