new(userspace/falco): add webserver endpoint for retrieving internal versions

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2023-01-13 18:08:17 +00:00 committed by poiana
parent ea48ec70be
commit 55a6436ee8
3 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,7 @@ application::run_result application::start_webserver()
+ ssl_option + "\n");
m_state->webserver.start(
m_state->offline_inspector,
m_state->config->m_webserver_threadiness,
m_state->config->m_webserver_listen_port,
m_state->config->m_webserver_k8s_healthz_endpoint,

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "webserver.h"
#include "falco_utils.h"
#include "versions_info.h"
#include <atomic>
falco_webserver::~falco_webserver()
@ -24,6 +25,7 @@ falco_webserver::~falco_webserver()
}
void falco_webserver::start(
const std::shared_ptr<sinsp>& inspector,
uint32_t threadiness,
uint32_t listen_port,
std::string& healthz_endpoint,
@ -56,6 +58,13 @@ void falco_webserver::start(
[](const httplib::Request &, httplib::Response &res) {
res.set_content("{\"status\": \"ok\"}", "application/json");
});
// setup versions endpoint
const auto versions_json_str = falco::versions_info(inspector).as_json().dump();
m_server->Get("/versions",
[versions_json_str](const httplib::Request &, httplib::Response &res) {
res.set_content(versions_json_str, "application/json");
});
// run server in a separate thread
if (!m_server->is_valid())

View File

@ -19,6 +19,8 @@ limitations under the License.
#define CPPHTTPLIB_ZLIB_SUPPORT
#include <httplib.h>
#include <thread>
#include <memory>
#include <sinsp.h>
#include "configuration.h"
class falco_webserver
@ -26,6 +28,7 @@ class falco_webserver
public:
virtual ~falco_webserver();
virtual void start(
const std::shared_ptr<sinsp>& inspector,
uint32_t threadiness,
uint32_t listen_port,
std::string& healthz_endpoint,