From 6135d0e3ccc31f58193af1f49ec6fcdd9f45d6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20All=C3=A9tru?= Date: Fri, 18 Nov 2022 10:26:41 +0100 Subject: [PATCH] feat(autossl) expose function to get cert from LRU cache (#96) --- README.md | 6 +++++- lib/resty/acme/autossl.lua | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f1ed24..8411dce 100644 --- a/README.md +++ b/README.md @@ -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}), diff --git a/lib/resty/acme/autossl.lua b/lib/resty/acme/autossl.lua index 9054233..8724c11 100644 --- a/lib/resty/acme/autossl.lua +++ b/lib/resty/acme/autossl.lua @@ -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 @@ -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