Skip to content

Commit

Permalink
feat(autossl) expose function to get cert from LRU cache (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoobleD authored Nov 18, 2022
1 parent 441b095 commit 6135d0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ domain_whitelist_callback = function(domain, is_new_cert_needed)
local http = require("resty.http")
local res, err = httpc:request_uri("http://example.com")
-- access the storage
local value, err = require("resty.acme.autossl").storage:get("key")
local acme = require("resty.acme.autossl")
local value, err = acme.storage:get("key")
-- get cert from resty LRU cache
-- cached = { pkey, cert } or nil if cert is not in cache
local cached, staled, flags = acme.get_cert_from_cache(domain, "rsa")
-- do something to check the domain
-- return is_domain_included
end}),
Expand Down
6 changes: 5 additions & 1 deletion lib/resty/acme/autossl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ local account_private_key_prefix = "account_key:"
local certificate_failure_lock_key_prefix = "failure_lock:"
local certificate_failure_count_prefix = "failed_attempts:"

function AUTOSSL.get_cert_from_cache(domain, typ)
return certs_cache[typ]:get(domain)
end

-- get cert from storage
local function get_certkey(domain, typ)
local domain_key = domain_cache_key_prefix .. typ .. ":" .. domain
Expand All @@ -106,7 +110,7 @@ end

-- get cert and key cdata with caching
local function get_certkey_parsed(domain, typ)
local data, data_staled, _ --[[flags]] = certs_cache[typ]:get(domain)
local data, data_staled, _ --[[flags]] = AUTOSSL.get_cert_from_cache(domain, typ)

if data then
return data, nil
Expand Down

0 comments on commit 6135d0e

Please sign in to comment.