Module: AlexaVerifier::CertificateStore
- Defined in:
- lib/alexa_verifier/certificate_store.rb
Overview
A module used to download, cache and serve certificates from our requests.
Constant Summary collapse
- CERTIFICATE_CACHE_TIME =
30 minutes
1800- CERTIFICATE_SEPARATOR =
'-----BEGIN CERTIFICATE-----'.freeze
Class Method Summary collapse
-
.delete(uri) ⇒ nil|Hash
Given a certificate uri, remove the certificate from our store.
-
.fetch(uri) ⇒ OpenSSL::X509::Certificate+
Given a certificate uri, either download the certificate and chain, or load them from our certificate store.
-
.store ⇒ Hash
Returns a copy of our certificate store.
Class Method Details
.delete(uri) ⇒ nil|Hash
Given a certificate uri, remove the certificate from our store.
35 36 37 38 39 |
# File 'lib/alexa_verifier/certificate_store.rb', line 35 def delete(uri) store @store.delete(uri) end |
.fetch(uri) ⇒ OpenSSL::X509::Certificate+
Given a certificate uri, either download the certificate and chain, or load them from our certificate store.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/alexa_verifier/certificate_store.rb', line 14 def fetch(uri) store if cache_valid?(@store[uri]) certificate = @store[uri][:certificate] chain = @store[uri][:chain] else chain = generate_certificate_chain_from_data(download_certificate(uri)) certificate = chain.delete_at(0) @store[uri] = { timestamp: Time.now, certificate: certificate, chain: chain } end [certificate, chain] end |
.store ⇒ Hash
Returns a copy of our certificate store
44 45 46 |
# File 'lib/alexa_verifier/certificate_store.rb', line 44 def store @store ||= {} end |