The API req->param["name"] to access parameters in the path part of the URL was buggy - it forgot to do URL decoding and the result of our use of it in Scylla was bugs like #5883 - where special characters in certain REST API requests got botched up (encoded by the client, then not decoded by the server). The solution is to replace all uses of req->param["name"] by the new req->get_path_param("name"), which does the decoding correctly. Unfortunately we needed to change 104 (!) callers in this patch, but the transformation is mostly mechanical and there is no functional changes in this patch. Another set of changes was to bring req, not req->param, to a few functions that want to get the path param. This patch avoids the numerous deprecation warnings we had before, and more importantly, it fixes #5883. Signed-off-by: Nadav Har'El <nyh@scylladb.com>
75 lines
2.8 KiB
C++
75 lines
2.8 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include <seastar/core/coroutine.hh>
|
|
|
|
#include "gossiper.hh"
|
|
#include "api/api-doc/gossiper.json.hh"
|
|
#include "gms/endpoint_state.hh"
|
|
#include "gms/gossiper.hh"
|
|
#include "api/api.hh"
|
|
|
|
namespace api {
|
|
using namespace seastar::httpd;
|
|
using namespace json;
|
|
|
|
void set_gossiper(http_context& ctx, routes& r, gms::gossiper& g) {
|
|
httpd::gossiper_json::get_down_endpoint.set(r, [&g] (std::unique_ptr<request> req) -> future<json::json_return_type> {
|
|
auto res = co_await g.get_unreachable_members_synchronized();
|
|
co_return json::json_return_type(container_to_vec(res));
|
|
});
|
|
|
|
|
|
httpd::gossiper_json::get_live_endpoint.set(r, [&g] (std::unique_ptr<request> req) {
|
|
return g.get_live_members_synchronized().then([] (auto res) {
|
|
return make_ready_future<json::json_return_type>(container_to_vec(res));
|
|
});
|
|
});
|
|
|
|
httpd::gossiper_json::get_endpoint_downtime.set(r, [&g] (std::unique_ptr<request> req) -> future<json::json_return_type> {
|
|
gms::inet_address ep(req->get_path_param("addr"));
|
|
// synchronize unreachable_members on all shards
|
|
co_await g.get_unreachable_members_synchronized();
|
|
co_return g.get_endpoint_downtime(ep);
|
|
});
|
|
|
|
httpd::gossiper_json::get_current_generation_number.set(r, [&g] (std::unique_ptr<http::request> req) {
|
|
gms::inet_address ep(req->get_path_param("addr"));
|
|
return g.get_current_generation_number(ep).then([] (gms::generation_type res) {
|
|
return make_ready_future<json::json_return_type>(res.value());
|
|
});
|
|
});
|
|
|
|
httpd::gossiper_json::get_current_heart_beat_version.set(r, [&g] (std::unique_ptr<http::request> req) {
|
|
gms::inet_address ep(req->get_path_param("addr"));
|
|
return g.get_current_heart_beat_version(ep).then([] (gms::version_type res) {
|
|
return make_ready_future<json::json_return_type>(res.value());
|
|
});
|
|
});
|
|
|
|
httpd::gossiper_json::assassinate_endpoint.set(r, [&g](std::unique_ptr<http::request> req) {
|
|
if (req->get_query_param("unsafe") != "True") {
|
|
return g.assassinate_endpoint(req->get_path_param("addr")).then([] {
|
|
return make_ready_future<json::json_return_type>(json_void());
|
|
});
|
|
}
|
|
return g.unsafe_assassinate_endpoint(req->get_path_param("addr")).then([] {
|
|
return make_ready_future<json::json_return_type>(json_void());
|
|
});
|
|
});
|
|
|
|
httpd::gossiper_json::force_remove_endpoint.set(r, [&g](std::unique_ptr<http::request> req) {
|
|
gms::inet_address ep(req->get_path_param("addr"));
|
|
return g.force_remove_endpoint(ep, gms::null_permit_id).then([] {
|
|
return make_ready_future<json::json_return_type>(json_void());
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|