This commit is contained in:
parent
8f06fc31ae
commit
e7558be416
@ -120,14 +120,14 @@ bool config::is_agent_installed()
|
|||||||
return std::filesystem::exists(localfile::bb64());
|
return std::filesystem::exists(localfile::bb64());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> config::get_template_registry_urls() {
|
std::vector<tRegistryEntry> config::get_template_registry_urls() {
|
||||||
nlohmann::json template_registry_urls = mConfig["template_registry_URLs"];
|
nlohmann::json template_registries = mConfig["template_registries"];
|
||||||
std::vector<std::string> urls;
|
std::vector<tRegistryEntry> registries;
|
||||||
for (auto &url : template_registry_urls) {
|
for (auto ®istry : template_registries) {
|
||||||
if (url.is_string() && !url.empty())
|
if (registry.is_object() && !registry.empty())
|
||||||
urls.push_back(url);
|
registries.push_back(tRegistryEntry(registry));
|
||||||
}
|
}
|
||||||
return urls;
|
return registries;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> config::get_local_template_paths()
|
std::vector<std::string> config::get_local_template_paths()
|
||||||
@ -167,22 +167,31 @@ std::string config::get_template_create_path()
|
|||||||
return paths[0];
|
return paths[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string config::get_template_upload_url()
|
|
||||||
{
|
|
||||||
std::vector<std::string> 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()
|
std::string config::get_backups_path()
|
||||||
{
|
{
|
||||||
return mConfig["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
|
} // namespace dropshell
|
@ -8,6 +8,19 @@
|
|||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
|
class tRegistryEntry {
|
||||||
|
|
||||||
|
public:
|
||||||
|
tRegistryEntry(nlohmann::json json);
|
||||||
|
~tRegistryEntry();
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string name;
|
||||||
|
std::string url;
|
||||||
|
std::string token;
|
||||||
|
bool valid;
|
||||||
|
};
|
||||||
|
|
||||||
class config {
|
class config {
|
||||||
public:
|
public:
|
||||||
config();
|
config();
|
||||||
@ -19,15 +32,12 @@ class config {
|
|||||||
bool is_config_set() const;
|
bool is_config_set() const;
|
||||||
static bool is_agent_installed();
|
static bool is_agent_installed();
|
||||||
|
|
||||||
std::vector<std::string> get_template_registry_urls();
|
std::vector<tRegistryEntry> get_template_registry_urls();
|
||||||
std::vector<std::string> get_local_template_paths();
|
std::vector<std::string> get_local_template_paths();
|
||||||
std::vector<std::string> get_local_server_definition_paths();
|
std::vector<std::string> get_local_server_definition_paths();
|
||||||
|
|
||||||
std::string get_server_create_path();
|
std::string get_server_create_path();
|
||||||
std::string get_template_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();
|
std::string get_backups_path();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
#define JSON_INLINE_ALL
|
#define JSON_INLINE_ALL
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class template_source_interface {
|
|||||||
|
|
||||||
class template_source_registry : public template_source_interface {
|
class template_source_registry : public template_source_interface {
|
||||||
public:
|
public:
|
||||||
template_source_registry(std::string URL) : mURL(URL) {}
|
template_source_registry(tRegistryEntry registry) : mRegistry(registry) {}
|
||||||
|
|
||||||
~template_source_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);
|
template_info get_template_info(const std::string& template_name);
|
||||||
bool template_command_exists(const std::string& template_name,const std::string& command);
|
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:
|
private:
|
||||||
std::filesystem::path get_cache_dir();
|
std::filesystem::path get_cache_dir();
|
||||||
private:
|
private:
|
||||||
std::string mURL;
|
tRegistryEntry mRegistry;
|
||||||
std::vector<nlohmann::json> mTemplates; // cached list.
|
std::vector<nlohmann::json> mTemplates; // cached list.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user