new(falco): enable -o key={object} configuration

Signed-off-by: Luca Guerra <luca@guerra.sh>
This commit is contained in:
Luca Guerra 2024-09-03 14:57:51 +00:00 committed by poiana
parent 24a70da976
commit 5b6810a51e
2 changed files with 21 additions and 3 deletions

View File

@ -84,8 +84,8 @@ falco_configuration::falco_configuration():
m_metrics_convert_memory_to_mb(true), m_metrics_convert_memory_to_mb(true),
m_metrics_include_empty_values(false), m_metrics_include_empty_values(false),
m_container_engines_mask(0), m_container_engines_mask(0),
m_container_engines_cri_socket_paths({"/run/containerd/containerd.sock", "/run/crio/crio.sock","/run/k3s/containerd/containerd.sock"}), m_container_engines_disable_cri_async(false),
m_container_engines_disable_cri_async(false) m_container_engines_cri_socket_paths({"/run/containerd/containerd.sock", "/run/crio/crio.sock","/run/k3s/containerd/containerd.sock"})
{ {
m_config_schema = nlohmann::json::parse(schema_json_string); m_config_schema = nlohmann::json::parse(schema_json_string);
} }
@ -749,5 +749,12 @@ void falco_configuration::set_cmdline_option(const std::string &opt)
throw std::logic_error("Error parsing config option \"" + opt + "\". Must be of the form key=val or key.subkey=val"); throw std::logic_error("Error parsing config option \"" + opt + "\". Must be of the form key=val or key.subkey=val");
} }
if (keyval.second[0] == '{' && keyval.second[keyval.second.size() - 1] == '}')
{
YAML::Node node = YAML::Load(keyval.second);
m_config.set_object(keyval.first, node);
} else
{
m_config.set_scalar(keyval.first, keyval.second); m_config.set_scalar(keyval.first, keyval.second);
}
} }

View File

@ -177,6 +177,16 @@ public:
node = value; node = value;
} }
/**
* Set the node identified by key to an object value
*/
void set_object(const std::string& key, const YAML::Node& value)
{
YAML::Node node;
get_node(node, key, true);
node = value;
}
/** /**
* Get the sequence value from the node identified by key. * Get the sequence value from the node identified by key.
*/ */
@ -482,5 +492,6 @@ namespace YAML {
return true; return true;
} }
// The "encode" function is not needed here, in fact you can simply YAML::load any json string.
}; };
} }