The name of the Scylla table backing an Alternator LSI looks like `basename:!lsiname`. Some REST API clients (including Scylla Manager) when they send a "!" character in the REST API request path may decide to "URL encode" it - convert it to `%21`.
Because of a Seastar bug (https://github.com/scylladb/seastar/issues/725) Scylla's REST API server forgets to do the URL decoding on the path part of the request, which leads to the REST API request failing to address the LSI table.
The first patch in this PR fixes the bug by using a new Seastar API introduced in https://github.com/scylladb/seastar/pull/2125 that does the URL decoding as appropriate. The second patch in the PR is a new test for this bug, which fails without the fix, and passes afterwards.
Fixes #5883.
Closes scylladb/scylladb#18286
* github.com:scylladb/scylladb:
test/alternator: test addressing LSI using REST API
REST API: stop using deprecated, buggy, path parameter
(cherry picked from commit 0438febdc9)
Signed-off-by: Nadav Har'El <nyh@scylladb.com>
107 lines
3.0 KiB
C++
107 lines
3.0 KiB
C++
/*
|
|
* Copyright 2018-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include "api/config.hh"
|
|
#include "api/api-doc/config.json.hh"
|
|
#include "db/config.hh"
|
|
#include <sstream>
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
namespace api {
|
|
using namespace seastar::httpd;
|
|
|
|
template<class T>
|
|
json::json_return_type get_json_return_type(const T& val) {
|
|
return json::json_return_type(val);
|
|
}
|
|
|
|
/*
|
|
* As commented on db::seed_provider_type is not used
|
|
* and probably never will.
|
|
*
|
|
* Just in case, we will return its name
|
|
*/
|
|
template<>
|
|
json::json_return_type get_json_return_type(const db::seed_provider_type& val) {
|
|
return json::json_return_type(val.class_name);
|
|
}
|
|
|
|
std::string_view format_type(std::string_view type) {
|
|
if (type == "int") {
|
|
return "integer";
|
|
}
|
|
return type;
|
|
}
|
|
|
|
future<> get_config_swagger_entry(std::string_view name, const std::string& description, std::string_view type, bool& first, output_stream<char>& os) {
|
|
std::stringstream ss;
|
|
if (first) {
|
|
first=false;
|
|
} else {
|
|
ss <<',';
|
|
};
|
|
ss << "\"/v2/config/" << name <<"\": {"
|
|
"\"get\": {"
|
|
"\"description\": \"" << boost::replace_all_copy(boost::replace_all_copy(boost::replace_all_copy(description,"\n","\\n"),"\"", "''"), "\t", " ") <<"\","
|
|
"\"operationId\": \"find_config_"<< name <<"\","
|
|
"\"produces\": ["
|
|
"\"application/json\""
|
|
"],"
|
|
"\"tags\": [\"config\"],"
|
|
"\"parameters\": ["
|
|
"],"
|
|
"\"responses\": {"
|
|
"\"200\": {"
|
|
"\"description\": \"Config value\","
|
|
"\"schema\": {"
|
|
"\"type\": \"" << format_type(type) << "\""
|
|
"}"
|
|
"},"
|
|
"\"default\": {"
|
|
"\"description\": \"unexpected error\","
|
|
"\"schema\": {"
|
|
"\"$ref\": \"#/definitions/ErrorModel\""
|
|
"}"
|
|
"}"
|
|
"}"
|
|
"}"
|
|
"}";
|
|
return os.write(ss.str());
|
|
}
|
|
|
|
namespace cs = httpd::config_json;
|
|
|
|
void set_config(std::shared_ptr < api_registry_builder20 > rb, http_context& ctx, routes& r, const db::config& cfg, bool first) {
|
|
rb->register_function(r, [&cfg, first] (output_stream<char>& os) {
|
|
return do_with(first, [&os, &cfg] (bool& first) {
|
|
auto f = make_ready_future();
|
|
for (auto&& cfg_ref : cfg.values()) {
|
|
auto&& cfg = cfg_ref.get();
|
|
f = f.then([&os, &first, &cfg] {
|
|
return get_config_swagger_entry(cfg.name(), std::string(cfg.desc()), cfg.type_name(), first, os);
|
|
});
|
|
}
|
|
return f;
|
|
});
|
|
});
|
|
|
|
cs::find_config_id.set(r, [&cfg] (const_req r) {
|
|
auto id = r.get_path_param("id");
|
|
for (auto&& cfg_ref : cfg.values()) {
|
|
auto&& cfg = cfg_ref.get();
|
|
if (id == cfg.name()) {
|
|
return cfg.value_as_json();
|
|
}
|
|
}
|
|
throw bad_param_exception(sstring("No such config entry: ") + id);
|
|
});
|
|
}
|
|
|
|
}
|
|
|