vagrant-proxyconf 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -1
- data/Gemfile +1 -1
- data/README.md +52 -18
- data/Rakefile +14 -0
- data/lib/vagrant-proxyconf/action/configure_apt_proxy.rb +2 -0
- data/lib/vagrant-proxyconf/config/apt_proxy.rb +97 -0
- data/lib/vagrant-proxyconf/plugin.rb +21 -4
- data/lib/vagrant-proxyconf/version.rb +1 -1
- data/spec/unit/vagrant-proxyconf/{apt_proxy_config_spec.rb → config/apt_proxy_spec.rb} +5 -3
- data/spec/unit/vagrant-proxyconf/plugin_spec.rb +42 -0
- data/vagrant-proxyconf.gemspec +1 -1
- metadata +10 -9
- data/lib/vagrant-proxyconf/action.rb +0 -1
- data/lib/vagrant-proxyconf/apt_proxy_config.rb +0 -88
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
# 0.2.0 / 2013-07-05
|
2
|
+
|
3
|
+
- Add Apt proxy configuration for FTP URIs ([GH-5][])
|
4
|
+
- Warn and fail if Vagrant is older than v1.2.0 ([GH-7][])
|
5
|
+
- New [home page](http://tmatilai.github.io/vagrant-proxyconf/) ([GH-8][])
|
6
|
+
|
1
7
|
# 0.1.1 / 2013-06-27
|
2
8
|
|
3
|
-
- Don't crash if there is no configuration for us in the Vagrantfiles ([GH-2])
|
9
|
+
- Don't crash if there is no configuration for us in the Vagrantfiles ([GH-2][])
|
4
10
|
* Related [Vagrant issue](https://github.com/mitchellh/vagrant/issues/1877)
|
5
11
|
|
6
12
|
# 0.1.0 / 2013-06-27
|
@@ -11,3 +17,6 @@
|
|
11
17
|
|
12
18
|
|
13
19
|
[GH-2]: https://github.com/tmatilai/vagrant-proxyconf/issues/2 "Issue 2"
|
20
|
+
[GH-5]: https://github.com/tmatilai/vagrant-proxyconf/issues/5 "Issue 5"
|
21
|
+
[GH-7]: https://github.com/tmatilai/vagrant-proxyconf/issues/7 "Issue 7"
|
22
|
+
[GH-8]: https://github.com/tmatilai/vagrant-proxyconf/issues/8 "Issue 8"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Vagrant Proxy Configuration Plugin
|
2
2
|
|
3
|
+
<span class="badges">
|
3
4
|
[![Gem Version](https://badge.fury.io/rb/vagrant-proxyconf.png)][gem]
|
4
5
|
[![Build Status](https://travis-ci.org/tmatilai/vagrant-proxyconf.png?branch=master)][travis]
|
5
6
|
[![Dependency Status](https://gemnasium.com/tmatilai/vagrant-proxyconf.png)][gemnasium]
|
@@ -9,52 +10,85 @@
|
|
9
10
|
[travis]: https://travis-ci.org/tmatilai/vagrant-proxyconf
|
10
11
|
[gemnasium]: https://gemnasium.com/tmatilai/vagrant-proxyconf
|
11
12
|
[codeclimate]: https://codeclimate.com/github/tmatilai/vagrant-proxyconf
|
13
|
+
</span>
|
12
14
|
|
13
|
-
A [Vagrant](http://www.vagrantup.com/)
|
15
|
+
A [Vagrant](http://www.vagrantup.com/) plugin that configures the virtual machine to use specified proxies for package managers etc.
|
14
16
|
|
15
17
|
At this state we support:
|
16
18
|
|
17
|
-
|
19
|
+
* [APT](http://en.wikipedia.org/wiki/Advanced_Packaging_Tool) proxy/cacher
|
18
20
|
|
19
21
|
Support is planned for other package managers (at least yum).
|
20
22
|
|
21
|
-
##
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
**Note:** This plugin requires Vagrant v1.2 or newer ([downloads](http://downloads.vagrantup.com/)).
|
26
|
+
|
27
|
+
Install using standard Vagrant plugin installation method:
|
22
28
|
|
23
|
-
Install using standard Vagrant 1.1+ plugin installation method:
|
24
29
|
```sh
|
25
30
|
vagrant plugin install vagrant-proxyconf
|
26
31
|
```
|
27
32
|
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Proxy settings can be configured in Vagrantfile. In the common case that you want to use the same configuration in all Vagrant machines, you can use _$HOME/.vagrant.d/Vagrantfile_ or environment variables. Package manager specific settings are only used on supporting platforms (i.e. Apt configuration on Debian based systems), so there is no harm using global configuration.
|
36
|
+
|
37
|
+
Project specific Vagrantfile overrides global settings. Environment variables override both.
|
38
|
+
|
28
39
|
### Apt
|
29
40
|
|
30
|
-
|
41
|
+
Configures Apt to use the specified proxy settings. The configuration will be written to _/etc/apt/apt.conf.d/01proxy_ on the guest.
|
42
|
+
|
43
|
+
#### Example Vagrantfile
|
31
44
|
|
32
|
-
Example configuration:
|
33
45
|
```ruby
|
34
46
|
Vagrant.configure("2") do |config|
|
35
|
-
|
36
|
-
config.apt_proxy.
|
37
|
-
|
47
|
+
config.apt_proxy.http = "192.168.33.1:3142"
|
48
|
+
config.apt_proxy.https = "DIRECT"
|
38
49
|
# ... other stuff
|
39
50
|
end
|
40
51
|
```
|
41
52
|
|
42
|
-
|
53
|
+
#### Configuration keys
|
54
|
+
|
55
|
+
* `config.apt_proxy.http` - The proxy for HTTP URIs
|
56
|
+
* `config.apt_proxy.https` - The proxy for HTTPS URIs
|
57
|
+
* `config.apt_proxy.ftp` - The proxy for FTP URIs
|
58
|
+
|
59
|
+
#### Possible values
|
60
|
+
|
61
|
+
* If all keys are unset or `nil`, no configuration is written.
|
62
|
+
* 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 protocol is the same as the key.
|
63
|
+
* Empty string (`""`) or `false` in any protocol also force the configuration file to be written, but without configuration for that protocol. Can be used to clear the old configuration and/or override a global setting.
|
64
|
+
* `"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).
|
65
|
+
* Please refer to [apt.conf(5)](http://manpages.debian.net/man/5/apt.conf) manual for more information.
|
66
|
+
|
67
|
+
#### Environment variables
|
68
|
+
|
69
|
+
* `APT_PROXY_HTTP`
|
70
|
+
* `APT_PROXY_HTTPS`
|
71
|
+
* `APT_PROXY_FTP`
|
72
|
+
|
73
|
+
These also override the Vagrantfile configuration. To disable or remove the proxy use "DIRECT" or an empty value.
|
74
|
+
|
75
|
+
For example to spin up a VM, run:
|
43
76
|
|
44
|
-
You can also use `APT_PROXY_HTTP` and `APT_PROXY_HTTPS` environment variables. These override the Vagrantfile configuration. To disable or remove the proxy use "DIRECT" or an empty value. For example to spin up a VM while overriding a globally configured proxy, run:
|
45
77
|
```sh
|
46
|
-
APT_PROXY_HTTP="
|
78
|
+
APT_PROXY_HTTP="proxy.example.com:8080" vagrant up
|
47
79
|
```
|
48
80
|
|
49
|
-
Proxy settings will be written to _/etc/apt/apt.conf.d/01proxy_ on the guest.
|
50
|
-
|
51
81
|
#### Running apt-cacher-ng on a Vagrant box
|
52
82
|
|
53
83
|
[Here](https://github.com/tmatilai/apt-cacher-box) is an example for setting up apt-cacher proxy server in a Vagrant VM.
|
54
84
|
|
55
85
|
## Related plugins and projects
|
56
86
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
87
|
+
* [apt-cacher-box](https://github.com/tmatilai/apt-cacher-box)<br/>
|
88
|
+
a Vagrant setup for apt-cacher-ng.
|
89
|
+
* [vagrant-cachier](https://github.com/fgrehm/vagrant-cachier)<br/>
|
90
|
+
An excellent Vagrant plugin that shares various cache directories among similar VM instances. Should work fine together with vagrant-proxyconf.
|
91
|
+
* [vagrant-httpproxy](https://github.com/juliandunn/vagrant-httpproxy)<br/>
|
92
|
+
A Chef cookbook for configuring Chef resources to use the specified proxy (while offline).
|
93
|
+
* [vagrant-proxy](https://github.com/clintoncwolfe/vagrant-proxy)<br/>
|
94
|
+
A Vagrant plugin that uses iptables rules to force the VM to use a proxy.
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ namespace :test do
|
|
14
14
|
end
|
15
15
|
desc "Run all tests"
|
16
16
|
task :test => ['test:unit']
|
17
|
+
task :spec => :test
|
17
18
|
|
18
19
|
Tailor::RakeTask.new do |task|
|
19
20
|
task.file_set('lib/**/*.rb', 'code') do |style|
|
@@ -26,3 +27,16 @@ Tailor::RakeTask.new do |task|
|
|
26
27
|
style.spaces_before_lbrace 1, level: :off
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
desc "Update gh-pages"
|
32
|
+
task 'gh-pages' do
|
33
|
+
require 'tmpdir'
|
34
|
+
|
35
|
+
rev = `git rev-parse HEAD`.chomp
|
36
|
+
Dir.mktmpdir do |clone|
|
37
|
+
sh %Q{git clone --branch gh-pages "#{File.expand_path('..', __FILE__)}" "#{clone}"}
|
38
|
+
Dir.chdir(clone) do
|
39
|
+
sh %Q{_bin/update "#{rev}"}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProxyConf
|
5
|
+
module Config
|
6
|
+
class AptProxy < Vagrant.plugin('2', :config)
|
7
|
+
# HTTP proxy for Apt
|
8
|
+
attr_accessor :http
|
9
|
+
|
10
|
+
# HTTPS proxy for Apt
|
11
|
+
attr_accessor :https
|
12
|
+
|
13
|
+
# FTP proxy for Apt
|
14
|
+
attr_accessor :ftp
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@http = UNSET_VALUE
|
18
|
+
@https = UNSET_VALUE
|
19
|
+
@ftp = UNSET_VALUE
|
20
|
+
end
|
21
|
+
|
22
|
+
def finalize!
|
23
|
+
@http = override_from_env_var('http', @http)
|
24
|
+
@http = nil if @http == UNSET_VALUE
|
25
|
+
|
26
|
+
@https = override_from_env_var('https', @https)
|
27
|
+
@https = nil if @https == UNSET_VALUE
|
28
|
+
|
29
|
+
@ftp = override_from_env_var('ftp', @ftp)
|
30
|
+
@ftp = nil if @ftp == UNSET_VALUE
|
31
|
+
end
|
32
|
+
|
33
|
+
def enabled?
|
34
|
+
!http.nil? || !https.nil? || !ftp.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String] the full configuration stanza
|
38
|
+
def to_s
|
39
|
+
%w[http https ftp].map { |proto| config_for(proto) }.join
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def override_from_env_var(proto, default)
|
45
|
+
ENV.fetch("APT_PROXY_#{proto.upcase}", default)
|
46
|
+
end
|
47
|
+
|
48
|
+
def config_for(proto)
|
49
|
+
ConfigValue.new(proto, send(proto.to_sym))
|
50
|
+
end
|
51
|
+
|
52
|
+
class ConfigValue
|
53
|
+
|
54
|
+
attr_reader :proto, :value
|
55
|
+
|
56
|
+
# @param proto [String] the protocol ("http", "https", ...)
|
57
|
+
# @param value [Object] the configuration value
|
58
|
+
def initialize(proto, value)
|
59
|
+
@proto = proto
|
60
|
+
@value = value
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String] the full Apt configuration line
|
64
|
+
def to_s
|
65
|
+
set? ? %Q{Acquire::#{proto}::Proxy "#{proxy_uri}";\n} : ""
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def set?
|
71
|
+
value && !value.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def direct?
|
75
|
+
value.upcase == "DIRECT"
|
76
|
+
end
|
77
|
+
|
78
|
+
def proxy_uri
|
79
|
+
direct? ? "DIRECT" : "#{prefix}#{value}#{suffix}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def prefix
|
83
|
+
"#{proto}://" if value !~ %r{^.*://}
|
84
|
+
end
|
85
|
+
|
86
|
+
def suffix
|
87
|
+
":#{default_port}" if value !~ %r{:\d+$}
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_port
|
91
|
+
3142
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -3,11 +3,28 @@ require 'vagrant'
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module ProxyConf
|
5
5
|
class Plugin < Vagrant.plugin('2')
|
6
|
+
# The minimum compatible Vagrant version
|
7
|
+
MIN_VAGRANT_VERSION = '1.2.0'
|
8
|
+
|
9
|
+
# Verifies that the Vagrant version fulfills the requirements
|
10
|
+
#
|
11
|
+
# @raise [VagrantPlugins::ProxyConf::VagrantVersionError] if this plugin
|
12
|
+
# is incompatible with the Vagrant version
|
13
|
+
def self.check_vagrant_version!
|
14
|
+
if Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(MIN_VAGRANT_VERSION)
|
15
|
+
msg = "vagrant-proxyconf plugin requires Vagrant #{MIN_VAGRANT_VERSION} or newer"
|
16
|
+
$stderr.puts msg
|
17
|
+
raise msg
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
check_vagrant_version!
|
22
|
+
|
6
23
|
name 'vagrant-proxyconf'
|
7
24
|
|
8
|
-
config
|
9
|
-
require_relative '
|
10
|
-
|
25
|
+
config 'apt_proxy' do
|
26
|
+
require_relative 'config/apt_proxy'
|
27
|
+
Config::AptProxy
|
11
28
|
end
|
12
29
|
|
13
30
|
guest_capability 'debian', 'apt_proxy_conf' do
|
@@ -16,7 +33,7 @@ module VagrantPlugins
|
|
16
33
|
end
|
17
34
|
|
18
35
|
proxyconf_action_hook = lambda do |hook|
|
19
|
-
require_relative 'action'
|
36
|
+
require_relative 'action/configure_apt_proxy'
|
20
37
|
hook.after Vagrant::Action::Builtin::Provision, Action::ConfigureAptProxy
|
21
38
|
end
|
22
39
|
action_hook 'proxyconf-machine-up', :machine_action_up, &proxyconf_action_hook
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'unit/support/shared/apt_proxy_config'
|
3
|
-
require 'vagrant-proxyconf/
|
3
|
+
require 'vagrant-proxyconf/config/apt_proxy'
|
4
4
|
|
5
|
-
describe VagrantPlugins::ProxyConf::
|
5
|
+
describe VagrantPlugins::ProxyConf::Config::AptProxy do
|
6
6
|
let(:instance) { described_class.new }
|
7
7
|
|
8
8
|
before :each do
|
9
9
|
# Ensure tests are not affected by environment variables
|
10
|
-
%w[APT_PROXY_HTTP APT_PROXY_HTTPS].each { |k| ENV.delete(k) }
|
10
|
+
%w[APT_PROXY_HTTP APT_PROXY_HTTPS APT_PROXY_FTP].each { |k| ENV.delete(k) }
|
11
11
|
end
|
12
12
|
|
13
13
|
context "defaults" do
|
@@ -18,6 +18,7 @@ describe VagrantPlugins::ProxyConf::AptProxyConfig do
|
|
18
18
|
|
19
19
|
include_examples "apt proxy config", "http"
|
20
20
|
include_examples "apt proxy config", "https"
|
21
|
+
include_examples "apt proxy config", "ftp"
|
21
22
|
|
22
23
|
context "with both http and https proxies" do
|
23
24
|
subject { config_with(http: "10.2.3.4", https: "ssl-proxy:8443") }
|
@@ -29,6 +30,7 @@ describe VagrantPlugins::ProxyConf::AptProxyConfig do
|
|
29
30
|
context "with env var" do
|
30
31
|
include_examples "apt proxy env var", "APT_PROXY_HTTP", "http"
|
31
32
|
include_examples "apt proxy env var", "APT_PROXY_HTTPS", "https"
|
33
|
+
include_examples "apt proxy env var", "APT_PROXY_FTP", "ftp"
|
32
34
|
end
|
33
35
|
|
34
36
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vagrant-proxyconf/plugin'
|
3
|
+
|
4
|
+
describe VagrantPlugins::ProxyConf::Plugin do
|
5
|
+
|
6
|
+
describe ".check_vagrant_version!" do
|
7
|
+
let(:min_vagrant_verision) { '1.2.3' }
|
8
|
+
let(:err_msg) { /requires Vagrant #{min_vagrant_verision}/ }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
stub_const('VagrantPlugins::ProxyConf::Plugin::MIN_VAGRANT_VERSION', min_vagrant_verision)
|
12
|
+
stub_const('Vagrant::VERSION', vagrant_version)
|
13
|
+
$stderr.stub(:puts)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "on too old Vagrant version" do
|
17
|
+
let(:vagrant_version) { '1.1.5' }
|
18
|
+
it "raises" do
|
19
|
+
expect { described_class.check_vagrant_version! }.to raise_error(err_msg)
|
20
|
+
end
|
21
|
+
it "warns" do
|
22
|
+
$stderr.should_receive(:puts).with(err_msg)
|
23
|
+
described_class.check_vagrant_version! rescue nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on exact required Vagrant version" do
|
28
|
+
let(:vagrant_version) { min_vagrant_verision }
|
29
|
+
it "does not raise" do
|
30
|
+
expect { described_class.check_vagrant_version! }.not_to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "on newer Vagrant version" do
|
35
|
+
let(:vagrant_version) { '1.3.5' }
|
36
|
+
it "does not raise" do
|
37
|
+
expect { described_class.check_vagrant_version! }.not_to raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/vagrant-proxyconf.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["teemu.matilainen@iki.fi"]
|
11
11
|
spec.description = "A Vagrant Plugin that configures the virtual machine to use proxies"
|
12
12
|
spec.summary = spec.description
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "http://tmatilai.github.io/vagrant-proxyconf/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
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
|
+
version: 0.2.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-
|
12
|
+
date: 2013-07-05 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:
|
@@ -30,17 +30,17 @@ files:
|
|
30
30
|
- development/README.md
|
31
31
|
- development/Vagrantfile.example
|
32
32
|
- lib/vagrant-proxyconf.rb
|
33
|
-
- lib/vagrant-proxyconf/action.rb
|
34
33
|
- lib/vagrant-proxyconf/action/configure_apt_proxy.rb
|
35
|
-
- lib/vagrant-proxyconf/apt_proxy_config.rb
|
36
34
|
- lib/vagrant-proxyconf/cap/debian/apt_proxy_conf.rb
|
35
|
+
- lib/vagrant-proxyconf/config/apt_proxy.rb
|
37
36
|
- lib/vagrant-proxyconf/plugin.rb
|
38
37
|
- lib/vagrant-proxyconf/version.rb
|
39
38
|
- spec/spec_helper.rb
|
40
39
|
- spec/unit/support/shared/apt_proxy_config.rb
|
41
|
-
- spec/unit/vagrant-proxyconf/
|
40
|
+
- spec/unit/vagrant-proxyconf/config/apt_proxy_spec.rb
|
41
|
+
- spec/unit/vagrant-proxyconf/plugin_spec.rb
|
42
42
|
- vagrant-proxyconf.gemspec
|
43
|
-
homepage:
|
43
|
+
homepage: http://tmatilai.github.io/vagrant-proxyconf/
|
44
44
|
licenses:
|
45
45
|
- MIT
|
46
46
|
post_install_message:
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: -654121375063372740
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: -654121375063372740
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
70
|
rubygems_version: 1.8.23
|
@@ -74,4 +74,5 @@ summary: A Vagrant Plugin that configures the virtual machine to use proxies
|
|
74
74
|
test_files:
|
75
75
|
- spec/spec_helper.rb
|
76
76
|
- spec/unit/support/shared/apt_proxy_config.rb
|
77
|
-
- spec/unit/vagrant-proxyconf/
|
77
|
+
- spec/unit/vagrant-proxyconf/config/apt_proxy_spec.rb
|
78
|
+
- spec/unit/vagrant-proxyconf/plugin_spec.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative 'action/configure_apt_proxy'
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'vagrant'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module ProxyConf
|
5
|
-
class AptProxyConfig < Vagrant.plugin('2', :config)
|
6
|
-
# HTTP proxy for Apt
|
7
|
-
attr_accessor :http
|
8
|
-
|
9
|
-
# HTTPS proxy for Apt
|
10
|
-
attr_accessor :https
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@http = UNSET_VALUE
|
14
|
-
@https = UNSET_VALUE
|
15
|
-
end
|
16
|
-
|
17
|
-
def finalize!
|
18
|
-
@http = override_from_env_var('http', @http)
|
19
|
-
@http = nil if @http == UNSET_VALUE
|
20
|
-
|
21
|
-
@https = override_from_env_var('https', @https)
|
22
|
-
@https = nil if @https == UNSET_VALUE
|
23
|
-
end
|
24
|
-
|
25
|
-
def enabled?
|
26
|
-
!http.nil? || !https.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [String] the full configuration stanza
|
30
|
-
def to_s
|
31
|
-
"#{config_for('http')}#{config_for('https')}"
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def override_from_env_var(proto, default)
|
37
|
-
ENV.fetch("APT_PROXY_#{proto.upcase}", default)
|
38
|
-
end
|
39
|
-
|
40
|
-
def config_for(proto)
|
41
|
-
ConfigValue.new(proto, send(proto.to_sym))
|
42
|
-
end
|
43
|
-
|
44
|
-
class ConfigValue
|
45
|
-
|
46
|
-
attr_reader :proto, :value
|
47
|
-
|
48
|
-
# @param proto [String] the protocol ("http", "https")
|
49
|
-
# @param value [Object] the configuration value
|
50
|
-
def initialize(proto, value)
|
51
|
-
@proto = proto
|
52
|
-
@value = value
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [String] the full Apt configuration line
|
56
|
-
def to_s
|
57
|
-
set? ? %Q{Acquire::#{proto}::Proxy "#{proxy_uri}";\n} : ""
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def set?
|
63
|
-
value && !value.empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
def direct?
|
67
|
-
value.upcase == "DIRECT"
|
68
|
-
end
|
69
|
-
|
70
|
-
def proxy_uri
|
71
|
-
direct? ? "DIRECT" : "#{prefix}#{value}#{suffix}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def prefix
|
75
|
-
"#{proto}://" if value !~ %r{^.*://}
|
76
|
-
end
|
77
|
-
|
78
|
-
def suffix
|
79
|
-
":#{default_port}" if value !~ %r{:\d+$}
|
80
|
-
end
|
81
|
-
|
82
|
-
def default_port
|
83
|
-
3142
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|