Skip to content

Commit

Permalink
Merge pull request #207 from dylanmckay/socks-proxy
Browse files Browse the repository at this point in the history
Add support for SOCKS proxies
  • Loading branch information
arangamani committed May 21, 2016
2 parents d478f8a + ac0df18 commit 7f44f69
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
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

0 comments on commit 7f44f69

Please sign in to comment.