-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tmatilai/yum-proxy
Add support for yum proxy configuration
- Loading branch information
Showing
29 changed files
with
523 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
guard 'rspec' do | ||
watch(%r{^spec/unit/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" } | ||
watch(%r{^(resources/.+)\.}) { |m| "spec/unit/vagrant-proxyconf/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require_relative 'base' | ||
require_relative '../resource' | ||
require_relative '../userinfo_uri' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
class Action | ||
# Action for configuring Yum on the guest | ||
class ConfigureYumProxy < Base | ||
def config_name | ||
'yum_proxy' | ||
end | ||
|
||
private | ||
|
||
def configure_machine(machine, config) | ||
tmp = "/tmp/vagrant-proxyconf" | ||
path = config_path(machine) | ||
|
||
machine.communicate.tap do |comm| | ||
comm.upload(ProxyConf.resource("yum_config.awk"), tmp) | ||
comm.sudo("touch #{path}") | ||
comm.sudo("gawk -f #{tmp} #{proxy_params(config)} #{path} > #{path}.new") | ||
comm.sudo("chmod 0644 #{path}.new") | ||
comm.sudo("chown root:root #{path}.new") | ||
comm.sudo("mv #{path}.new #{path}") | ||
comm.sudo("rm #{tmp}") | ||
end | ||
end | ||
|
||
def proxy_params(config) | ||
u = UserinfoURI.new(config.http) | ||
"-v proxy=#{escape(u.uri)} -v user=#{escape(u.user)} -v pass=#{escape(u.pass)}" | ||
end | ||
|
||
# @param value [String, nil] the string to escape for shell usage | ||
def escape(value) | ||
value.to_s.shellescape | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module VagrantPlugins | ||
module ProxyConf | ||
module Cap | ||
module Redhat | ||
# Capability for Yum proxy configuration | ||
module YumProxyConf | ||
# @return [String] the path to the configuration file | ||
def self.yum_proxy_conf(machine) | ||
'/etc/yum.conf' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Yum | ||
# | ||
# @!parse class YumProxy < Vagrant::Plugin::V2::Config; end | ||
class YumProxy < Vagrant.plugin('2', :config) | ||
include KeyMixin | ||
# @!parse extend KeyMixin::ClassMethods | ||
|
||
# @return [String] the HTTP proxy | ||
key :http, env_var: 'VAGRANT_YUM_HTTP_PROXY' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module VagrantPlugins | ||
# Base module for Vagrant Proxyconf plugin | ||
module ProxyConf | ||
# @param name [String] the resource file name | ||
# @return [String] the absolute path to the resource file | ||
def self.resource(name) | ||
File.join(resource_root, name) | ||
end | ||
|
||
private | ||
|
||
# @return [String] the absolute åath to the resource directory | ||
def self.resource_root | ||
File.expand_path('../../../resources', __FILE__) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env gawk | ||
# | ||
# Adds or modifies proxy configuration for Yum | ||
# | ||
# Usage: | ||
# yum_config.awk -v proxy=http://proxy:1234 -v user=foo -v pass=bar /etc/yum.comf | ||
# | ||
# License: MIT | ||
# Copyright (c) 2013 Teemu Matilainen <[email protected]> | ||
# | ||
|
||
BEGIN { | ||
FS = OFS = "=" | ||
|
||
# [main] section: | ||
# 0: not seen yet | ||
# 1: inside of it | ||
# 2: already on another section | ||
main = 0 | ||
|
||
conf["proxy"] = (proxy ? proxy : "_none_") | ||
conf["proxy_username"] = (proxy ? user : "") | ||
conf["proxy_password"] = (proxy ? pass : "") | ||
} | ||
|
||
# Section headers | ||
/^\[.*\]$/ { | ||
if ($0 == "[main]") { | ||
# entering [main] section | ||
main = 1 | ||
} else if (main == 1) { | ||
# [main] section ended | ||
print_proxy_conf() | ||
main = 2 | ||
} | ||
} | ||
|
||
# Old configuration | ||
$1 ~ /^proxy(_username|_password)?$/ { | ||
if (main == 1) { | ||
$2 = conf[$1] | ||
seen[$1] = 1 | ||
} | ||
} | ||
|
||
# Print every line by default | ||
{ print $0 } | ||
|
||
# Print missing configuration if needed | ||
END { | ||
if (main == 0) print "[main]" | ||
if (main < 2) print_proxy_conf() | ||
} | ||
|
||
# Prints proxy* configuration not seen yet | ||
function print_proxy_conf() { | ||
print_key("proxy") | ||
print_key("proxy_username") | ||
print_key("proxy_password") | ||
} | ||
|
||
# Prints a proxy*=<value> line | ||
function print_key(key) { | ||
if (!seen[key]) print key, conf[key] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[main] | ||
proxy=_none_ | ||
proxy_username= | ||
proxy_password= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[main] | ||
cachedir=/var/cache/yum/$basearch/$releasever | ||
keepcache=0 | ||
debuglevel=2 | ||
logfile=/var/log/yum.log | ||
exactarch=1 | ||
obsoletes=1 | ||
gpgcheck=1 | ||
plugins=1 | ||
installonly_limit=5 | ||
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum | ||
distroverpkg=centos-release | ||
|
||
# This is the default, if you make this bigger yum won't see if the metadata | ||
# is newer on the remote and so you'll "gain" the bandwidth of not having to | ||
# download the new metadata and "pay" for it by yum not having correct | ||
# information. | ||
# It is esp. important, to have correct metadata, for distributions like | ||
# Fedora which don't keep old packages around. If you don't like this checking | ||
# interupting your command line usage, it's much better to have something | ||
# manually check the metadata once an hour (yum-updatesd will do this). | ||
# metadata_expire=90m | ||
|
||
# PUT YOUR REPOS HERE OR IN separate files named file.repo | ||
# in /etc/yum.repos.d |
Oops, something went wrong.