Commit 7d8dd901 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added a proxy check and environment variables to info rake task

parent 9ba46172
module Gitlab
class Proxy
class << self
# Try to detect possible proxies defined in the OS
# @return [Hash] of ENV variables that ends with '_proxy' case-insensitive
def detect_proxy
env.select { |k, v| /_proxy$/i =~ k }
end
private
def env
ENV
end
end
end
end
......@@ -15,10 +15,13 @@ namespace :gitlab do
rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s)
# check redis version
redis_version = run_and_match(%W(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a
# check for system defined proxies
proxies = Gitlab::Proxy.detect_proxy.map{|k,v| "#{k}: #{v}"}.join("\n\t\t")
puts ""
puts "System information".color(:yellow)
puts "System:\t\t#{os_name || "unknown".color(:red)}"
puts "Proxy:\t\t#{proxies.present? ? proxies.color(:green) : "no"}"
puts "Current User:\t#{run_command(%W(whoami))}"
puts "Using RVM:\t#{rvm_version.present? ? "yes".color(:green) : "no"}"
puts "RVM Version:\t#{rvm_version}" if rvm_version.present?
......@@ -84,6 +87,9 @@ namespace :gitlab do
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
puts ""
puts "Environment Variables".color(:yellow)
puts ENV.map{|k,v| %Q(#{k}="#{v}")}.join("\n")
end
end
end
require 'spec_helper'
describe Gitlab::Proxy do
describe '.detect_proxy' do
subject { described_class.detect_proxy }
context 'without any existing proxies' do
before do
allow(described_class).to receive(:env).and_return({})
end
it 'returns an empty array' do
expect(subject).to be_empty
end
end
context 'with existing proxies' do
before do
stubbed_env = { 'http_proxy' => 'http://proxy.example.com',
'HTTPS_PROXY' => 'https://proxy.example.com',
'http_notaproxy' => 'http://example.com' }
allow(described_class).to receive(:env).and_return(stubbed_env)
end
it 'returns a list of existing proxies' do
aggregate_failures 'list of proxies' do
expect(subject).to include('http_proxy')
expect(subject).to include('HTTPS_PROXY')
expect(subject).not_to include('http_notaproxy')
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment