Compare commits

...

3 Commits

Author SHA1 Message Date
bf11906434 [ui] Implement provider test button #49
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2025-04-24 07:00:48 -05:00
6fe6ccbbfe [ui] Implement provider test button #49 2025-04-24 06:56:55 -05:00
1a02d89ab9 [ui] Implement provider test button #49 2025-04-24 06:54:53 -05:00
2 changed files with 32 additions and 8 deletions

View File

@ -315,6 +315,8 @@ auto handlers::data_directory_exists(provider_type prov,
void handlers::generate_config(provider_type prov, std::string_view name,
const json &cfg,
std::optional<std::string> data_dir) const {
REPERTORY_USES_FUNCTION_NAME();
std::map<std::string, std::string> values{};
for (const auto &[key, value] : cfg.items()) {
if (value.is_object()) {
@ -342,7 +344,13 @@ void handlers::generate_config(provider_type prov, std::string_view name,
}
if (data_dir.has_value()) {
utils::file::directory{data_dir.value()}.create_directory();
if (not utils::file::directory{data_dir.value()}.create_directory()) {
throw utils::error::create_exception(function_name,
{
"failed to create data diretory",
data_dir.value(),
});
}
launch_process(prov, name, {"-dd", data_dir.value(), "-gc"});
} else {
launch_process(prov, name, {"-gc"});
@ -521,6 +529,8 @@ void handlers::handle_get_settings(httplib::Response &res) const {
void handlers::handle_get_test(const httplib::Request &req,
httplib::Response &res) const {
REPERTORY_USES_FUNCTION_NAME();
unique_mutex_lock lock(test_mtx_);
auto name = req.get_param_value("name");
@ -530,13 +540,24 @@ void handlers::handle_get_test(const httplib::Request &req,
auto data_dir = utils::path::combine(
utils::directory::temp(), {utils::file::create_temp_name("repertory")});
try {
generate_config(prov, name, cfg, data_dir);
auto lines = launch_process(prov, name, {"-dd", data_dir, "-test"});
res.status = lines.at(0U) == "0" ? http_error_codes::ok
: http_error_codes::internal_error;
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e, "test provider config failed");
res.status = http_error_codes::internal_error;
}
utils::file::directory{data_dir}.remove_recursively();
if (utils::file::directory{data_dir}.remove_recursively()) {
return;
}
utils::error::raise_error(
function_name, e,
fmt::format("failed to remove data directory|{}", data_dir));
}
void handlers::handle_post_add_mount(const httplib::Request &req,
@ -551,7 +572,6 @@ void handlers::handle_post_add_mount(const httplib::Request &req,
auto cfg = nlohmann::json::parse(req.get_param_value("config"));
generate_config(prov, name, cfg);
launch_process(prov, name, {"-test"});
res.status = http_error_codes::ok;
}

View File

@ -285,11 +285,15 @@ class Mount with ChangeNotifier {
Future<bool> test() async {
try {
final map = await convertAllToString(
jsonDecode(jsonEncode(mountConfig.settings)),
_auth.key,
);
final auth = await _auth.createAuth();
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(mountConfig.settings)}',
'${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&config=${jsonEncode(map)}',
),
),
);