mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-08 18:19:30 +00:00
new(userspace/engine): expose resolve_tokens to lua
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com> Signed-off-by: Lorenzo Fontana <lo@linux.com>
This commit is contained in:
committed by
Leo Di Donato
parent
826ad0b271
commit
7f35b7f712
@@ -36,6 +36,7 @@ const static struct luaL_reg ll_falco [] =
|
||||
{"free_formatter", &falco_formats::free_formatter},
|
||||
{"free_formatters", &falco_formats::free_formatters},
|
||||
{"format_event", &falco_formats::format_event},
|
||||
{"resolve_tokens", &falco_formats::resolve_tokens},
|
||||
{NULL,NULL}
|
||||
};
|
||||
|
||||
@@ -265,3 +266,34 @@ int falco_formats::format_event (lua_State *ls)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int falco_formats::resolve_tokens(lua_State *ls)
|
||||
{
|
||||
if (!lua_isstring(ls, -1) ||
|
||||
!lua_isstring(ls, -2)) {
|
||||
lua_pushstring(ls, "Invalid arguments passed to resolve_tokens()");
|
||||
lua_error(ls);
|
||||
}
|
||||
gen_event* evt = (gen_event*)lua_topointer(ls, 1);
|
||||
const char *source = (char *) lua_tostring(ls, 2); // TODO(fntlnz, leodido): do we need this one?
|
||||
const char *format = (char *) lua_tostring(ls, 3);
|
||||
string sformat = format;
|
||||
|
||||
|
||||
map<string,string> values;
|
||||
|
||||
s_formatters->resolve_tokens((sinsp_evt *)evt, sformat, values);
|
||||
|
||||
lua_newtable(ls);
|
||||
int top = lua_gettop(ls);
|
||||
for (std::map<string, string>::iterator it = values.begin(); it != values.end(); ++it) {
|
||||
const char* key = it->first.c_str();
|
||||
const char* value = it->second.c_str();
|
||||
lua_pushlstring(ls, key, it->first.size());
|
||||
lua_pushlstring(ls, value, it->second.size());
|
||||
lua_settable(ls, top);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@@ -53,6 +53,8 @@ class falco_formats
|
||||
// formatted_string = falco.format_event(evt, formatter)
|
||||
static int format_event(lua_State *ls);
|
||||
|
||||
static int resolve_tokens(lua_State *ls);
|
||||
|
||||
static sinsp* s_inspector;
|
||||
static falco_engine *s_engine;
|
||||
static sinsp_evt_formatter_cache *s_formatters;
|
||||
|
Reference in New Issue
Block a user