initial commit
Some checks failed
BlockStorage/repertory_osx/pipeline/head There was a failure building this commit
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

This commit is contained in:
2022-03-05 00:30:50 -06:00
commit 3ff46723b8
626 changed files with 178600 additions and 0 deletions

96
include/cli/actions.hpp Normal file
View File

@ -0,0 +1,96 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_ACTIONS_HPP_
#define INCLUDE_CLI_ACTIONS_HPP_
#include "common.hpp"
#include "cli/check_version.hpp"
#include "cli/display_config.hpp"
#include "cli/drive_information.hpp"
#include "cli/export.hpp"
#include "cli/export_all.hpp"
#include "cli/get.hpp"
#include "cli/get_directory_items.hpp"
#include "cli/get_pinned_files.hpp"
#include "cli/help.hpp"
#include "cli/import.hpp"
#include "cli/import_json.hpp"
#include "cli/mount.hpp"
#include "cli/open_files.hpp"
#include "cli/pin_file.hpp"
#include "cli/pinned_status.hpp"
#include "cli/set.hpp"
#include "cli/status.hpp"
#include "cli/test_skynet_auth.hpp"
#include "cli/unmount.hpp"
#include "cli/unpin_file.hpp"
#include "cli/version.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
typedef std::function<exit_code(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password)>
action;
struct option_hasher {
std::size_t operator()(const utils::cli::option &opt) const {
return std::hash<std::string>()(opt[0u] + '|' + opt[1u]);
}
};
static const std::unordered_map<utils::cli::option, action, option_hasher> option_actions = {
{utils::cli::options::check_version_option, cli::actions::check_version},
{utils::cli::options::display_config_option, cli::actions::display_config},
{utils::cli::options::drive_information_option, cli::actions::drive_information},
{utils::cli::options::export_option, cli::actions::export_action},
{utils::cli::options::export_all_option, cli::actions::export_all},
{utils::cli::options::get_directory_items_option, cli::actions::get_directory_items},
{utils::cli::options::get_option, cli::actions::get},
{utils::cli::options::get_pinned_files_option, cli::actions::get_pinned_files},
{utils::cli::options::import_option, cli::actions::import},
{utils::cli::options::import_json_option, cli::actions::import_json},
{utils::cli::options::open_files_option, cli::actions::open_files},
{utils::cli::options::pin_file_option, cli::actions::pin_file},
{utils::cli::options::pinned_status_option, cli::actions::pinned_status},
{utils::cli::options::set_option, cli::actions::set},
{utils::cli::options::status_option, cli::actions::status},
#if defined(REPERTORY_ENABLE_SKYNET)
{utils::cli::options::test_skynet_auth_option, cli::actions::test_skynet_auth},
#endif
{utils::cli::options::unmount_option, cli::actions::unmount},
{utils::cli::options::unpin_file_option, cli::actions::unpin_file},
};
static exit_code perform_action(const utils::cli::option &opt, const int &argc, char *argv[],
const std::string &data_directory, const provider_type &pt,
const std::string &unique_id, std::string user,
std::string password) {
if (utils::cli::has_option(argc, argv, opt)) {
if (option_actions.find(opt) != option_actions.end()) {
return option_actions.at(opt)(argc, argv, data_directory, pt, unique_id, std::move(user),
std::move(password));
}
}
return exit_code::option_not_found;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_ACTIONS_HPP_

View File

@ -0,0 +1,63 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_CHECK_VERSION_HPP_
#define INCLUDE_CLI_CHECK_VERSION_HPP_
#include "common.hpp"
#include "comm/curl/curl_comm.hpp"
#include "app_config.hpp"
#include "types/repertory.hpp"
namespace repertory::cli::actions {
static exit_code check_version(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string,
std::string) {
auto ret = exit_code::success;
if (not((pt == provider_type::remote) || (pt == provider_type::s3) ||
(pt == provider_type::skynet))) {
app_config config(pt, data_directory);
curl_comm comm(config);
json data, err;
if (comm.get("/daemon/version", data, err) == api_error::success) {
const auto res = utils::compare_version_strings(data["version"].get<std::string>(),
app_config::get_provider_minimum_version(pt));
if (res < 0) {
ret = exit_code::incompatible_version;
std::cerr << "Failed!" << std::endl;
std::cerr << " Actual: " << data["version"].get<std::string>() << std::endl;
std::cerr << " Minimum: " << app_config::get_provider_minimum_version(pt) << std::endl;
} else {
std::cout << "Success!" << std::endl;
std::cout << " Actual: " << data["version"].get<std::string>() << std::endl;
std::cout << " Minimum: " << app_config::get_provider_minimum_version(pt) << std::endl;
}
} else {
std::cerr << "Failed!" << std::endl;
std::cerr << err.dump(2) << std::endl;
ret = exit_code::communication_error;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_CHECK_VERSION_HPP_

View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_DISPLAY_CONFIG_HPP_
#define INCLUDE_CLI_DISPLAY_CONFIG_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "platform/platform.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code display_config(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password) {
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
if (res == lock_result::success) {
app_config config(pt, data_directory);
const auto cfg = config.get_json();
std::cout << 0 << std::endl;
std::cout << cfg.dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).get_config();
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
}
return exit_code::success;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_DISPLAY_CONFIG_HPP_

View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_DRIVE_INFORMATION_HPP_
#define INCLUDE_CLI_DRIVE_INFORMATION_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "platform/platform.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code drive_information(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password) {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).get_drive_information();
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted." << std::endl;
ret = exit_code::not_mounted;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_DRIVE_INFORMATION_HPP_

53
include/cli/export.hpp Normal file
View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_EXPORT_HPP_
#define INCLUDE_CLI_EXPORT_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code export_action(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(argc, argv,
repertory::utils::cli::options::export_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response =
client({"localhost", password, port, user}).export_list(utils::string::split(data, ','));
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::export_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_EXPORT_HPP_

View File

@ -0,0 +1,49 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_EXPORT_ALL_HPP_
#define INCLUDE_CLI_EXPORT_ALL_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code export_all(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
auto ret = exit_code::success;
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).export_all();
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::export_failed;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_EXPORT_ALL_HPP_

60
include/cli/get.hpp Normal file
View File

@ -0,0 +1,60 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_GET_HPP_
#define INCLUDE_CLI_GET_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "platform/platform.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code get(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id, std::string user,
std::string password) {
std::string data;
auto ret =
utils::cli::parse_string_option(argc, argv, repertory::utils::cli::options::get_option, data);
if (ret == exit_code::success) {
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1);
if (res == lock_result::success) {
app_config config(pt, data_directory);
const auto value = config.get_value_by_name(data);
std::cout << (value.empty() ? static_cast<int>(rpc_response_type::config_value_not_found) : 0)
<< std::endl;
std::cout << json({{"value", value}}).dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response =
client({"localhost", password, port, user}).get_config_value_by_name(data);
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_GET_HPP_

View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_GET_DIRECTORY_ITEMS_HPP_
#define INCLUDE_CLI_GET_DIRECTORY_ITEMS_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code get_directory_items(const int &argc, char *argv[],
const std::string &data_directory, const provider_type &pt,
const std::string &, std::string user, std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::get_directory_items_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).get_directory_items(data);
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::export_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_GETDIRECTORYITEMS_HPP_

View File

@ -0,0 +1,48 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_GET_PINNED_FILES_HPP_
#define INCLUDE_CLI_GET_PINNED_FILES_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code get_pinned_files(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
auto ret = exit_code::success;
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).get_pinned_files();
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::export_failed;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_GET_PINNED_FILES_HPP_

106
include/cli/help.hpp Normal file
View File

@ -0,0 +1,106 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_HELP_HPP_
#define INCLUDE_CLI_HELP_HPP_
#include "common.hpp"
namespace repertory::cli::actions {
template <typename drive> static void help(const int &argc, char *argv[]) {
drive::display_options(argc, argv);
std::cout << "Repertory options:" << std::endl;
std::cout << " -cv,--check_version Check daemon version compatibility"
<< std::endl;
std::cout << " -dc,--display_config Display configuration" << std::endl;
std::cout << " -dd,--data_directory [directory] Override data directory" << std::endl;
std::cout << " -di,--drive_information Display mounted drive information"
<< std::endl;
#if defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -ea,--export_all Export all Skynet skylinks" << std::endl;
std::cout << " -ex,--export [path1,path2,...] Export one or more Skynet skylinks"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_SKYNET)
#if defined(REPERTORY_ENABLE_S3)
std::cout << " -s3,--s3 Enables S3 mode" << std::endl;
std::cout << " -na,--name Unique name for S3 instance [Required]"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_S3)
std::cout << " -gc,--generate_config Generate initial configuration" << std::endl;
std::cout << " -get,--get [name] Get configuration value" << std::endl;
std::cout << " -gdi,--get_directory_items Get directory list in json format"
<< std::endl
<< " [API path]" << std::endl;
std::cout << " -gpf,--get_pinned_files Get a list of all pinned files" << std::endl;
std::cout << " -gt,--generate_template Generate configuration template" << std::endl;
#if defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -ij,--import_json [json_array] Import Skynet skylink(s)" << std::endl;
std::cout << " [json_array] format:" << std::endl;
std::cout << " [{" << std::endl;
std::cout << R"( "directory": "/parent",)" << std::endl;
std::cout << R"( "skylink": "AACeCiD6WQG6DzDcCdIu3cFPSxMUMoQPx46NYSyijNMKUA",)"
<< std::endl;
std::cout << R"( "token": "encryption password")" << std::endl;
std::cout << " }]" << std::endl;
std::cout << " NOTE: 'directory' and 'token' are optional" << std::endl;
std::cout << " -im,--import [list] Import Skynet skylink(s)" << std::endl;
std::cout << " [list] format:" << std::endl;
std::cout << " directory=<directory>:skylink=<skylink>:token=<token>;..." << std::endl;
std::cout << std::endl;
std::cout << " NOTE: 'directory' and 'token' are optional" << std::endl;
std::cout << " NOTE: Use '@sem@' to escape a ';'" << std::endl;
std::cout << " Use '@comma@' to escape a ','" << std::endl;
std::cout << " Use '@equal@' to escape an '='" << std::endl;
std::cout << " Use '@dbl_quote@' to escape a '\"'" << std::endl;
#endif // defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -nc Force disable console output" << std::endl;
std::cout << " -of,--open_files List all open files and count" << std::endl;
std::cout << " -rm,--remote_mount [host/ip:port] Enables remote mount mode" << std::endl;
std::cout << " -pf,--pin_file [API path] Pin a file to cache to prevent eviction"
<< std::endl;
std::cout << " -ps,--pinned_status [API path] Return pinned status for a file" << std::endl;
std::cout << " -pw,--password Specify API password" << std::endl;
#if defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -sk,--skynet [EXPERIMENTAL] Enables Skynet mode"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_SKYNET)
#ifndef _WIN32
#if defined(REPERTORY_ENABLE_S3)
std::cout << " -o s3 Enables S3 mode for 'fstab' mounts"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_S3)
#if defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -o sk,-o skynet Enables Skynet mode for 'fstab' mounts"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_SKYNET)
#endif // _WIN32
std::cout << " -set,--set [name] [value] Set configuration value" << std::endl;
std::cout << " -status Display mount status" << std::endl;
#if defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -tsa,--test_skynet_auth Test Skynet portal authentication"
<< std::endl;
std::cout << " [URL] [user] [password] [agent string] [API key]" << std::endl;
#endif // defined(REPERTORY_ENABLE_SKYNET)
std::cout << " -unmount,--unmount Unmount and shutdown" << std::endl;
std::cout << " -uf,--unpin_file [API path] Unpin a file from cache to allow eviction"
<< std::endl;
std::cout << " -us,--user Specify API user name" << std::endl;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_HELP_HPP_

62
include/cli/import.hpp Normal file
View File

@ -0,0 +1,62 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_IMPORT_HPP_
#define INCLUDE_CLI_IMPORT_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code import(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(argc, argv,
repertory::utils::cli::options::import_option, data);
if (ret == exit_code::success) {
utils::string::replace(data, "@dbl_quote@", "\"");
const auto parts = utils::string::split(data, ';');
skylink_import_list list;
for (const auto &part : parts) {
list.emplace_back(
skylink_import::from_string(utils::string::replace_copy(part, "@sem@", ";")));
}
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).import_skylink(list);
std::cout << static_cast<int>(response.response_type) << std::endl;
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::import_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_IMPORT_HPP_

