2022-12-06 21:24:25 +00:00
|
|
|
local env_config_path = os.getenv('APROXY_CONFIG_PATH')
|
|
|
|
local DEFAULT_CONFIG_PATH = ".;/etc/aproxy"
|
|
|
|
local config_path = env_config_path or DEFAULT_CONFIG_PATH
|
|
|
|
|
|
|
|
function mysplit (inputstr, sep)
|
|
|
|
if sep == nil then
|
|
|
|
sep = "%s"
|
|
|
|
end
|
|
|
|
local t={}
|
|
|
|
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
|
|
|
|
table.insert(t, str)
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
|
|
|
local function findConfigFile()
|
|
|
|
for _, config_directory in ipairs(mysplit(config_path, ";")) do
|
|
|
|
local possible_config_path = config_directory .. "/" .. "conf.lua"
|
2022-12-07 04:35:57 +00:00
|
|
|
local fd, res = io.open(possible_config_path, "rb")
|
2022-12-06 21:24:25 +00:00
|
|
|
if fd then
|
|
|
|
local data = fd:read("*a")
|
|
|
|
fd:close()
|
|
|
|
return data
|
2022-12-07 04:34:32 +00:00
|
|
|
else
|
2022-12-07 04:35:57 +00:00
|
|
|
log('config not found at ' .. possible_config_path .. ':' .. tostring(res))
|
2022-12-06 21:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local function loadConfigFile()
|
|
|
|
local config_file_data = assert(findConfigFile(), 'no config file found, config path: ' .. config_path)
|
|
|
|
local config_file_function = assert(loadstring(config_file_data))
|
|
|
|
return config_file_function()
|
|
|
|
end
|
|
|
|
|
|
|
|
return loadConfigFile()
|