Class: Anchor::PemBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/anchor/pem_bundle.rb

Overview

PEMBundle is a collection of PEM encoded certificates. It can be written to a temporarly file on disk as a bundle if needed.

This temp file to disk is needed for some other libraries that require a path to a pem file, and not a string of pem encoded certificates.

Constant Summary collapse

DEFAULT_BASENAME =
'bundle.pem'

Instance Method Summary collapse

Constructor Details

#initialize(pems: []) ⇒ PemBundle

Returns a new instance of PemBundle.



15
16
17
18
19
20
# File 'lib/anchor/pem_bundle.rb', line 15

def initialize(pems: [])
  @pems = pems || []
  @path = nil
  @temp_dir = nil
  @basename = DEFAULT_BASENAME
end

Instance Method Details

#add_cert(cert) ⇒ Object



37
38
39
40
# File 'lib/anchor/pem_bundle.rb', line 37

def add_cert(cert)
  @pems << cert
  remove_path
end

#clearObject



46
47
48
49
# File 'lib/anchor/pem_bundle.rb', line 46

def clear
  @pems.clear
  remove_path
end

#pathObject



26
27
28
29
# File 'lib/anchor/pem_bundle.rb', line 26

def path
  write
  @path
end

#pemsObject



22
23
24
# File 'lib/anchor/pem_bundle.rb', line 22

def pems
  @pems.dup
end

#to_sObject



42
43
44
# File 'lib/anchor/pem_bundle.rb', line 42

def to_s
  @pems.join("\n")
end

#with_pathObject



31
32
33
34
35
# File 'lib/anchor/pem_bundle.rb', line 31

def with_path
  yield(path)
ensure
  remove_path
end