fix(config): lua 5.1 compatibility and multi-tenant validation
- Replace goto statements with if-not pattern for Lua 5.1 compatibility - Validate mail config only for API keys with mail:send permissions - Safe display of API key info for monitoring keys without mail config - Fix health check SMTP detection for new config structure - Multi-tenant system tested and working on port 7811 Fixes multi-tenant config parsing, validation, and health checks. Related to DAW/furt#89
This commit is contained in:
parent
a5db9a633f
commit
8ec401930c
4 changed files with 75 additions and 49 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -56,3 +56,4 @@ debug.log
|
|||
config.local.lua
|
||||
config.production.lua
|
||||
|
||||
config/furt.conf
|
||||
|
|
|
|||
|
|
@ -67,11 +67,28 @@ print(" Default SMTP: " .. (config.smtp_default.host or "not configured"))
|
|||
local api_key_count = 0
|
||||
for key_name, key_config in pairs(config.api_keys) do
|
||||
api_key_count = api_key_count + 1
|
||||
|
||||
-- Check if this API key has mail permissions
|
||||
local has_mail_permission = false
|
||||
if key_config.permissions then
|
||||
for _, perm in ipairs(key_config.permissions) do
|
||||
if perm == "mail:send" or perm == "*" then
|
||||
has_mail_permission = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local smtp_info = ""
|
||||
if key_config.mail_smtp_host then
|
||||
smtp_info = " (custom SMTP: " .. key_config.mail_smtp_host .. ")"
|
||||
end
|
||||
|
||||
if has_mail_permission then
|
||||
print(" API Key: " .. key_config.name .. " -> " .. key_config.mail_to .. smtp_info)
|
||||
else
|
||||
print(" API Key: " .. key_config.name .. " (no mail)" .. smtp_info)
|
||||
end
|
||||
end
|
||||
print(" Total API Keys: " .. api_key_count)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
-- src/config_parser.lua
|
||||
-- nginx-style configuration parser for Multi-Tenant setup
|
||||
-- Dragons@Work Digital Sovereignty Project
|
||||
-- Lua 5.1 compatible (no goto statements)
|
||||
|
||||
local ConfigParser = {}
|
||||
|
||||
|
|
@ -26,10 +27,7 @@ function ConfigParser.parse_file(config_path)
|
|||
|
||||
-- Skip empty lines and comments
|
||||
line = line:match("^%s*(.-)%s*$") -- trim whitespace
|
||||
if line == "" or line:match("^#") then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if not (line == "" or line:match("^#")) then
|
||||
-- Section headers: [section] or [api_key "keyname"]
|
||||
local section_match = line:match("^%[([^%]]+)%]$")
|
||||
if section_match then
|
||||
|
|
@ -49,9 +47,7 @@ function ConfigParser.parse_file(config_path)
|
|||
config[current_section] = {}
|
||||
end
|
||||
end
|
||||
goto continue
|
||||
end
|
||||
|
||||
else
|
||||
-- Key-value pairs: key = value
|
||||
local key, value = line:match("^([^=]+)=(.+)$")
|
||||
if key and value then
|
||||
|
|
@ -71,8 +67,8 @@ function ConfigParser.parse_file(config_path)
|
|||
else
|
||||
error(string.format("Invalid line format at line %d: %s", line_number, line))
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
file:close()
|
||||
|
|
@ -163,7 +159,18 @@ function ConfigParser.validate_config(config)
|
|||
key_config.allowed_ips = {} -- no IP restrictions
|
||||
end
|
||||
|
||||
-- Validate mail configuration
|
||||
-- Validate mail configuration only if API key has mail:send permission
|
||||
local has_mail_permission = false
|
||||
if key_config.permissions then
|
||||
for _, perm in ipairs(key_config.permissions) do
|
||||
if perm == "mail:send" or perm == "*" then
|
||||
has_mail_permission = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if has_mail_permission then
|
||||
if not key_config.mail_to then
|
||||
error("API key '" .. key_name .. "' missing mail_to")
|
||||
end
|
||||
|
|
@ -172,6 +179,7 @@ function ConfigParser.validate_config(config)
|
|||
error("API key '" .. key_name .. "' missing mail_from")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Set SMTP defaults if not configured
|
||||
if not config.smtp_default.host then
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ server:add_route("GET", "/health", function(request, server)
|
|||
timestamp = os.time(),
|
||||
source = version_info.source,
|
||||
features = {
|
||||
smtp_configured = config.mail and config.mail.username ~= nil,
|
||||
smtp_configured = config.smtp_default and config.smtp_default.host ~= nil,
|
||||
auth_enabled = true,
|
||||
rate_limiting = true,
|
||||
merkwerk_integrated = version_info.source == "merkwerk"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue