make wantedScripts an ordered list #3

Merged
luna merged 1 commit from claude/aproxy-readme-todo-01Xkjy2nyHBYcMqRcFXVbH2x into mistress 2025-11-23 20:17:28 +00:00
4 changed files with 13 additions and 4 deletions
Showing only changes of commit c01c6d0ba1 - Show all commits

Change wantedScripts to ordered list format

This ensures scripts execute in the order they appear in the config file,
resolving the TODO in the README. The config format has been changed from
a table with script names as keys to an ordered list of script entries.

Changes:
- ctx.lua: Use ipairs() instead of pairs() to iterate in order
- config.lua: Update validation to handle new list structure
- conf.lua: Update example config to use new format
- README.md: Remove TODO and clarify execution order

New config format:
wantedScripts = {
    {name = 'script1', config = {...}},
    {name = 'script2', config = {...}}
}
Claude 2025-11-22 04:37:40 +00:00 committed by Luna

View file

@ -29,7 +29,7 @@ initialization will run validation of your configuration file and check
if it is valid. if it is not you will see logs emitted about what failed if it is valid. if it is not you will see logs emitted about what failed
when a request comes in, the scripts declared in the aproxy config file will when a request comes in, the scripts declared in the aproxy config file will
be executed sequentially (TODO: ensure order on conf file is chain order). be executed sequentially in the order they appear in the configuration.
each script has two types of callbacks: init and request each script has two types of callbacks: init and request

View file

@ -1,6 +1,11 @@
return { return {
version = 1, version = 1,
wantedScripts = { wantedScripts = {
['webfinger_allowlist'] = {accounts = {"example@example.com"}} {
name = 'webfinger_allowlist',
config = {
accounts = {"example@example.com"}
}
}
} }
} }

View file

@ -84,7 +84,9 @@ end
local function validateConfigFile(config_object) local function validateConfigFile(config_object)
local all_schema_errors = {} local all_schema_errors = {}
for module_name, module_config in pairs(config_object.wantedScripts) do for _, script_entry in ipairs(config_object.wantedScripts) do
local module_name = script_entry.name
local module_config = script_entry.config
local module_manifest = require('scripts.' .. module_name) local module_manifest = require('scripts.' .. module_name)
local config_schema = module_manifest.config local config_schema = module_manifest.config
local schema_errors = validateSchema(config_schema, module_config) local schema_errors = validateSchema(config_schema, module_config)

View file

@ -18,7 +18,9 @@ end
function ctx:loadChain() function ctx:loadChain()
self.compiled_chain = {} self.compiled_chain = {}
for module_name, module_config in pairs(self._wanted_scripts) do for _, script_entry in ipairs(self._wanted_scripts) do
local module_name = script_entry.name
local module_config = script_entry.config
local module = require('scripts.' .. module_name) local module = require('scripts.' .. module_name)
local module_config_readonly = table.readonly(module_config) local module_config_readonly = table.readonly(module_config)
local module_state = module.init(module_config_readonly) local module_state = module.init(module_config_readonly)