2025-08-14 09:36:55 +02:00
|
|
|
-- config/server.lua
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Multi-Tenant server configuration using nginx-style config parser
|
|
|
|
|
-- Dragons@Work Digital Sovereignty Project
|
2025-06-17 20:40:40 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
local ConfigParser = require("src.config_parser")
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Load configuration from furt.conf
|
|
|
|
|
local config = ConfigParser.load_config()
|
|
|
|
|
|
|
|
|
|
-- Add legacy compatibility and runtime enhancements
|
|
|
|
|
local server_config = {
|
|
|
|
|
-- HTTP Server settings (from [server] section)
|
|
|
|
|
host = config.server.host,
|
|
|
|
|
port = config.server.port,
|
|
|
|
|
|
|
|
|
|
-- Timeouts and limits
|
|
|
|
|
client_timeout = config.server.client_timeout or 10,
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-06-24 19:42:44 +02:00
|
|
|
-- CORS Configuration
|
|
|
|
|
cors = {
|
|
|
|
|
allowed_origins = (function()
|
|
|
|
|
local env_origins = os.getenv("CORS_ALLOWED_ORIGINS")
|
|
|
|
|
if env_origins then
|
|
|
|
|
-- Parse comma-separated list from environment
|
|
|
|
|
local origins = {}
|
|
|
|
|
for origin in env_origins:gmatch("([^,]+)") do
|
2025-08-15 16:18:55 +02:00
|
|
|
table.insert(origins, origin:match("^%s*(.-)%s*$"))
|
2025-06-24 19:42:44 +02:00
|
|
|
end
|
|
|
|
|
return origins
|
|
|
|
|
else
|
|
|
|
|
-- Default development origins
|
|
|
|
|
return {
|
|
|
|
|
"http://localhost:1313", -- Hugo dev server
|
|
|
|
|
"http://127.0.0.1:1313", -- Hugo dev server alternative
|
|
|
|
|
"http://localhost:3000", -- Common dev port
|
|
|
|
|
"http://127.0.0.1:3000" -- Common dev port alternative
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end)()
|
|
|
|
|
},
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-06-17 20:40:40 +02:00
|
|
|
-- Logging
|
2025-08-15 16:18:55 +02:00
|
|
|
log_level = config.server.log_level or "info",
|
|
|
|
|
log_requests = config.server.log_requests or true,
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- API Keys (converted from nginx-style to old format for backward compatibility)
|
|
|
|
|
api_keys = config.api_keys,
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Default SMTP config (for legacy compatibility)
|
|
|
|
|
mail = config.smtp_default,
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Multi-tenant mail configuration function
|
|
|
|
|
get_mail_config_for_api_key = function(api_key)
|
|
|
|
|
return ConfigParser.get_mail_config_for_api_key(config, api_key)
|
|
|
|
|
end,
|
2025-08-14 09:36:55 +02:00
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Raw config access (for advanced usage)
|
|
|
|
|
raw_config = config
|
2025-06-17 20:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
-- Print configuration summary on load
|
|
|
|
|
print("Furt Multi-Tenant Configuration Loaded:")
|
|
|
|
|
print(" Server: " .. server_config.host .. ":" .. server_config.port)
|
|
|
|
|
print(" Log Level: " .. server_config.log_level)
|
|
|
|
|
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
|
2025-08-28 19:53:30 +02:00
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
|
2025-08-15 16:18:55 +02:00
|
|
|
local smtp_info = ""
|
|
|
|
|
if key_config.mail_smtp_host then
|
|
|
|
|
smtp_info = " (custom SMTP: " .. key_config.mail_smtp_host .. ")"
|
|
|
|
|
end
|
2025-08-28 19:53:30 +02:00
|
|
|
|
|
|
|
|
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
|
2025-08-15 16:18:55 +02:00
|
|
|
end
|
|
|
|
|
print(" Total API Keys: " .. api_key_count)
|
|
|
|
|
|
|
|
|
|
return server_config
|
|
|
|
|
|