Remove 'default' as initial bucket name for Sia #54
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -286,7 +286,8 @@ enum class exit_code : std::int32_t {
|
|||||||
init_failed = -18,
|
init_failed = -18,
|
||||||
ui_mount_failed = -19,
|
ui_mount_failed = -19,
|
||||||
exception = -20,
|
exception = -20,
|
||||||
provider_offline = -21
|
provider_offline = -21,
|
||||||
|
ui_failed = -22
|
||||||
};
|
};
|
||||||
|
|
||||||
enum http_error_codes : std::int32_t {
|
enum http_error_codes : std::int32_t {
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef REPERTORY_INCLUDE_CLI_UI_HPP_
|
|
||||||
#define REPERTORY_INCLUDE_CLI_UI_HPP_
|
|
||||||
|
|
||||||
#include "cli/common.hpp"
|
|
||||||
#include "ui/handlers.hpp"
|
|
||||||
#include "ui/mgmt_app_config.hpp"
|
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
|
||||||
[[nodiscard]] inline auto
|
|
||||||
ui(std::vector<const char *> args, const std::string & /*data_directory*/,
|
|
||||||
const provider_type & /* prov */, const std::string & /* unique_id */,
|
|
||||||
std::string /* user */, std::string /* password */) -> exit_code {
|
|
||||||
|
|
||||||
ui::mgmt_app_config config{};
|
|
||||||
|
|
||||||
std::string data;
|
|
||||||
auto res = utils::cli::parse_string_option(
|
|
||||||
args, utils::cli::options::ui_port_option, data);
|
|
||||||
if (res == exit_code::success && not data.empty()) {
|
|
||||||
config.set_api_port(utils::string::to_uint16(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not utils::file::change_to_process_directory()) {
|
|
||||||
return exit_code::ui_mount_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
httplib::Server server;
|
|
||||||
if (not server.set_mount_point("/ui", "./web")) {
|
|
||||||
return exit_code::ui_mount_failed;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui::handlers handlers(&config, &server);
|
|
||||||
return exit_code::success;
|
|
||||||
}
|
|
||||||
} // namespace repertory::cli::actions
|
|
||||||
|
|
||||||
#endif // REPERTORY_INCLUDE_CLI_UI_HPP_
|
|
@@ -26,6 +26,8 @@
|
|||||||
#include "cli/actions.hpp"
|
#include "cli/actions.hpp"
|
||||||
#include "initialize.hpp"
|
#include "initialize.hpp"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
|
#include "ui/handlers.hpp"
|
||||||
|
#include "ui/mgmt_app_config.hpp"
|
||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
#include "utils/polling.hpp"
|
#include "utils/polling.hpp"
|
||||||
|
|
||||||
@@ -51,121 +53,143 @@ auto main(int argc, char **argv) -> int {
|
|||||||
args.push_back("-h");
|
args.push_back("-h");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto prov = utils::cli::get_provider_type_from_args(args);
|
int ret{0};
|
||||||
|
if (utils::cli::has_option(args, utils::cli::options::ui_option)) {
|
||||||
|
ui::mgmt_app_config config{};
|
||||||
|
|
||||||
std::string data_directory;
|
std::string data;
|
||||||
auto res = utils::cli::parse_string_option(
|
auto res = utils::cli::parse_string_option(
|
||||||
args, utils::cli::options::data_directory_option, data_directory);
|
args, utils::cli::options::ui_port_option, data);
|
||||||
|
if (res == exit_code::success && not data.empty()) {
|
||||||
|
config.set_api_port(utils::string::to_uint16(data));
|
||||||
|
}
|
||||||
|
|
||||||
std::string password;
|
if (not utils::file::change_to_process_directory()) {
|
||||||
res = (res == exit_code::success)
|
ret = static_cast<std::int32_t>(exit_code::ui_failed);
|
||||||
? utils::cli::parse_string_option(
|
} else {
|
||||||
args, utils::cli::options::password_option, password)
|
httplib::Server server;
|
||||||
: res;
|
if (not server.set_mount_point("/ui", "./web")) {
|
||||||
|
ret = static_cast<std::int32_t>(exit_code::ui_failed);
|
||||||
|
} else {
|
||||||
|
ui::handlers handlers(&config, &server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto prov = utils::cli::get_provider_type_from_args(args);
|
||||||
|
|
||||||
std::string user;
|
std::string data_directory;
|
||||||
res = (res == exit_code::success)
|
auto res = utils::cli::parse_string_option(
|
||||||
? utils::cli::parse_string_option(
|
args, utils::cli::options::data_directory_option, data_directory);
|
||||||
args, utils::cli::options::user_option, user)
|
|
||||||
: res;
|
|
||||||
|
|
||||||
std::string remote_host;
|
std::string password;
|
||||||
std::uint16_t remote_port{};
|
res = (res == exit_code::success)
|
||||||
std::string unique_id;
|
? utils::cli::parse_string_option(
|
||||||
if (res == exit_code::success) {
|
args, utils::cli::options::password_option, password)
|
||||||
if (prov == provider_type::remote) {
|
: res;
|
||||||
std::string data;
|
|
||||||
res = utils::cli::parse_string_option(
|
std::string user;
|
||||||
args, utils::cli::options::remote_mount_option, data);
|
res = (res == exit_code::success)
|
||||||
if (res == exit_code::success) {
|
? utils::cli::parse_string_option(
|
||||||
const auto parts = utils::string::split(data, ':', false);
|
args, utils::cli::options::user_option, user)
|
||||||
if (parts.size() != 2) {
|
: res;
|
||||||
std::cerr << "Invalid syntax for host/port '-rm "
|
|
||||||
"host:port,--remote_mount host:port'"
|
std::string remote_host;
|
||||||
<< std::endl;
|
std::uint16_t remote_port{};
|
||||||
res = exit_code::invalid_syntax;
|
std::string unique_id;
|
||||||
} else {
|
if (res == exit_code::success) {
|
||||||
unique_id = parts.at(0U) + ':' + parts.at(1U);
|
if (prov == provider_type::remote) {
|
||||||
remote_host = parts.at(0U);
|
std::string data;
|
||||||
try {
|
res = utils::cli::parse_string_option(
|
||||||
remote_port = utils::string::to_uint16(parts.at(1U));
|
args, utils::cli::options::remote_mount_option, data);
|
||||||
data_directory =
|
if (res == exit_code::success) {
|
||||||
data_directory.empty()
|
const auto parts = utils::string::split(data, ':', false);
|
||||||
? utils::path::combine(
|
if (parts.size() != 2) {
|
||||||
app_config::default_data_directory(prov),
|
std::cerr << "Invalid syntax for host/port '-rm "
|
||||||
{
|
"host:port,--remote_mount host:port'"
|
||||||
utils::string::replace_copy(unique_id, ':', '_'),
|
|
||||||
})
|
|
||||||
: utils::path::absolute(data_directory);
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
std::cerr << (e.what() == nullptr ? "Unable to parse port"
|
|
||||||
: e.what())
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
res = exit_code::invalid_syntax;
|
res = exit_code::invalid_syntax;
|
||||||
|
} else {
|
||||||
|
unique_id = parts.at(0U) + ':' + parts.at(1U);
|
||||||
|
remote_host = parts.at(0U);
|
||||||
|
try {
|
||||||
|
remote_port = utils::string::to_uint16(parts.at(1U));
|
||||||
|
data_directory =
|
||||||
|
data_directory.empty()
|
||||||
|
? utils::path::combine(
|
||||||
|
app_config::default_data_directory(prov),
|
||||||
|
{
|
||||||
|
utils::string::replace_copy(unique_id, ':',
|
||||||
|
'_'),
|
||||||
|
})
|
||||||
|
: utils::path::absolute(data_directory);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << (e.what() == nullptr ? "Unable to parse port"
|
||||||
|
: e.what())
|
||||||
|
<< std::endl;
|
||||||
|
res = exit_code::invalid_syntax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((prov == provider_type::s3) || (prov == provider_type::sia) ||
|
||||||
|
(prov == provider_type::encrypt)) {
|
||||||
|
std::string data;
|
||||||
|
res = utils::cli::parse_string_option(
|
||||||
|
args, utils::cli::options::name_option, data);
|
||||||
|
if (res == exit_code::success) {
|
||||||
|
unique_id = utils::string::trim(data);
|
||||||
|
if (unique_id.empty()) {
|
||||||
|
std::cerr << "Configuration name for '"
|
||||||
|
<< app_config::get_provider_display_name(prov)
|
||||||
|
<< "' was not provided" << std::endl;
|
||||||
|
res = exit_code::invalid_syntax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if ((prov == provider_type::s3) || (prov == provider_type::sia) ||
|
if (res == exit_code::success) {
|
||||||
(prov == provider_type::encrypt)) {
|
data_directory =
|
||||||
std::string data;
|
data_directory.empty()
|
||||||
res = utils::cli::parse_string_option(
|
? utils::path::combine(
|
||||||
args, utils::cli::options::name_option, data);
|
app_config::default_data_directory(prov), {unique_id})
|
||||||
if (res == exit_code::success) {
|
: utils::path::absolute(data_directory);
|
||||||
unique_id = utils::string::trim(data);
|
|
||||||
if (unique_id.empty()) {
|
|
||||||
std::cerr << "Configuration name for '"
|
|
||||||
<< app_config::get_provider_display_name(prov)
|
|
||||||
<< "' was not provided" << std::endl;
|
|
||||||
res = exit_code::invalid_syntax;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == exit_code::success) {
|
|
||||||
data_directory =
|
|
||||||
data_directory.empty()
|
|
||||||
? utils::path::combine(app_config::default_data_directory(prov),
|
|
||||||
{unique_id})
|
|
||||||
: utils::path::absolute(data_directory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int mount_result{};
|
int mount_result{};
|
||||||
if (res == exit_code::success) {
|
if (res == exit_code::success) {
|
||||||
if (utils::cli::has_option(args, utils::cli::options::help_option)) {
|
if (utils::cli::has_option(args, utils::cli::options::help_option)) {
|
||||||
cli::actions::help<repertory_drive>(args);
|
cli::actions::help<repertory_drive>(args);
|
||||||
} else if (utils::cli::has_option(args,
|
} else if (utils::cli::has_option(args,
|
||||||
utils::cli::options::version_option)) {
|
utils::cli::options::version_option)) {
|
||||||
cli::actions::version<repertory_drive>(args);
|
cli::actions::version<repertory_drive>(args);
|
||||||
} else {
|
} else {
|
||||||
res = exit_code::option_not_found;
|
res = exit_code::option_not_found;
|
||||||
for (std::size_t idx = 0U;
|
for (std::size_t idx = 0U;
|
||||||
(res == exit_code::option_not_found) &&
|
(res == exit_code::option_not_found) &&
|
||||||
(idx < utils::cli::options::option_list.size());
|
(idx < utils::cli::options::option_list.size());
|
||||||
idx++) {
|
idx++) {
|
||||||
try {
|
try {
|
||||||
res = cli::actions::perform_action(
|
res = cli::actions::perform_action(
|
||||||
utils::cli::options::option_list[idx], args, data_directory, prov,
|
utils::cli::options::option_list[idx], args, data_directory,
|
||||||
unique_id, user, password);
|
prov, unique_id, user, password);
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
res = exit_code::exception;
|
res = exit_code::exception;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
res = exit_code::exception;
|
res = exit_code::exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == exit_code::option_not_found) {
|
||||||
|
res = cli::actions::mount(args, data_directory, mount_result, prov,
|
||||||
|
remote_host, remote_port, unique_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == exit_code::option_not_found) {
|
|
||||||
res = cli::actions::mount(args, data_directory, mount_result, prov,
|
|
||||||
remote_host, remote_port, unique_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto ret =
|
ret = ((res == exit_code::mount_result) ? mount_result
|
||||||
((res == exit_code::mount_result) ? mount_result
|
: static_cast<std::int32_t>(res));
|
||||||
: static_cast<std::int32_t>(res));
|
}
|
||||||
|
|
||||||
repertory::project_cleanup();
|
repertory::project_cleanup();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user