-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add support for Git/Svn proxy through system config. #40
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
require_relative 'action/configure_env_proxy' | ||
require_relative 'action/configure_pear_proxy' | ||
require_relative 'action/configure_yum_proxy' | ||
require_relative 'action/configure_git_proxy' | ||
require_relative 'action/configure_svn_proxy' | ||
require_relative 'action/is_enabled' | ||
require_relative 'action/only_once' | ||
|
||
|
@@ -48,6 +50,8 @@ def self.config_actions | |
b2.use ConfigureEnvProxy | ||
b2.use ConfigurePearProxy | ||
b2.use ConfigureYumProxy | ||
b2.use ConfigureGitProxy | ||
b2.use ConfigureSvnProxy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please maintain alphabetic order. And add these also to |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,12 @@ def write_config(config, opts = {}) | |
comm.sudo("chmod #{opts[:mode] || '0644'} #{tmp}") | ||
comm.sudo("chown #{opts[:owner] || 'root:root'} #{tmp}") | ||
comm.sudo("mkdir -p #{File.dirname(path)}") | ||
comm.sudo("mv #{tmp} #{path}") | ||
|
||
if opts[:append] | ||
comm.sudo("cat #{tmp} | tee -a #{path}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First, |
||
else | ||
comm.sudo("mv #{tmp} #{path}") | ||
end | ||
end | ||
end | ||
|
||
|
@@ -114,6 +119,11 @@ def supported? | |
def config_path | ||
@machine.guest.capability(cap_name) | ||
end | ||
|
||
# @param value [String, nil] the string to escape for shell usage | ||
def escape(value) | ||
value.to_s.shellescape | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method was already moved here in another PR. |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require_relative 'base' | ||
require_relative '../resource' | ||
require_relative '../userinfo_uri' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
class Action | ||
# Action for configuring Git on the guest | ||
class ConfigureGitProxy < Base | ||
def config_name | ||
'git_proxy' | ||
end | ||
|
||
private | ||
|
||
def configure_machine | ||
if @machine.guest.capability(:git_proxy_conf) | ||
@machine.communicate.sudo("git config --system http.proxy #{config.http}") | ||
else | ||
write_config(git_config, path: '/etc/gitconfig', append: true) | ||
end | ||
end | ||
|
||
def git_config | ||
(<<-CONFIG) | ||
|
||
[http] | ||
proxy = "#{config.http}" | ||
CONFIG | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative 'base' | ||
require_relative '../resource' | ||
require 'uri' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
class Action | ||
# Action for configuring Svn on the guest | ||
class ConfigureSvnProxy < Base | ||
def config_name | ||
'svn_proxy' | ||
end | ||
|
||
private | ||
|
||
def configure_machine | ||
write_config(svn_config, path: '/etc/subversion/servers') | ||
end | ||
|
||
def svn_config | ||
uri = URI.parse(config.http) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a helper class/module for this. IIRC the yum action uses it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall there was an issue with how the helper stripped information. I originally tried to use it. I can take a look at it again. |
||
user = uri.user | ||
pass = uri.password | ||
config = (<<-CONFIG) | ||
[global] | ||
http-proxy-host=#{uri.host} | ||
http-proxy-port=#{uri.port} | ||
CONFIG | ||
|
||
config.concat("http-proxy-username=#{user}") if user | ||
config.concat("http-proxy-password=#{pass}") if pass | ||
config | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module VagrantPlugins | ||
module ProxyConf | ||
module Cap | ||
module Linux | ||
# Capability for Git command | ||
module GitProxyConf | ||
def self.git_proxy_conf(machine) | ||
machine.communicate.test('sudo which git') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module VagrantPlugins | ||
module ProxyConf | ||
module Cap | ||
module Linux | ||
# Capability for Svn command | ||
module SvnProxyConf | ||
def self.svn_proxy_conf(machine) | ||
machine.communicate.test('test -d /etc/subversion') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'vagrant' | ||
require_relative 'key_mixin' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
module Config | ||
# Proxy configuration for Git | ||
# | ||
# @!parse class GitProxy < Vagrant::Plugin::V2::Config; end | ||
class GitProxy < Vagrant.plugin('2', :config) | ||
include KeyMixin | ||
# @!parse extend KeyMixin::ClassMethods | ||
|
||
# @return [String] the HTTP proxy | ||
key :http, env_var: 'VAGRANT_GIT_HTTP_PROXY' | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'vagrant' | ||
require_relative 'key_mixin' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
module Config | ||
# Proxy configuration for Subversion | ||
# | ||
# @!parse class SvnProxy < Vagrant::Plugin::V2::Config; end | ||
class SvnProxy < Vagrant.plugin('2', :config) | ||
include KeyMixin | ||
# @!parse extend KeyMixin::ClassMethods | ||
|
||
# @return [String] the HTTP proxy | ||
key :http, env_var: 'VAGRANT_SVN_HTTP_PROXY' | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/action/configure_git_proxy' | ||
|
||
describe VagrantPlugins::ProxyConf::Action::ConfigureGitProxy do | ||
|
||
describe '#config_name' do | ||
subject { described_class.new(double, double).config_name } | ||
it { should eq 'git_proxy' } | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/action/configure_svn_proxy' | ||
|
||
describe VagrantPlugins::ProxyConf::Action::ConfigureSvnProxy do | ||
|
||
describe '#config_name' do | ||
subject { described_class.new(double, double).config_name } | ||
it { should eq 'svn_proxy' } | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/cap/linux/git_proxy_conf' | ||
|
||
describe VagrantPlugins::ProxyConf::Git::Linux::EnvProxyConf do | ||
|
||
describe '.git_proxy_conf' do | ||
let(:subject) { described_class.git_proxy_conf(double) } | ||
it { should eq 0 } | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/config/git_proxy' | ||
|
||
describe VagrantPlugins::ProxyConf::Config::GitProxy do | ||
let(:instance) { described_class.new } | ||
before(:each) { ENV.delete('VAGRANT_GIT_HTTP_PROXY') } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/config/svn_proxy' | ||
|
||
describe VagrantPlugins::ProxyConf::Config::SvnProxy do | ||
let(:instance) { described_class.new } | ||
before(:each) { ENV.delete('VAGRANT_SVN_HTTP_PROXY') } | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please maintain alphabetic order.