This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
namespace dropshell
|
||||
{
|
||||
|
||||
server_config::server_config(const std::string &server_name) : mValid(false), mServerName(server_name)
|
||||
ServerConfig::ServerConfig(const std::string &server_name) : mValid(false), mServerName(server_name)
|
||||
{
|
||||
if (server_name.empty())
|
||||
return;
|
||||
@@ -110,22 +110,22 @@ namespace dropshell
|
||||
}
|
||||
}
|
||||
|
||||
std::string server_config::get_SSH_HOST() const
|
||||
std::string ServerConfig::get_SSH_HOST() const
|
||||
{
|
||||
return get_variable("SSH_HOST");
|
||||
}
|
||||
|
||||
std::string server_config::get_SSH_PORT() const
|
||||
std::string ServerConfig::get_SSH_PORT() const
|
||||
{
|
||||
return get_variable("SSH_PORT");
|
||||
}
|
||||
|
||||
std::vector<UserConfig> server_config::get_users() const
|
||||
std::vector<UserConfig> ServerConfig::get_users() const
|
||||
{
|
||||
return mUsers;
|
||||
}
|
||||
|
||||
std::string server_config::get_user_dir(const std::string &user) const
|
||||
std::string ServerConfig::get_user_dir(const std::string &user) const
|
||||
{
|
||||
for (const auto &u : mUsers)
|
||||
{
|
||||
@@ -137,12 +137,12 @@ namespace dropshell
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string server_config::get_server_name() const
|
||||
std::string ServerConfig::get_server_name() const
|
||||
{
|
||||
return mServerName;
|
||||
}
|
||||
|
||||
std::string server_config::get_user_for_service(const std::string &service) const
|
||||
std::string ServerConfig::get_user_for_service(const std::string &service) const
|
||||
{
|
||||
return dropshell::get_user_for_service(mServerName, service);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ namespace dropshell
|
||||
return "";
|
||||
}
|
||||
|
||||
sSSHInfo server_config::get_SSH_INFO(std::string user) const
|
||||
sSSHInfo ServerConfig::get_SSH_INFO(std::string user) const
|
||||
{
|
||||
ASSERT(!user.empty(), "User is empty, cannot get SSH info.");
|
||||
// Find user in mUsers vector
|
||||
@@ -169,24 +169,24 @@ namespace dropshell
|
||||
return sSSHInfo(get_SSH_HOST(), it->user, get_SSH_PORT(), get_server_name(), it->dir);
|
||||
}
|
||||
|
||||
bool server_config::hasRootUser() const
|
||||
bool ServerConfig::hasRootUser() const
|
||||
{
|
||||
auto it = std::find_if(mUsers.begin(), mUsers.end(),[](const UserConfig &u)
|
||||
{ return u.user == "root"; });
|
||||
return it != mUsers.end();
|
||||
}
|
||||
|
||||
bool server_config::hasDocker() const
|
||||
bool ServerConfig::hasDocker() const
|
||||
{
|
||||
return get_variable("HAS_DOCKER") == "true";
|
||||
}
|
||||
|
||||
bool server_config::hasRootDocker() const
|
||||
bool ServerConfig::hasRootDocker() const
|
||||
{
|
||||
return get_variable("DOCKER_ROOTLESS") == "false";
|
||||
}
|
||||
|
||||
bool server_config::hasUser(const std::string &user) const
|
||||
bool ServerConfig::hasUser(const std::string &user) const
|
||||
{
|
||||
auto it = std::find_if(mUsers.begin(), mUsers.end(),
|
||||
[&user](const UserConfig &u)
|
||||
@@ -194,19 +194,19 @@ namespace dropshell
|
||||
return it != mUsers.end();
|
||||
}
|
||||
|
||||
bool server_config::check_remote_dir_exists(const std::string &dir_path, std::string user) const
|
||||
bool ServerConfig::check_remote_dir_exists(const std::string &dir_path, std::string user) const
|
||||
{
|
||||
sCommand scommand("", "test -d " + quote(dir_path), {});
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
||||
}
|
||||
|
||||
bool server_config::check_remote_file_exists(const std::string &file_path, std::string user) const
|
||||
bool ServerConfig::check_remote_file_exists(const std::string &file_path, std::string user) const
|
||||
{
|
||||
sCommand scommand("", "test -f " + quote(file_path), {});
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
||||
}
|
||||
|
||||
bool server_config::check_remote_items_exist(const std::vector<std::string> &file_paths, std::string user) const
|
||||
bool ServerConfig::check_remote_items_exist(const std::vector<std::string> &file_paths, std::string user) const
|
||||
{
|
||||
// convert file_paths to a single string, separated by spaces
|
||||
std::string file_paths_str;
|
||||
@@ -229,7 +229,7 @@ namespace dropshell
|
||||
return true;
|
||||
}
|
||||
|
||||
bool server_config::remove_remote_dir(
|
||||
bool ServerConfig::remove_remote_dir(
|
||||
const std::string &dir_path, bool silent, std::string user) const
|
||||
{
|
||||
std::filesystem::path path(dir_path);
|
||||
@@ -258,7 +258,7 @@ namespace dropshell
|
||||
return execute_ssh_command(sshinfo, scommand, mode);
|
||||
}
|
||||
|
||||
bool server_config::run_remote_template_command(
|
||||
bool ServerConfig::run_remote_template_command(
|
||||
const std::string &service_name,
|
||||
const std::string &command,
|
||||
std::vector<std::string> args,
|
||||
@@ -280,7 +280,7 @@ namespace dropshell
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand.value(), mode);
|
||||
}
|
||||
|
||||
bool server_config::run_remote_template_command_and_capture_output(
|
||||
bool ServerConfig::run_remote_template_command_and_capture_output(
|
||||
const std::string &service_name,
|
||||
const std::string &command,
|
||||
std::vector<std::string> args,
|
||||
@@ -300,7 +300,7 @@ namespace dropshell
|
||||
return execute_ssh_command(get_SSH_INFO(user), scommand.value(), cMode::Defaults, &output);
|
||||
}
|
||||
|
||||
std::string server_config::get_variable(const std::string &name) const
|
||||
std::string ServerConfig::get_variable(const std::string &name) const
|
||||
{
|
||||
auto it = mVariables.find(name);
|
||||
if (it == mVariables.end())
|
||||
@@ -310,7 +310,7 @@ namespace dropshell
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::optional<sCommand> server_config::construct_standard_template_run_cmd(const std::string &service_name, const std::string &command, const std::vector<std::string> args, const bool silent) const
|
||||
std::optional<sCommand> ServerConfig::construct_standard_template_run_cmd(const std::string &service_name, const std::string &command, const std::vector<std::string> args, const bool silent) const
|
||||
{
|
||||
if (command.empty())
|
||||
return std::nullopt;
|
||||
@@ -346,9 +346,9 @@ namespace dropshell
|
||||
return sc;
|
||||
}
|
||||
|
||||
std::vector<server_config> get_configured_servers()
|
||||
std::vector<ServerConfig> get_configured_servers()
|
||||
{
|
||||
std::vector<server_config> servers;
|
||||
std::vector<ServerConfig> servers;
|
||||
|
||||
std::vector<std::string> lsdp = gConfig().get_local_server_definition_paths();
|
||||
if (lsdp.empty())
|
||||
@@ -367,7 +367,7 @@ namespace dropshell
|
||||
if (server_name.empty() || server_name[0] == '.' || server_name[0] == '_')
|
||||
continue;
|
||||
|
||||
server_config env(server_name);
|
||||
ServerConfig env(server_name);
|
||||
if (!env.is_valid())
|
||||
{
|
||||
std::cerr << "Error: Invalid server environment file: " << entry.path().string() << std::endl;
|
||||
@@ -430,7 +430,7 @@ namespace dropshell
|
||||
|
||||
void get_all_used_commands(std::set<std::string> &commands)
|
||||
{
|
||||
std::vector<server_config> servers = get_configured_servers();
|
||||
std::vector<ServerConfig> servers = get_configured_servers();
|
||||
for (const auto &server : servers)
|
||||
{
|
||||
auto services = get_server_services_info(server.get_server_name());
|
||||
|
Reference in New Issue
Block a user