Replace template registry system with git-backed template sources
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 43s
Build-Test-Publish / build (linux/arm64) (push) Successful in 4m6s

This commit is contained in:
j
2026-03-23 09:14:33 +13:00
parent 208433c436
commit 5217ad42d3
15 changed files with 447 additions and 1457 deletions

View File

@@ -46,37 +46,26 @@ bool config::load_config() { // load json config file.
// Validate the config format - check for required and supported fields
std::set<std::string> allowed_fields = {
"server_definition_paths",
"template_local_paths",
"template_registries",
"backups_path",
"log_level",
"disabled_servers"
};
std::set<std::string> deprecated_fields = {
"template_registry_URLs",
"template_upload_token"
"template_upload_token",
"template_registries",
"template_local_paths"
};
// Check for deprecated fields
for (const auto& field : deprecated_fields) {
if (mConfig.contains(field)) {
error << "Config file contains deprecated field '" << field << "'" << std::endl;
error << "Please update your config file to the new format." << std::endl;
if (field == "template_registry_URLs") {
error << "Replace 'template_registry_URLs' with 'template_registries' using the format:" << std::endl;
error << " \"template_registries\": [" << std::endl;
error << " {" << std::endl;
error << " \"name\": \"main\"," << std::endl;
error << " \"url\": \"https://templates.dropshell.app\"," << std::endl;
error << " \"token\": \"\"" << std::endl;
error << " }" << std::endl;
error << " ]" << std::endl;
}
return false;
warning << "Config file contains deprecated field '" << field << "' - ignoring it." << std::endl;
mConfig.erase(field);
}
}
// Check for unknown fields
for (auto& [key, value] : mConfig.items()) {
if (allowed_fields.find(key) == allowed_fields.end()) {
@@ -92,25 +81,7 @@ bool config::load_config() { // load json config file.
return false;
}
}
// Validate template_registries format if present
if (mConfig.contains("template_registries")) {
if (!mConfig["template_registries"].is_array()) {
error << "'template_registries' must be an array" << std::endl;
return false;
}
for (const auto& registry : mConfig["template_registries"]) {
if (!registry.is_object()) {
error << "Each registry in 'template_registries' must be an object" << std::endl;
return false;
}
if (!registry.contains("name") || !registry.contains("url")) {
error << "Each registry must have 'name' and 'url' fields" << std::endl;
return false;
}
}
}
// Validate log_level if present
if (mConfig.contains("log_level")) {
if (!mConfig["log_level"].is_string()) {
@@ -131,15 +102,6 @@ bool config::load_config() { // load json config file.
return true;
}
void _append(std::vector<std::string> & a, const std::vector<std::string> & b) {
if (b.empty())
return;
if (a.empty())
a = b;
else
a.insert(std::end(a), std::begin(b), std::end(b));
}
bool config::save_config()
{
std::string config_path = localfile::dropshell_json();
@@ -160,19 +122,9 @@ bool config::save_config()
mConfig["server_definition_paths"] = {
dropshell_base + "/servers"
};
mConfig["template_local_paths"] = {
dropshell_base + "/local_templates"
};
mConfig["template_registries"] = nlohmann::json::array({
nlohmann::json::object({
{"name", "main"},
{"url", "https://templates.dropshell.app"},
{"token", ""}
})
});
mConfig["backups_path"] = dropshell_base + "/backups";
mConfig["log_level"] = "info"; // Default log level
}
}
config_file << mConfig.dump(4);
config_file.close();
@@ -181,15 +133,13 @@ bool config::save_config()
for (auto [key,value] : mConfig.items()) {
debug << " " << key << ": " << value << std::endl;
}
return true;
}
bool config::create_aux_directories()
{
std::vector<std::string> paths;
_append(paths, get_local_template_paths());
_append(paths, get_local_server_definition_paths());
std::vector<std::string> paths = get_local_server_definition_paths();
for (auto & p : paths)
if (!std::filesystem::exists(p))
{
@@ -200,7 +150,7 @@ bool config::create_aux_directories()
}
bool config::is_config_set() const
{
{
return mIsConfigSet;
}
@@ -209,27 +159,6 @@ bool config::is_agent_installed()
return std::filesystem::exists(localfile::bb64());
}
std::vector<tRegistryEntry> config::get_template_registry_urls() {
nlohmann::json template_registries = mConfig["template_registries"];
std::vector<tRegistryEntry> registries;
for (auto &registry : template_registries) {
if (registry.is_object() && !registry.empty())
registries.push_back(tRegistryEntry(registry));
}
return registries;
}
std::vector<std::string> config::get_local_template_paths()
{
nlohmann::json template_local_paths = mConfig["template_local_paths"];
std::vector<std::string> paths;
for (auto &path : template_local_paths) {
if (path.is_string() && !path.empty())
paths.push_back(path);
}
return paths;
}
std::vector<std::string> config::get_local_server_definition_paths() {
nlohmann::json server_definition_paths = mConfig["server_definition_paths"];
std::vector<std::string> paths;
@@ -248,14 +177,6 @@ std::string config::get_server_create_path()
return paths[0];
}
std::string config::get_template_create_path()
{
std::vector<std::string> paths = get_local_template_paths();
if (paths.empty())
return "";
return paths[0];
}
std::string config::get_backups_path()
{
nlohmann::json backups_path = mConfig["backups_path"];
@@ -267,39 +188,11 @@ std::string config::get_backups_path()
return "";
}
dropshell::tRegistryEntry::tRegistryEntry(nlohmann::json json)
{
valid = false;
if (json.is_object() && !json.empty()) {
for (auto &[key, value] : json.items()) {
if (value.is_string() && !value.empty())
switch (switchhash(key.c_str())) {
case switchhash("name"):
name = value;
break;
case switchhash("url"):
url = value;
break;
case switchhash("token"):
token = value;
break;
default:
break;
}
}
valid = (!url.empty()&&!name.empty()); // token can be empty.
}
}
tRegistryEntry::~tRegistryEntry()
{
}
std::string config::get_log_level() const
{
if (!mIsConfigSet || !mConfig.contains("log_level"))
return "info"; // Default log level
return mConfig["log_level"];
}
@@ -376,4 +269,4 @@ std::vector<std::string> config::get_disabled_servers() const
return result;
}
} // namespace dropshell
} // namespace dropshell