diff --git a/source/src/config.cpp b/source/src/config.cpp index 1019e05..ecca563 100644 --- a/source/src/config.cpp +++ b/source/src/config.cpp @@ -120,14 +120,14 @@ bool config::is_agent_installed() return std::filesystem::exists(localfile::bb64()); } -std::vector config::get_template_registry_urls() { - nlohmann::json template_registry_urls = mConfig["template_registry_URLs"]; - std::vector urls; - for (auto &url : template_registry_urls) { - if (url.is_string() && !url.empty()) - urls.push_back(url); +std::vector config::get_template_registry_urls() { + nlohmann::json template_registries = mConfig["template_registries"]; + std::vector registries; + for (auto ®istry : template_registries) { + if (registry.is_object() && !registry.empty()) + registries.push_back(tRegistryEntry(registry)); } - return urls; + return registries; } std::vector config::get_local_template_paths() @@ -167,22 +167,31 @@ std::string config::get_template_create_path() return paths[0]; } -std::string config::get_template_upload_url() -{ - std::vector urls = get_template_registry_urls(); - if (urls.empty()) - return ""; - return urls[0]; -} - -std::string config::get_template_upload_token() { - return mConfig["template_upload_token"]; -} - std::string config::get_backups_path() { return mConfig["backups_path"]; } +dropshell::tRegistryEntry::tRegistryEntry(nlohmann::json json) +{ + if (json.is_object() && !json.empty()) { + for (auto &[key, value] : json.items()) { + if (tolower(key) == "name") { + name = value; + } else if (tolower(key) == "url") { + url = value; + } else if (tolower(key) == "token") { + token = value; + } + } + valid = true; + } else { + valid = false; + } +} + +tRegistryEntry::~tRegistryEntry() +{ +} } // namespace dropshell \ No newline at end of file diff --git a/source/src/config.hpp b/source/src/config.hpp index dd2cfd0..2153581 100644 --- a/source/src/config.hpp +++ b/source/src/config.hpp @@ -8,6 +8,19 @@ namespace dropshell { +class tRegistryEntry { + + public: + tRegistryEntry(nlohmann::json json); + ~tRegistryEntry(); + + public: + std::string name; + std::string url; + std::string token; + bool valid; +}; + class config { public: config(); @@ -19,15 +32,12 @@ class config { bool is_config_set() const; static bool is_agent_installed(); - std::vector get_template_registry_urls(); + std::vector get_template_registry_urls(); std::vector get_local_template_paths(); std::vector get_local_server_definition_paths(); std::string get_server_create_path(); std::string get_template_create_path(); - std::string get_template_upload_url(); - std::string get_template_upload_token(); - std::string get_backups_path(); private: diff --git a/source/src/templates.hpp b/source/src/templates.hpp index 9509ec0..9f7af8e 100644 --- a/source/src/templates.hpp +++ b/source/src/templates.hpp @@ -4,6 +4,7 @@ #include #include +#include "config.hpp" #define JSON_INLINE_ALL #include "json.hpp" @@ -50,7 +51,7 @@ class template_source_interface { class template_source_registry : public template_source_interface { public: - template_source_registry(std::string URL) : mURL(URL) {} + template_source_registry(tRegistryEntry registry) : mRegistry(registry) {} ~template_source_registry() {} @@ -59,11 +60,11 @@ class template_source_registry : public template_source_interface { template_info get_template_info(const std::string& template_name); bool template_command_exists(const std::string& template_name,const std::string& command); - std::string get_description() { return "Registry: " + mURL; } + std::string get_description() { return "Registry: " + mRegistry.name + " (" + mRegistry.url + ")"; } private: std::filesystem::path get_cache_dir(); private: - std::string mURL; + tRegistryEntry mRegistry; std::vector mTemplates; // cached list. };