Skip to content

Commit

Permalink
new(falco): enable -o key={object} configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <[email protected]>
  • Loading branch information
LucaGuerra committed Sep 3, 2024
1 parent 4053c6e commit b8b8dab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions userspace/falco/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ falco_configuration::falco_configuration():
m_metrics_convert_memory_to_mb(true),
m_metrics_include_empty_values(false),
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);
}
Expand Down Expand Up @@ -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");
}

m_config.set_scalar(keyval.first, keyval.second);
if (keyval.second.find_first_of('{', 0) == 0 && keyval.second.find_first_of('}', 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);
}
}
11 changes: 11 additions & 0 deletions userspace/falco/yaml_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ class yaml_helper
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.
*/
Expand Down Expand Up @@ -482,5 +492,6 @@ namespace YAML {

return true;
}
// The "encode" function is not needed here, in fact you can simply YAML::load any json string.
};
}

0 comments on commit b8b8dab

Please sign in to comment.