Skip to content

Commit

Permalink
style(core/runloop): style clean for certificate.lua (#10119)
Browse files Browse the repository at this point in the history
* localize vars
* fix fetch_ca_certificates
* CA_KEY
  • Loading branch information
chronolaw authored Jan 17, 2023
1 parent 2d2104a commit ca73cc9
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions kong/runloop/certificate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ local set_cert = ngx_ssl.set_cert
local set_priv_key = ngx_ssl.set_priv_key
local tb_concat = table.concat
local tb_sort = table.sort
local kong = kong
local type = type
local error = error
local assert = assert
local tostring = tostring
local ipairs = ipairs
local ngx_md5 = ngx.md5
local ngx_exit = ngx.exit
local ngx_ERROR = ngx.ERROR


local default_cert_and_key

local DEFAULT_SNI = "*"

local CA_KEY = {
id = "",
}


local function log(lvl, ...)
ngx_log(lvl, "[ssl] ", ...)
end
Expand Down Expand Up @@ -244,13 +255,13 @@ local function execute()
local sn, err = server_name()
if err then
log(ERR, "could not retrieve SNI: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

local cert_and_key, err = find_certificate(sn)
if err then
log(ERR, err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

if cert_and_key == default_cert_and_key then
Expand All @@ -263,32 +274,32 @@ local function execute()
local ok, err = clear_certs()
if not ok then
log(ERR, "could not clear existing (default) certificates: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

ok, err = set_cert(cert_and_key.cert)
if not ok then
log(ERR, "could not set configured certificate: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

ok, err = set_priv_key(cert_and_key.key)
if not ok then
log(ERR, "could not set configured private key: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

if cert_and_key.cert_alt and cert_and_key.key_alt then
ok, err = set_cert(cert_and_key.cert_alt)
if not ok then
log(ERR, "could not set alternate configured certificate: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end

ok, err = set_priv_key(cert_and_key.key_alt)
if not ok then
log(ERR, "could not set alternate configured private key: ", err)
return ngx.exit(ngx.ERROR)
return ngx_exit(ngx_ERROR)
end
end
end
Expand All @@ -302,12 +313,11 @@ end

local function fetch_ca_certificates(ca_ids)
local cas = new_tab(#ca_ids, 0)
local key = new_tab(1, 0)

for i, ca_id in ipairs(ca_ids) do
key.id = ca_id
CA_KEY.id = ca_id

local obj, err = kong.db.ca_certificates:select(key)
local obj, err = kong.db.ca_certificates:select(CA_KEY)
if not obj then
if err then
return nil, err
Expand Down

1 comment on commit ca73cc9

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:ca73cc9084ec0142b08404cfb9d960cba965aae5
Artifacts available https://github.com/Kong/kong/actions/runs/3938212088

Please sign in to comment.