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

Add support for SOCKS proxies #207

Merged
merged 1 commit into from
May 21, 2016
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gem "thor", ">= 0.16.0"
gem "json", ">= 0"
gem "terminal-table", ">= 1.4.0"
gem "mixlib-shellout", ">= 1.1.0"
gem 'socksify', ">= 1.7.0"

group :development do
gem "bundler", ">= 1.0"
Expand Down
3 changes: 3 additions & 0 deletions jenkins_api_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<terminal-table>, [">= 1.4.0"])
s.add_runtime_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
s.add_runtime_dependency(%q<socksify>, [">= 1.7.0"])
s.add_development_dependency(%q<bundler>, [">= 1.0"])
s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
s.add_development_dependency(%q<rspec>, ["~> 2.14.1"])
Expand All @@ -115,6 +116,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
s.add_dependency(%q<socksify>, [">= 1.7.0"])
s.add_dependency(%q<bundler>, [">= 1.0"])
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
s.add_dependency(%q<rspec>, ["~> 2.14.1"])
Expand All @@ -129,6 +131,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<terminal-table>, [">= 1.4.0"])
s.add_dependency(%q<mixlib-shellout>, [">= 1.1.0"])
s.add_dependency(%q<socksify>, [">= 1.7.0"])
s.add_dependency(%q<bundler>, [">= 1.0"])
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
s.add_dependency(%q<rspec>, ["~> 2.14.1"])
Expand Down
13 changes: 12 additions & 1 deletion lib/jenkins_api_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require 'mixlib/shellout'
require 'uri'
require 'logger'
require 'socksify/http'

# The main module that contains the Client class and all subclasses that
# communicate with the Jenkins's Remote Access API.
Expand All @@ -53,6 +54,7 @@ class Client
"server_port",
"proxy_ip",
"proxy_port",
"proxy_protocol",
"jenkins_path",
"username",
"password",
Expand Down Expand Up @@ -86,6 +88,7 @@ class Client
# <Server IP>:<Server Port>/user/<Username>/configure
# @option args [String] :proxy_ip the proxy IP address
# @option args [String] :proxy_port the proxy port
# @option args [String] :proxy_protocol the proxy protocol ('socks' or 'http' (defaults to HTTP)
# @option args [String] :jenkins_path ("/") the optional context path for Jenkins
# @option args [Boolean] :ssl (false) indicates if Jenkins is accessible over HTTPS
# @option args [Boolean] :follow_redirects this argument causes the client to follow a redirect (jenkins can
Expand Down Expand Up @@ -146,6 +149,7 @@ def initialize(args)
@http_open_timeout = DEFAULT_HTTP_OPEN_TIMEOUT unless @http_open_timeout
@http_read_timeout = DEFAULT_HTTP_READ_TIMEOUT unless @http_read_timeout
@ssl ||= false
@proxy_protocol ||= 'http'

# Setting log options
if @logger
Expand Down Expand Up @@ -292,7 +296,14 @@ def make_http_request(request, follow_redirect = @follow_redirects)
request['Cookie'] = @cookies if @cookies

if @proxy_ip
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @server_port)
case @proxy_protocol
when 'http'
http = Net::HTTP::Proxy(@proxy_ip, @proxy_port).new(@server_ip, @server_port)
when 'socks'
http = Net::HTTP::SOCKSProxy(@proxy_ip, @proxy_port).start(@server_ip, @server_port)
else
raise "unknwon proxy protocol: '#{@proxy_protocol}'"
end
else
http = Net::HTTP.new(@server_ip, @server_port)
end
Expand Down