Class: Bundler::SSLCerts::CertificateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/ssl_certs/certificate_manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rubygems_path = nil) ⇒ CertificateManager

Returns a new instance of CertificateManager.



16
17
18
19
20
21
22
23
24
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 16

def initialize(rubygems_path = nil)
  if rubygems_path
    rubygems_cert_path = File.join(rubygems_path, "lib/rubygems/ssl_certs")
    @rubygems_certs = certificates_in(rubygems_cert_path)
  end

  @bundler_cert_path = File.expand_path("..", __FILE__)
  @bundler_certs = certificates_in(bundler_cert_path)
end

Instance Attribute Details

#bundler_cert_pathObject (readonly)

Returns the value of attribute bundler_cert_path.



10
11
12
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 10

def bundler_cert_path
  @bundler_cert_path
end

#bundler_certsObject (readonly)

Returns the value of attribute bundler_certs.



10
11
12
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 10

def bundler_certs
  @bundler_certs
end

#rubygems_certsObject (readonly)

Returns the value of attribute rubygems_certs.



10
11
12
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 10

def rubygems_certs
  @rubygems_certs
end

Class Method Details

.update_from!(rubygems_path) ⇒ Object



12
13
14
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 12

def self.update_from!(rubygems_path)
  new(rubygems_path).update!
end

Instance Method Details

#connect_to(host) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 41

def connect_to(host)
  http = Net::HTTP.new(host, 443)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.cert_store = store
  http.head("/")
end

#up_to_date?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 26

def up_to_date?
  rubygems_certs.all? do |rc|
    bundler_certs.find do |bc|
      File.basename(bc) == File.basename(rc) && FileUtils.compare_file(bc, rc)
    end
  end
end

#update!Object



34
35
36
37
38
39
# File 'lib/bundler/ssl_certs/certificate_manager.rb', line 34

def update!
  return if up_to_date?

  FileUtils.rm bundler_certs
  FileUtils.cp rubygems_certs, bundler_cert_path
end