// server_env.hpp // // read the server.env file and provide a class to access the variables #ifndef __SERVER_ENV_HPP #define __SERVER_ENV_HPP #include #include #include #include #include "utils/execute.hpp" #include namespace dropshell { class server_env_manager; // ------------------------------------------------------------------------------------------------ // reads path / server.env and provides a class to access the variables. // each env file is required to have the following variables: // SSH_HOST // SSH_USER // SSH_PORT // the following replacements are made in the values: // ${USER} -> the username of the user running dropshell class server_env_manager { public: server_env_manager(const std::string& server_name); static bool create_server_env( const std::string& server_env_path, const std::string& SSH_HOST, const std::string& SSH_USER, const std::string& SSH_PORT, const std::string& DROPSHELL_DIR); std::string get_variable(const std::string& name) const; // trivial getters. const std::map& get_variables() const { return mVariables; } std::string get_SSH_HOST() const { return get_variable("SSH_HOST"); } std::string get_SSH_USER() const { return get_variable("SSH_USER"); } std::string get_SSH_PORT() const { return get_variable("SSH_PORT"); } std::string get_DROPSHELL_DIR() const { return get_variable("DROPSHELL_DIR"); } sSSHInfo get_SSH_INFO() const { return sSSHInfo{get_SSH_HOST(), get_SSH_USER(), get_SSH_PORT(), get_server_name()}; } bool is_valid() const { return mValid; } std::string get_server_name() const { return mServerName; } // helper functions public: bool check_remote_dir_exists(const std::string &dir_path) const; bool check_remote_file_exists(const std::string& file_path) const; bool check_remote_items_exist(const std::vector& file_paths) const; bool remove_remote_dir(const std::string &dir_path, bool silent) const; bool run_remote_template_command(const std::string& service_name, const std::string& command, std::vector args, bool silent, std::map extra_env_vars) const; bool run_remote_template_command_and_capture_output(const std::string& service_name, const std::string& command, std::vector args, std::string & output, bool silent, std::map extra_env_vars) const; private: std::optional construct_standard_template_run_cmd(const std::string& service_name, const std::string& command, const std::vector args, const bool silent) const; private: std::string mServerName; std::map mVariables; bool mValid; }; } // namespace dropshell #endif // __SERVER_ENV_HPP