Mercurial > prosody-modules
comparison mod_audit/mod_audit.lua @ 4934:08dea42a302a
mod_audit*: fix luacheck warnings
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 26 Apr 2022 22:37:13 +0200 |
parents | 530d116b7f68 |
children | ae83200fb55f |
comparison
equal
deleted
inserted
replaced
4933:530d116b7f68 | 4934:08dea42a302a |
---|---|
10 local function get_store(self, host) | 10 local function get_store(self, host) |
11 local store = rawget(self, host); | 11 local store = rawget(self, host); |
12 if store then | 12 if store then |
13 return store | 13 return store |
14 end | 14 end |
15 local store = module:context(host):open_store("audit", "archive"); | 15 store = module:context(host):open_store("audit", "archive"); |
16 rawset(self, host, store); | 16 rawset(self, host, store); |
17 return store; | 17 return store; |
18 end | 18 end |
19 | 19 |
20 setmetatable(stores, { __index = get_store }); | 20 setmetatable(stores, { __index = get_store }); |
39 | 39 |
40 local function audit(host, user, source, event_type, extra) | 40 local function audit(host, user, source, event_type, extra) |
41 if not host or host == "*" then | 41 if not host or host == "*" then |
42 error("cannot log audit events for global"); | 42 error("cannot log audit events for global"); |
43 end | 43 end |
44 local user = user or host_wide_user; | 44 local user_key = user or host_wide_user; |
45 | 45 |
46 local attr = { | 46 local attr = { |
47 ["source"] = source, | 47 ["source"] = source, |
48 ["type"] = event_type, | 48 ["type"] = event_type, |
49 }; | 49 }; |
50 if user ~= host_wide_user then | 50 if user_key ~= host_wide_user then |
51 attr.user = user; | 51 attr.user = user_key; |
52 end | 52 end |
53 local stanza = st.stanza("audit-event", attr); | 53 local stanza = st.stanza("audit-event", attr); |
54 if extra ~= nil then | 54 if extra ~= nil then |
55 if extra.session then | 55 if extra.session then |
56 local child = session_extra(extra.session); | 56 local child = session_extra(extra.session); |
66 stanza:add_child(child); | 66 stanza:add_child(child); |
67 end | 67 end |
68 end | 68 end |
69 end | 69 end |
70 | 70 |
71 local id, err = stores[host]:append(nil, nil, stanza, time_now(), user); | 71 local id, err = stores[host]:append(nil, nil, stanza, time_now(), user_key); |
72 if err then | 72 if err then |
73 module:log("error", "failed to persist audit event: %s", err); | 73 module:log("error", "failed to persist audit event: %s", err); |
74 return | 74 return |
75 else | 75 else |
76 module:log("debug", "persisted audit event %s as %s", stanza:top_tag(), id); | 76 module:log("debug", "persisted audit event %s as %s", stanza:top_tag(), id); |