Skip to content

Commit

Permalink
new(userspace/falco): added --config-schema action to print config …
Browse files Browse the repository at this point in the history
…schema.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and poiana committed Sep 6, 2024
1 parent dabfe0e commit f3eecb6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions userspace/falco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_library(falco_application STATIC
app/actions/validate_rules_files.cpp
app/actions/create_requested_paths.cpp
app/actions/close_inspectors.cpp
app/actions/print_config_schema.cpp
configuration.cpp
falco_outputs.cpp
outputs_file.cpp
Expand Down
1 change: 1 addition & 0 deletions userspace/falco/app/actions/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ falco::app::run_result list_plugins(const falco::app::state& s);
falco::app::run_result load_config(const falco::app::state& s);
falco::app::run_result load_plugins(falco::app::state& s);
falco::app::run_result load_rules_files(falco::app::state& s);
falco::app::run_result print_config_schema(falco::app::state& s);
falco::app::run_result print_generated_gvisor_config(falco::app::state& s);
falco::app::run_result print_help(falco::app::state& s);
falco::app::run_result print_ignored_events(const falco::app::state& s);
Expand Down
31 changes: 31 additions & 0 deletions userspace/falco/app/actions/print_config_schema.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2024 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "actions.h"

using namespace falco::app;
using namespace falco::app::actions;

falco::app::run_result falco::app::actions::print_config_schema(falco::app::state &s)
{
if(s.options.print_config_schema)
{
printf("%s", s.config->m_config_schema.dump(2).c_str());
return run_result::exit();
}
return run_result::ok();
}
1 change: 1 addition & 0 deletions userspace/falco/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool falco::app::run(falco::app::state& s, bool& restart, std::string& errstr)
// dependencies are honored (e.g. don't process events before
// loading plugins, opening inspector, etc.).
std::list<app_action> run_steps = {
falco::app::actions::print_config_schema,
falco::app::actions::load_config,
falco::app::actions::print_help,
falco::app::actions::print_kernel_version,
Expand Down
3 changes: 2 additions & 1 deletion userspace/falco/app/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ void options::define(cxxopts::Options& opts)
opts.add_options()
("h,help", "Print this help list and exit.", cxxopts::value(help)->default_value("false"))
#ifdef BUILD_TYPE_RELEASE
("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
#else
("c", "Configuration file. If not specified tries " FALCO_SOURCE_CONF_FILE ", " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
#endif
("config-schema", "Print the config json schema and exit.", cxxopts::value(print_config_schema)->default_value("false"))
("A", "Monitor all events supported by Falco and defined in rules and configs. Some events are ignored by default when -A is not specified (the -i option lists these events ignored). Using -A can impact performance. This option has no effect when reproducing events from a capture file.", cxxopts::value(all_events)->default_value("false"))
("b,print-base64", "Print data buffers in base64. This is useful for encoding binary data that needs to be used over media designed to consume this format.")
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(MINIMAL_BUILD)
Expand Down
1 change: 1 addition & 0 deletions userspace/falco/app/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class options {

// Each of these maps directly to a command line option.
bool help = false;
bool print_config_schema = false;
std::string conf_filename;
bool all_events = false;
sinsp_evt::param_fmt event_buffer_format = sinsp_evt::PF_NORMAL;
Expand Down

0 comments on commit f3eecb6

Please sign in to comment.