View File

@ -0,0 +1,68 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_IMPORT_JSON_HPP_
#define INCLUDE_CLI_IMPORT_JSON_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code import_json(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(argc, argv, {"-ij", "--import_json"}, data);
if (ret == exit_code::success) {
utils::string::replace(data, "@dbl_quote@", "\"");
skylink_import_list list;
try {
const auto json_data = json::parse(data);
for (const auto &j : json_data) {
list.emplace_back(skylink_import::from_json(j));
}
} catch (const std::exception &e) {
std::cerr << "Import JSON failed:" << std::endl << e.what() << std::endl;
ret = exit_code::import_failed;
}
if (not list.empty()) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).import_skylink(list);
std::cout << static_cast<int>(response.response_type) << std::endl;
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::import_failed;
}
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_IMPORT_JSON_HPP_

159
include/cli/mount.hpp Normal file
View File

@ -0,0 +1,159 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_MOUNT_HPP_
#define INCLUDE_CLI_MOUNT_HPP_
#include "common.hpp"
#include "platform/platform.hpp"
#include "providers/provider.hpp"
#include "types/repertory.hpp"
#include "utils/cli_utils.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/file_utils.hpp"
#ifdef _WIN32
#include "drives/winfsp/remotewinfsp/remote_client.hpp"
#include "drives/winfsp/remotewinfsp/remote_winfsp_drive.hpp"
#include "drives/winfsp/winfsp_drive.hpp"
typedef repertory::winfsp_drive repertory_drive;
typedef repertory::remote_winfsp::remote_client remote_client;
typedef repertory::remote_winfsp::remote_winfsp_drive remote_drive;
typedef repertory::remote_winfsp::i_remote_instance remote_instance;
#else
#include "drives/fuse/fuse_drive.hpp"
#include "drives/fuse/remotefuse/remote_client.hpp"
#include "drives/fuse/remotefuse/remote_fuse_drive.hpp"
typedef repertory::fuse_drive repertory_drive;
typedef repertory::remote_fuse::remote_client remote_client;
typedef repertory::remote_fuse::remote_fuse_drive remote_drive;
typedef repertory::remote_fuse::i_remote_instance remote_instance;
#endif
namespace repertory::cli::actions {
static exit_code mount(const int &argc, char *argv[], std::string data_directory, int &mount_result,
provider_type pt, const std::string &remote_host,
const std::uint16_t &remote_port, const std::string &unique_id) {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock();
if (res == lock_result::locked) {
ret = exit_code::mount_active;
std::cerr << app_config::get_provider_display_name(pt) << " mount is already active"
<< std::endl;
} else if (res == lock_result::success) {
curl_global_init(CURL_GLOBAL_DEFAULT);
{
const auto generate_config =
utils::cli::has_option(argc, argv, utils::cli::options::generate_config_option);
if (generate_config) {
app_config config(pt, data_directory);
if (pt == provider_type::remote) {
config.set_enable_remote_mount(false);
config.set_is_remote_mount(true);
config.set_remote_host_name_or_ip(remote_host);
config.set_remote_port(remote_port);
}
std::cout << "Generated " << app_config::get_provider_display_name(pt) << " Configuration"
<< std::endl;
std::cout << config.get_config_file_path() << std::endl;
ret = utils::file::is_file(config.get_config_file_path()) ? exit_code::success
: exit_code::file_creation_failed;
} else {
#ifdef _WIN32
if (utils::cli::has_option(argc, argv, utils::cli::options::hidden_option)) {
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
#endif
const auto driveArgs = utils::cli::parse_drive_options(argc, argv, pt, data_directory);
std::cout << "Initializing " << app_config::get_provider_display_name(pt)
<< (unique_id.empty() ? ""
: (pt == provider_type::s3)
? " [" + unique_id + ']'
: " [" + remote_host + ':' + std::to_string(remote_port) + ']')
<< " Drive" << std::endl;
app_config config(pt, data_directory);
if (pt == provider_type::remote) {
std::uint16_t port = 0u;
if (utils::get_next_available_port(config.get_api_port(), port)) {
config.set_remote_host_name_or_ip(remote_host);
config.set_remote_port(remote_port);
config.set_api_port(port);
config.set_is_remote_mount(true);
config.set_enable_remote_mount(false);
config.save();
try {
remote_drive drive(config, lock, [&config]() -> std::unique_ptr<remote_instance> {
return std::unique_ptr<remote_instance>(new remote_client(config));
});
lock.set_mount_state(true, "", -1);
mount_result = drive.mount(driveArgs);
ret = exit_code::mount_result;
} catch (const std::exception &e) {
std::cerr << "FATAL: " << e.what() << std::endl;
ret = exit_code::startup_exception;
}
} else {
std::cerr << "FATAL: Unable to get available port" << std::endl;
ret = exit_code::startup_exception;
}
} else {
#ifdef _WIN32
if (config.get_enable_mount_manager() && not utils::is_process_elevated()) {
com_init_wrapper cw;
lock.set_mount_state(true, "elevating", -1);
lock.release();
mount_result = utils::run_process_elevated(argc, argv);
lock_data lockData2(pt, unique_id);
if (lockData2.grab_lock() == lock_result::success) {
lockData2.set_mount_state(false, "", -1);
lockData2.release();
}
return exit_code::mount_result;
}
#endif
config.set_is_remote_mount(false);
try {
auto provider = create_provider(pt, config);
repertory_drive drive(config, lock, *provider);
lock.set_mount_state(true, "", -1);
mount_result = drive.mount(driveArgs);
ret = exit_code::mount_result;
} catch (const std::exception &e) {
std::cerr << "FATAL: " << e.what() << std::endl;
ret = exit_code::startup_exception;
}
}
}
}
curl_global_cleanup();
} else {
ret = exit_code::lock_failed;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_MOUNT_HPP_

View File

@ -0,0 +1,52 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_OPEN_FILES_HPP_
#define INCLUDE_CLI_OPEN_FILES_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "platform/platform.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code open_files(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id, std::string user,
std::string password) {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).get_open_files();
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted." << std::endl;
ret = exit_code::not_mounted;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_OPEN_FILES_HPP_

53
include/cli/pin_file.hpp Normal file
View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_PIN_FILE_HPP_
#define INCLUDE_CLI_PIN_FILE_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code pin_file(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(argc, argv,
repertory::utils::cli::options::pin_file_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).pin_file(data);
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::pin_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_PIN_FILE_HPP_

View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_PINNED_STATUS_HPP_
#define INCLUDE_CLI_PINNED_STATUS_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code pinned_status(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::pinned_status_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).pinned_status(data);
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::export_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_PINNED_STATUS_HPP_

72
include/cli/set.hpp Normal file
View File

@ -0,0 +1,72 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_SET_HPP_
#define INCLUDE_CLI_SET_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "platform/platform.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code set(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id, std::string user,
std::string password) {
auto ret = exit_code::success;
auto data = utils::cli::parse_option(argc, argv, "-set", 2u);
if (data.empty()) {
data = utils::cli::parse_option(argc, argv, "--set", 2u);
if (data.empty()) {
ret = exit_code::invalid_syntax;
std::cerr << "Invalid syntax for '-set'" << std::endl;
}
}
if (ret == exit_code::success) {
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
if (res == lock_result::success) {
app_config config(pt, data_directory);
const auto value = config.set_value_by_name(data[0u], data[1u]);
const auto notFound = value.empty() && not data[1u].empty();
ret = notFound ? exit_code::set_option_not_found : exit_code::success;
std::cout << (notFound ? static_cast<int>(rpc_response_type::config_value_not_found) : 0)
<< std::endl;
std::cout << json({{"value", value}}).dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response =
client({"localhost", password, port, user}).set_config_value_by_name(data[0u], data[1u]);
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
ret = response.response_type == rpc_response_type::config_value_not_found
? exit_code::set_option_not_found
: response.response_type == rpc_response_type::success ? exit_code::success
: exit_code::communication_error;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_SET_HPP_

44
include/cli/status.hpp Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_STATUS_HPP_
#define INCLUDE_CLI_STATUS_HPP_
#include "common.hpp"
#include "platform/platform.hpp"
#include "types/repertory.hpp"
namespace repertory::cli::actions {
static exit_code status(const int &, char *[], const std::string &, const provider_type &pt,
const std::string &unique_id, std::string, std::string) {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
lock.grab_lock(10u);
json mount_state;
if (lock.get_mount_state(mount_state)) {
std::cout << mount_state.dump(2) << std::endl;
} else {
std::cout << "{}" << std::endl;
ret = exit_code::failed_to_get_mount_state;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_STATUS_HPP_

View File

@ -0,0 +1,91 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_
#define INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_
#ifdef REPERTORY_ENABLE_SKYNET
#include "common.hpp"
#include "comm/curl/curl_comm.hpp"
#include "app_config.hpp"
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "types/repertory.hpp"
#include "utils/cli_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory::cli::actions {
static exit_code test_skynet_auth(const int &argc, char *argv[], const std::string &,
const provider_type &, const std::string &, std::string,
std::string) {
auto ret = exit_code::success;
auto data = utils::cli::parse_option(argc, argv, "-tsa", 5u);
if (data.empty()) {
data = utils::cli::parse_option(argc, argv, "--test_skynet_auth", 5u);
if (data.empty()) {
ret = exit_code::invalid_syntax;
std::cerr << "Invalid syntax for '-tsa'" << std::endl;
}
}
const auto uuid = utils::create_uuid_string();
const auto config_directory = utils::path::absolute(utils::path::combine("./", {uuid}));
if (ret == exit_code::success) {
utils::file::change_to_process_directory();
{
console_consumer c;
event_system::instance().start();
app_config config(provider_type::skynet, config_directory);
host_config hc{};
hc.auth_url = data[0];
hc.auth_user = data[1];
hc.auth_password = data[2];
hc.agent_string = data[3];
hc.api_password = data[4];
curl_comm comm(config);
std::string session;
CURL *curl_handle = nullptr;
ret = (comm.create_auth_session(curl_handle, config, hc, session))
? exit_code::success
: exit_code::communication_error;
if (ret == exit_code::success) {
curl_easy_cleanup(curl_handle);
comm.release_auth_session(config, hc, session);
}
event_system::instance().stop();
}
if (ret == exit_code::success) {
std::cout << std::endl << "Authentication Succeeded!" << std::endl;
} else {
std::cerr << std::endl << "Authentication Failed!" << std::endl;
}
}
utils::file::delete_directory_recursively(config_directory);
return ret;
}
} // namespace repertory::cli::actions
#endif // REPERTORY_ENABLE_SKYNET
#endif // INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_

49
include/cli/unmount.hpp Normal file
View File

@ -0,0 +1,49 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_UNMOUNT_HPP_
#define INCLUDE_CLI_UNMOUNT_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code unmount(const int &, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
auto ret = exit_code::success;
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).unmount();
std::cout << static_cast<int>(response.response_type) << std::endl;
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::communication_error;
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_UNMOUNT_HPP_

View File

@ -0,0 +1,53 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_UNPIN_FILE_HPP_
#define INCLUDE_CLI_UNPIN_FILE_HPP_
#include "common.hpp"
#include "app_config.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "types/skynet.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
static exit_code unpin_file(const int &argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::unpin_file_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
const auto response = client({"localhost", password, port, user}).unpin_file(data);
if (response.response_type == rpc_response_type::success) {
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << response.data.dump(2) << std::endl;
ret = exit_code::unpin_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_UNPIN_FILE_HPP_

32
include/cli/version.hpp Normal file
View File

@ -0,0 +1,32 @@
/*
Copyright <2018-2022> <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 INCLUDE_CLI_VERSION_HPP_
#define INCLUDE_CLI_VERSION_HPP_
#include "common.hpp"
namespace repertory::cli::actions {
template <typename drive> static void version(const int &argc, char *argv[]) {
std::cout << "Repertory core version: " << get_repertory_version() << std::endl;
std::cout << "Repertory Git revision: " << get_repertory_git_revision() << std::endl;
drive::display_version_information(argc, argv);
}
} // namespace repertory::cli::actions
#endif // INCLUDE_CLI_VERSION_HPP_