Skip to content

Commit

Permalink
remove debug puts statments and make Gem::ConfigFile canges non depen…
Browse files Browse the repository at this point in the history
…dant on rubygems version
  • Loading branch information
zebardy committed Dec 19, 2013
1 parent a1d4562 commit f30601d
Showing 1 changed file with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions lib/rubygems_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
require 'rubygems/remote_fetcher'

$stderr.puts "rubygems ssl client certs plugin loading"
class Gem::ConfigFile

if Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.1.0') then

class Gem::ConfigFile

attr_reader :ssl_client_cert
attr_reader :ssl_client_cert

attr_reader :ssl_verify_mode
attr_reader :ssl_verify_mode

attr_reader :ssl_ca_cert
$stderr.puts "loading Gem::ConfigFile monkey patch"

class << self
unless self.method_defined? :__new__
$stderr.puts "aliasing new to __new__"
alias_method :__new__, :new
end

def new(*args)
$stderr.puts "instantiating new Gem::ConfigFile with patch"
config = __new__(*args)
config.set_ssl_vars
return config
end
attr_reader :ssl_ca_cert

class << self
unless self.method_defined? :__new__
alias_method :__new__, :new
end

def set_ssl_vars
$stderr.puts "Configuring SSL variables for Gem::ConfigFile"
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
@ssl_ca_cert = ENV['BUNDLE_SSL_CA_CERT'] unless @ssl_ca_cert
@ssl_client_cert = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
@ssl_client_cert = ENV['BUNDLE_SSL_CLIENT_CERT'] unless @ssl_client_cert
def new(*args)
config = __new__(*args)
config.set_ssl_vars
return config
end

if Gem.instance_variable_get(:@configuration) then
$stderr.puts "forcing a reload of the Gem configuration"
Gem.configuration = nil
end
end

def set_ssl_vars
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
@ssl_ca_cert = ENV['BUNDLE_SSL_CA_CERT'] unless @ssl_ca_cert
@ssl_client_cert = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
@ssl_client_cert = ENV['BUNDLE_SSL_CLIENT_CERT'] unless @ssl_client_cert
end

if Gem.instance_variable_get(:@configuration) then
Gem.configuration = nil
end

end

if Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.1.0') then

class Gem::RemoteFetcher

def connection_for(uri)
Expand Down Expand Up @@ -85,11 +78,6 @@ def configure_connection_for_https(connection)
pem = File.read(Gem.configuration.ssl_client_cert)
connection.cert = OpenSSL::X509::Certificate.new(pem)
connection.key = OpenSSL::PKey::RSA.new(pem)
else
puts "no Client Cert configured!"
if !Gem.configuration.respond_to?(:ssl_client_cert)
puts "Loaded Gem::ConfigFile does not support ssl_client_cert"
end
end

if Gem.configuration.ssl_ca_cert
Expand All @@ -99,7 +87,6 @@ def configure_connection_for_https(connection)
store.add_file Gem.configuration.ssl_ca_cert
end
else
puts "no CA Cert configured!"
store.set_default_paths
add_rubygems_trusted_certs(store)
end
Expand Down

0 comments on commit f30601d

Please sign in to comment.