Skip to content

Commit

Permalink
Feat: Add GUID parameter to executeAndHandleError function
Browse files Browse the repository at this point in the history
Extended the executeAndHandleError function signature to include a GUID parameter. Updated relevant function calls to pass this new parameter, ensuring proper session handling. Adjusted the Lua script to log the session information accordingly.

Signed-off-by: Christian Roessner <[email protected]>
  • Loading branch information
Christian Roessner committed Nov 27, 2024
1 parent 8901d1b commit d63a4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion server/lua-plugins.d/hooks/dovecot-session-cleaner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ local json = require("json")

local N = "callback"

function nauthilus_run_hook(logging)
function nauthilus_run_hook(logging, session)
local result = {}

result.level = "info"
result.caller = N .. ".lua"
result.session = session

local custom_pool = "default"
local custom_pool_name = os.getenv("CUSTOM_REDIS_POOL_NAME")
Expand Down
9 changes: 5 additions & 4 deletions server/lualib/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func runLuaCommonWrapper(ctx context.Context, hook string, registerDynamicLoader

logTable := setupLogging(L)

_, err := executeAndHandleError(script.GetPrecompiledScript(), logTable, L, hook)
_, err := executeAndHandleError(script.GetPrecompiledScript(), logTable, L, hook, "")

return err
}
Expand All @@ -367,6 +367,7 @@ func runLuaCommonWrapper(ctx context.Context, hook string, registerDynamicLoader
func runLuaCustomWrapper(ctx *gin.Context, registerDynamicLoader func(*lua.LState, context.Context)) (gin.H, error) {
var script *PrecompiledLuaScript

guid := ctx.GetString(definitions.CtxGUIDKey)
hook := ctx.Param("hook")

if script = customLocation.GetScript(hook, ctx.Request.Method); script == nil {
Expand All @@ -387,7 +388,7 @@ func runLuaCustomWrapper(ctx *gin.Context, registerDynamicLoader func(*lua.LStat

logTable := setupLogging(L)

return executeAndHandleError(script.GetPrecompiledScript(), logTable, L, hook)
return executeAndHandleError(script.GetPrecompiledScript(), logTable, L, hook, guid)
}

// registerDynamicLoaderGin registers a dynamic loader function in the Lua state (L)
Expand Down Expand Up @@ -428,7 +429,7 @@ func RunLuaInit(ctx context.Context, hook string) error {
// if err != nil {
// // handle error
// }
func executeAndHandleError(compiledScript *lua.FunctionProto, logTable *lua.LTable, L *lua.LState, hook string) (result gin.H, err error) {
func executeAndHandleError(compiledScript *lua.FunctionProto, logTable *lua.LTable, L *lua.LState, hook, guid string) (result gin.H, err error) {
if err = lualib.PackagePath(L); err != nil {
processError(err, hook)
}
Expand All @@ -441,7 +442,7 @@ func executeAndHandleError(compiledScript *lua.FunctionProto, logTable *lua.LTab
Fn: L.GetGlobal(definitions.LuaFnRunHook),
NRet: 1,
Protect: true,
}, logTable); err != nil {
}, logTable, lua.LString(guid)); err != nil {
processError(err, hook)
}

Expand Down

0 comments on commit d63a4a1

Please sign in to comment.