Module: Billy::CertificateHelpers

Included in:
Authority, Certificate, CertificateChain
Defined in:
lib/billy/ssl/certificate_helpers.rb

Overview

A set of common certificate helper methods.

Instance Method Summary collapse

Instance Method Details

#days_ago(days) ⇒ Object

Give back the date from now minus given days.



17
18
19
# File 'lib/billy/ssl/certificate_helpers.rb', line 17

def days_ago(days)
  Time.now - (days * 24 * 60 * 60)
end

#days_from_now(days) ⇒ Object

Give back the date from now plus given days.



12
13
14
# File 'lib/billy/ssl/certificate_helpers.rb', line 12

def days_from_now(days)
  Time.now + (days * 24 * 60 * 60)
end

#serialObject

Generate a random serial number for a certificate.



22
23
24
# File 'lib/billy/ssl/certificate_helpers.rb', line 22

def serial
  rand(1_000_000..100_000_000_000)
end

#write_file(name, contents) ⇒ Object

Create/Overwrite a new file with the given name and ensure the location is safely created. Pass back the resulting path.



29
30
31
32
33
34
# File 'lib/billy/ssl/certificate_helpers.rb', line 29

def write_file(name, contents)
  path = File.join(Billy.config.certs_path, name)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, contents)
  path
end