From d63a4a11ab94af383b9aef17f587a80d32b7dec4 Mon Sep 17 00:00:00 2001 From: Christian Roessner Date: Wed, 27 Nov 2024 11:05:49 +0100 Subject: [PATCH] Feat: Add GUID parameter to executeAndHandleError function 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 --- server/lua-plugins.d/hooks/dovecot-session-cleaner.lua | 3 ++- server/lualib/hook/hook.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/lua-plugins.d/hooks/dovecot-session-cleaner.lua b/server/lua-plugins.d/hooks/dovecot-session-cleaner.lua index 82a5bf35..70932289 100644 --- a/server/lua-plugins.d/hooks/dovecot-session-cleaner.lua +++ b/server/lua-plugins.d/hooks/dovecot-session-cleaner.lua @@ -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") diff --git a/server/lualib/hook/hook.go b/server/lualib/hook/hook.go index 2a2beb7f..2e89c92a 100644 --- a/server/lualib/hook/hook.go +++ b/server/lualib/hook/hook.go @@ -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 } @@ -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 { @@ -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) @@ -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) } @@ -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) }