Compare commits
No commits in common. "374871578dd60ea206fe5300eee8331b2e684e72" and "c15abe3c05f741a530a3f79c2c8a79b0fe95f354" have entirely different histories.
374871578d
...
c15abe3c05
8 changed files with 13 additions and 65 deletions
6
Makefile
6
Makefile
|
@ -1,6 +0,0 @@
|
||||||
testdeps:
|
|
||||||
luarocks-5.1 install --local luaunit
|
|
||||||
luarocks-5.1 install --local lrexlib-PCRE2
|
|
||||||
|
|
||||||
test:
|
|
||||||
luajit test.lua
|
|
11
README.md
11
README.md
|
@ -13,10 +13,9 @@ on top of ActivityPub implementations.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
requires luajit
|
```
|
||||||
|
luarocks-5.1 install --local luaunit
|
||||||
```sh
|
luarocks-5.1 install --local lrexlib-PCRE2
|
||||||
make testdeps
|
eval (luarocks-5.1 path --bin)
|
||||||
eval (luarocks-5.1 path --bin)
|
lua5.1 test.lua
|
||||||
make test
|
|
||||||
```
|
```
|
||||||
|
|
6
conf.lua
6
conf.lua
|
@ -1,6 +0,0 @@
|
||||||
return {
|
|
||||||
version = 1,
|
|
||||||
wantedScripts = {
|
|
||||||
['webfinger_allowlist'] = {accounts = {"example@example.com"}}
|
|
||||||
}
|
|
||||||
}
|
|
36
config.lua
36
config.lua
|
@ -1,36 +0,0 @@
|
||||||
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"
|
|
||||||
local fd = io.open(possible_config_path, "rb")
|
|
||||||
if fd then
|
|
||||||
local data = fd:read("*a")
|
|
||||||
fd:close()
|
|
||||||
return data
|
|
||||||
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()
|
|
7
ctx.lua
7
ctx.lua
|
@ -8,15 +8,10 @@ function ctx:setWantedScripts(graph)
|
||||||
self._wanted_scripts = graph
|
self._wanted_scripts = graph
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctx:loadFromConfig(conf)
|
|
||||||
ctx:setWantedScripts(conf.wantedScripts)
|
|
||||||
ctx:loadChain()
|
|
||||||
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 module_name, module_config in pairs(self._wanted_scripts) do
|
||||||
local module = require('scripts.' .. module_name)
|
local module = require(module_name)
|
||||||
local module_state = module.init(module_config)
|
local module_state = module.init(module_config)
|
||||||
-- TODO is it possible to make module_config readonly?
|
-- TODO is it possible to make module_config readonly?
|
||||||
table.insert(self.compiled_chain, {module, module_config, module_state})
|
table.insert(self.compiled_chain, {module, module_config, module_state})
|
||||||
|
|
|
@ -8,5 +8,4 @@ services:
|
||||||
- 'LUA_PATH=/?.lua;/aproxy/?.lua'
|
- 'LUA_PATH=/?.lua;/aproxy/?.lua'
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||||
- ./conf.lua:/etc/aproxy/conf.lua:ro
|
|
||||||
- .:/aproxy:ro
|
- .:/aproxy:ro
|
||||||
|
|
7
main.lua
7
main.lua
|
@ -1,3 +1,4 @@
|
||||||
|
local CONFIG_PATH = ".;/etc/aproxy"
|
||||||
|
|
||||||
-- function loadConfig()
|
-- function loadConfig()
|
||||||
-- -- TODO load config_path
|
-- -- TODO load config_path
|
||||||
|
@ -7,9 +8,11 @@
|
||||||
-- local config = loadConfig()
|
-- local config = loadConfig()
|
||||||
|
|
||||||
local ctx = require('ctx')
|
local ctx = require('ctx')
|
||||||
local conf = require('config')
|
|
||||||
|
|
||||||
ctx:loadFromConfig(conf)
|
ctx:setWantedScripts({
|
||||||
|
['scripts.webfinger_allowlist'] = {accounts = {"example@example.com"}}
|
||||||
|
})
|
||||||
|
ctx:loadChain()
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
ctx:onRequest()
|
ctx:onRequest()
|
||||||
|
|
|
@ -25,12 +25,12 @@ return {
|
||||||
author='luna@l4.pm',
|
author='luna@l4.pm',
|
||||||
title='Webfinger Allowlist',
|
title='Webfinger Allowlist',
|
||||||
description=[[
|
description=[[
|
||||||
Prevent unnecessary DB load by discarding requests to users that we know
|
Prevent unecessary DB load by discarding requests to users that we know
|
||||||
won't exist.
|
won't exist.
|
||||||
|
|
||||||
Useful for small instances.
|
Useful for small instances.
|
||||||
]],
|
]],
|
||||||
version=1,
|
apiVersion=1,
|
||||||
init=webfingerInit,
|
init=webfingerInit,
|
||||||
callbacks = {
|
callbacks = {
|
||||||
['/.well-known/webfinger'] = webfingerCallback
|
['/.well-known/webfinger'] = webfingerCallback
|
||||||
|
|
Loading…
Reference in a new issue