.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-23 22:24:28 +12:00
parent 462d215d5c
commit b07704612b

View File

@ -44,7 +44,8 @@ namespace dropshell
nlohmann::json server_env_json = nlohmann::json::parse(std::ifstream(server_env_path)); nlohmann::json server_env_json = nlohmann::json::parse(std::ifstream(server_env_path));
if (server_env_json.empty()) if (server_env_json.empty())
{ {
std::cerr << "Error: Failed to parse server environment file: " + server_env_path << std::endl; error << "Failed to parse server environment file at "<< server_env_path << std::endl;
info << "The returned json was empty." << std::endl;
return; return;
} }
@ -69,10 +70,10 @@ namespace dropshell
if (mVariables.find(var) == mVariables.end()) if (mVariables.find(var) == mVariables.end())
{ {
// Print the variables identified in the file // Print the variables identified in the file
std::cout << "Variables identified in the file:" << std::endl; info << "Variables identified in the file:" << std::endl;
for (const auto &v : mVariables) for (const auto &v : mVariables)
{ {
std::cout << " " << v.first << std::endl; info << " " << v.first << std::endl;
} }
throw std::runtime_error("Missing required variable: " + std::string(var)); throw std::runtime_error("Missing required variable: " + std::string(var));
} }
@ -81,7 +82,7 @@ namespace dropshell
// Parse users array // Parse users array
if (!server_env_json.contains("USERS") || !server_env_json["USERS"].is_array()) if (!server_env_json.contains("USERS") || !server_env_json["USERS"].is_array())
{ {
std::cerr << "Error: USERS array not found or invalid in server configuration" << std::endl; error << "USERS array not found or invalid in server configuration" << std::endl;
return; return;
} }
@ -95,7 +96,7 @@ namespace dropshell
if (mUsers.empty()) if (mUsers.empty())
{ {
std::cerr << "Error: No users defined in server configuration" << std::endl; error << "No users defined in server configuration" << std::endl;
return; return;
} }
@ -103,7 +104,10 @@ namespace dropshell
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
std::cerr << "Failed to parse server environment file: " + std::string(e.what()) << std::endl; error << "Failed to parse " << server_env_path << std::endl;
error << "Error: " << e.what() << std::endl;
mValid = false;
} }
} }
@ -122,7 +126,7 @@ namespace dropshell
user_json["DIR"] = user.dir; user_json["DIR"] = user.dir;
users_array.push_back(user_json); users_array.push_back(user_json);
} }
server_env_json["USERS"] = users_array; server_env_json["SSH_USERS"] = users_array;
try try
{ {
@ -416,9 +420,13 @@ namespace dropshell
std::ofstream server_env_file(server_env_path); std::ofstream server_env_file(server_env_path);
server_env_file << "{" << std::endl; server_env_file << "{" << std::endl;
server_env_file << " \"SSH_HOST\": \"" << server_name << "\"," << std::endl; server_env_file << " \"SSH_HOST\": \"" << server_name << "\"," << std::endl;
server_env_file << " \"SSH_UNPRIVILEGED_USER\": \"" << user << "\"," << std::endl;
server_env_file << " \"SSH_PORT\": " << 22 << "," << std::endl; server_env_file << " \"SSH_PORT\": " << 22 << "," << std::endl;
server_env_file << " \"DROPSHELL_DIR\": \"" << "/home/" + user + "/.dropshell\"" << std::endl; server_env_file << " \"SSH_USERS\": [" << std::endl;
server_env_file << " {" << std::endl;
server_env_file << " \"USER\": \"" << user << "\"," << std::endl;
server_env_file << " \"DIR\": \"" << "/home/" + user << "/.dropshell\"" << std::endl;
server_env_file << " }" << std::endl;
server_env_file << " ]" << std::endl;
server_env_file << "}" << std::endl; server_env_file << "}" << std::endl;
server_env_file.close(); server_env_file.close();