Skip to content

Commit f3eecb6

Browse files
FedeDPpoiana
authored andcommitted
new(userspace/falco): added --config-schema action to print config schema.
Signed-off-by: Federico Di Pierro <[email protected]>
1 parent dabfe0e commit f3eecb6

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

userspace/falco/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_library(falco_application STATIC
4949
app/actions/validate_rules_files.cpp
5050
app/actions/create_requested_paths.cpp
5151
app/actions/close_inspectors.cpp
52+
app/actions/print_config_schema.cpp
5253
configuration.cpp
5354
falco_outputs.cpp
5455
outputs_file.cpp

userspace/falco/app/actions/actions.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ falco::app::run_result list_plugins(const falco::app::state& s);
3838
falco::app::run_result load_config(const falco::app::state& s);
3939
falco::app::run_result load_plugins(falco::app::state& s);
4040
falco::app::run_result load_rules_files(falco::app::state& s);
41+
falco::app::run_result print_config_schema(falco::app::state& s);
4142
falco::app::run_result print_generated_gvisor_config(falco::app::state& s);
4243
falco::app::run_result print_help(falco::app::state& s);
4344
falco::app::run_result print_ignored_events(const falco::app::state& s);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
/*
3+
Copyright (C) 2024 The Falco Authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
#include "actions.h"
19+
20+
using namespace falco::app;
21+
using namespace falco::app::actions;
22+
23+
falco::app::run_result falco::app::actions::print_config_schema(falco::app::state &s)
24+
{
25+
if(s.options.print_config_schema)
26+
{
27+
printf("%s", s.config->m_config_schema.dump(2).c_str());
28+
return run_result::exit();
29+
}
30+
return run_result::ok();
31+
}

userspace/falco/app/app.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bool falco::app::run(falco::app::state& s, bool& restart, std::string& errstr)
6060
// dependencies are honored (e.g. don't process events before
6161
// loading plugins, opening inspector, etc.).
6262
std::list<app_action> run_steps = {
63+
falco::app::actions::print_config_schema,
6364
falco::app::actions::load_config,
6465
falco::app::actions::print_help,
6566
falco::app::actions::print_kernel_version,

userspace/falco/app/options.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ void options::define(cxxopts::Options& opts)
110110
opts.add_options()
111111
("h,help", "Print this help list and exit.", cxxopts::value(help)->default_value("false"))
112112
#ifdef BUILD_TYPE_RELEASE
113-
("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
113+
("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
114114
#else
115115
("c", "Configuration file. If not specified tries " FALCO_SOURCE_CONF_FILE ", " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "<path>")
116116
#endif
117+
("config-schema", "Print the config json schema and exit.", cxxopts::value(print_config_schema)->default_value("false"))
117118
("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"))
118119
("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.")
119120
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(MINIMAL_BUILD)

userspace/falco/app/options.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class options {
4040

4141
// Each of these maps directly to a command line option.
4242
bool help = false;
43+
bool print_config_schema = false;
4344
std::string conf_filename;
4445
bool all_events = false;
4546
sinsp_evt::param_fmt event_buffer_format = sinsp_evt::PF_NORMAL;

0 commit comments

Comments
 (0)