Class: LetsencryptStandalone::Certificate
- Inherits:
-
Base
- Object
- Base
- LetsencryptStandalone::Certificate
show all
- Defined in:
- lib/letsencrypt_standalone/certificate.rb
Constant Summary
collapse
- @@default_names =
{
certificate: 'cert.pem',
chain: 'chain.pem',
fullchain: 'fullchain.pem'
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#endpoint_url, #logger, logger, #output_dir, #path, #ssl_subdir
Constructor Details
#initialize(domain:, client:) ⇒ Certificate
17
18
19
20
21
22
|
# File 'lib/letsencrypt_standalone/certificate.rb', line 17
def initialize(domain:, client:)
@files = domain.certificates || @@default_names
@domain = domain.host
@client = client
@private_key = domain.private_key
end
|
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
15
16
17
|
# File 'lib/letsencrypt_standalone/certificate.rb', line 15
def files
@files
end
|
Instance Method Details
#needs_refresh? ⇒ Boolean
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/letsencrypt_standalone/certificate.rb', line 30
def needs_refresh?
cert = @files[:certificate]
if cert.not_after > Time.now + 2*24*3600
logger.info("It doesnt need to refresh cert for domain: #{@domain}")
false
else
logger.info("It needs to refresh cert for domain: #{@domain}")
true
end
end
|
#obtain_new ⇒ Object
24
25
26
27
28
|
# File 'lib/letsencrypt_standalone/certificate.rb', line 24
def obtain_new
csr = Acme::Client::CertificateRequest.new(names: Array(@domain), private_key: @private_key)
@certificate = @client.new_certificate(csr)
return self
end
|
#save ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/letsencrypt_standalone/certificate.rb', line 41
def save
FileUtils.mkdir_p(File.join(output_dir, @domain))
File.write(File.join(output_dir, @domain, @files[:certificate]), @certificate.to_pem)
File.write(File.join(output_dir, @domain, @files[:chain]), @certificate.chain_to_pem)
File.write(File.join(output_dir, @domain, @files[:fullchain]), @certificate.fullchain_to_pem)
end
|