Module: DevCert::Export

Defined in:
lib/devcert/export.rb

Class Method Summary collapse

Class Method Details

.export(bundle_path, type, output_dir) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/devcert/export.rb', line 5

def self.export(bundle_path, type, output_dir)
  bundle = ::DevCert::Util.load_bundle(bundle_path)
  case type
  when 'private_key'
    private_key_path = ::File.join(
      output_dir,
      "#{::DevCert::Util.normalize_name(bundle[:common_name])}_key.pem"
    )
    ::DevCert::Util.export(private_key_path, bundle[:private_key])
    puts "file: #{private_key_path}"
  when 'certificate'
    certificate_path = ::File.join(
      output_dir,
      "#{::DevCert::Util.normalize_name(bundle[:common_name])}.crt"
    )
    ::DevCert::Util.export(certificate_path, bundle[:certificate])
    puts "file: #{certificate_path}"
  end
end