Class: HammerCLI::CACertManager

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/ca_cert_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ca_store_path) ⇒ CACertManager

Returns a new instance of CACertManager.



7
8
9
# File 'lib/hammer_cli/ca_cert_manager.rb', line 7

def initialize(ca_store_path)
  @ca_store_path = File.expand_path(ca_store_path)
end

Instance Attribute Details

#ca_store_pathObject (readonly)

Returns the value of attribute ca_store_path.



5
6
7
# File 'lib/hammer_cli/ca_cert_manager.rb', line 5

def ca_store_path
  @ca_store_path
end

Instance Method Details

#cert_exist?(uri) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/hammer_cli/ca_cert_manager.rb', line 22

def cert_exist?(uri)
  File.exist?(cert_file_name(uri))
end

#cert_file_name(uri) ⇒ Object



18
19
20
# File 'lib/hammer_cli/ca_cert_manager.rb', line 18

def cert_file_name(uri)
  File.join(ca_store_path, "#{uri.host}_#{uri.port}.pem")
end

#store_ca_cert(raw_cert, cert_file) ⇒ Object



11
12
13
14
15
16
# File 'lib/hammer_cli/ca_cert_manager.rb', line 11

def store_ca_cert(raw_cert, cert_file)
  raise HammerCLI::NoCACertificate.new unless is_ca_cert?(raw_cert)
  ensure_ca_store_exist
  File.write(cert_file, raw_cert)
  cert_file
end