Major refactor
This commit is contained in:
@@ -14,7 +14,6 @@ namespace fs = std::filesystem;
|
||||
namespace dropshell
|
||||
{
|
||||
|
||||
#pragma message("TODO : Smart test that the service is fully valid.")
|
||||
bool SIvalid(const LocalServiceInfo &service_info)
|
||||
{
|
||||
return !service_info.service_name.empty() &&
|
||||
@@ -24,7 +23,7 @@ namespace dropshell
|
||||
!service_info.user.empty();
|
||||
}
|
||||
|
||||
std::vector<LocalServiceInfo> get_server_services_info(const std::string &server_name, bool fast)
|
||||
std::vector<LocalServiceInfo> get_server_services_info(const std::string &server_name, bool skip_update)
|
||||
{
|
||||
std::vector<LocalServiceInfo> services;
|
||||
|
||||
@@ -50,7 +49,7 @@ namespace dropshell
|
||||
std::string dirname = entry.path().filename().string();
|
||||
if (dirname.empty() || dirname[0] == '.' || dirname[0] == '_')
|
||||
continue;
|
||||
auto service = get_service_info(server_name, dirname, fast);
|
||||
auto service = get_service_info(server_name, dirname, skip_update);
|
||||
if (!service.local_service_path.empty())
|
||||
services.push_back(service);
|
||||
else
|
||||
@@ -73,7 +72,7 @@ namespace dropshell
|
||||
return it->second == "true";
|
||||
}
|
||||
|
||||
LocalServiceInfo get_service_info(const std::string &server_name, const std::string &service_name, bool fast)
|
||||
LocalServiceInfo get_service_info(const std::string &server_name, const std::string &service_name, bool skip_update)
|
||||
{
|
||||
LocalServiceInfo service;
|
||||
|
||||
@@ -111,7 +110,7 @@ namespace dropshell
|
||||
service.template_name = it->second;
|
||||
}
|
||||
|
||||
template_info tinfo = gTemplateManager().get_template_info(service.template_name,fast);
|
||||
template_info tinfo = gTemplateManager().get_template_info(service.template_name,skip_update);
|
||||
if (!tinfo.is_set())
|
||||
{
|
||||
// Template not found - this means it's not available locally OR from registry
|
||||
@@ -137,30 +136,6 @@ namespace dropshell
|
||||
service.requires_docker = get_bool_variable(variables, "REQUIRES_DOCKER");
|
||||
service.requires_docker_root = get_bool_variable(variables, "REQUIRES_DOCKER_ROOT");
|
||||
|
||||
{ // determine if the service template hash matches the template hash.
|
||||
auto it = find_var(variables, "TEMPLATE_HASH");
|
||||
service.service_template_hash_match = false;
|
||||
|
||||
if (it == variables.end())
|
||||
{
|
||||
// For backward compatibility with services created before hash mechanism
|
||||
debug << "TEMPLATE_HASH not found in " << filenames::template_info_env << " for " << server_name << " - " << service.template_name
|
||||
<< " (service may have been created before hash tracking was implemented)" << std::endl;
|
||||
}
|
||||
else if (tinfo.is_set())
|
||||
{
|
||||
std::string template_hash_str = it->second;
|
||||
// Compare hash strings directly (migration from uint64_t to SHA256 string)
|
||||
service.service_template_hash_match = (template_hash_str == tinfo.hash());
|
||||
//debug << "Service template hash: " << service_template_hash << " == " << tinfo.hash() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Template not available yet, can't check hash
|
||||
debug << "Couldn't check template hash as the template info is not available (yet?)" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
@@ -254,7 +229,22 @@ namespace dropshell
|
||||
|
||||
// Load environment files
|
||||
load_env_file(localfile::service_env(server_name, service_name));
|
||||
load_env_file(localfile::template_info_env(server_name, service_name));
|
||||
|
||||
std::string template_name = get_var(all_env_vars, "TEMPLATE");
|
||||
if (template_name.empty())
|
||||
{
|
||||
error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
auto tinfo = gTemplateManager().get_template_info(template_name, true); // skip updates.
|
||||
if (!tinfo.is_set())
|
||||
{
|
||||
// Template is not available locally or from registry
|
||||
error << "Template '" << template_name << "' not found locally or in registry" << std::endl;
|
||||
return false;
|
||||
}
|
||||
ASSERT(std::filesystem::exists(tinfo.local_template_info_env_path()));
|
||||
load_env_file(tinfo.local_template_info_env_path());
|
||||
|
||||
std::string user = get_var(all_env_vars, "SSH_USER");
|
||||
if (user.empty())
|
||||
@@ -269,27 +259,6 @@ namespace dropshell
|
||||
set_var(all_env_vars, "CONFIG_PATH", remotepath(server_name, user).service_config(service_name));
|
||||
set_var(all_env_vars, "AGENT_PATH", remotepath(server_name, user).agent());
|
||||
|
||||
|
||||
// determine template name.
|
||||
auto it = find_var(all_env_vars, "TEMPLATE");
|
||||
if (it == all_env_vars.end())
|
||||
{
|
||||
error << "TEMPLATE variable not defined in service " << service_name << " on server " << server_name << std::endl;
|
||||
info << "The TEMPLATE variable is required to determine the template name." << std::endl;
|
||||
info << "Please check the " << filenames::service_env << " file and the "<< filenames::template_info_env << " file in:" << std::endl;
|
||||
info << " " << localpath::service(server_name, service_name) << std::endl
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
// Try to get the template - this will download from registry if needed
|
||||
template_info tinfo = gTemplateManager().get_template_info(it->second);
|
||||
if (!tinfo.is_set())
|
||||
{
|
||||
// Template is not available locally or from registry
|
||||
error << "Template '" << it->second << "' not found locally or in registry" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user