Skip to content

Commit

Permalink
add ssl_trusted_combined in apisix.home
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolyssup committed Feb 25, 2025
1 parent b7c2140 commit 5877450
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Please modify "admin_key" in conf/config.yaml .
end

local combined_cert_filepath = yaml_conf.apisix.ssl.ssl_trusted_combined_path
or "/usr/local/apisix/conf/ssl_trusted_combined.pem"
or profile.apisix_home .. "/conf/ssl_trusted_combined.pem"
util.gen_trusted_certs_combined_file(combined_cert_filepath, cert_paths)

yaml_conf.apisix.ssl.ssl_trusted_certificate = combined_cert_filepath
Expand Down
31 changes: 3 additions & 28 deletions apisix/cli/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,36 +174,11 @@ do
end


local function ensure_dir(path)
-- Extract directory from path
local dir = path:match("(.*/)")
if dir then
-- Try to create directory recursively.
-- This uses "mkdir -p" to avoid error if the directory already exists.
local ok = os.execute("mkdir -p " .. dir)
if not ok then
error("failed to create directory: " .. dir)
end
end
end

function _M.gen_trusted_certs_combined_file(combined_filepath, paths)
-- Ensure the directory for combined_filepath exists.
ensure_dir(combined_filepath)

local combined_file, err = io.open(combined_filepath, "w")
if not combined_file then
error("failed to open or create combined file at " .. combined_filepath ..
". error: " .. tostring(err))
end

local combined_file = assert(io.open(combined_filepath, "w"))
for _, path in ipairs(paths) do
local cert_file, cert_err = io.open(path, "r")
if not cert_file then
error("failed to open certificate file " .. path .. ": " .. tostring(cert_err))
end
local data = cert_file:read("*a") or ""
combined_file:write(data)
local cert_file = assert(io.open(path, "r"))
combined_file:write(cert_file:read("*a"))
combined_file:write("\n")
cert_file:close()
end
Expand Down

0 comments on commit 5877450

Please sign in to comment.