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.



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

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.



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

def bundler_cert_path
  @bundler_cert_path
end

#bundler_certsObject (readonly)

Returns the value of attribute bundler_certs.



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

def bundler_certs
  @bundler_certs
end

#rubygems_certsObject (readonly)

Returns the value of attribute rubygems_certs.



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

def rubygems_certs
  @rubygems_certs
end

Class Method Details

.update_from!(rubygems_path) ⇒ Object



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

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

Instance Method Details

#connect_to(host) ⇒ Object



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

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)


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

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



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

def update!
  return if up_to_date?

  FileUtils.rm bundler_certs
  FileUtils.cp rubygems_certs, bundler_cert_path
end