feat: Update 3 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 50s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m18s

This commit is contained in:
2025-10-12 11:51:32 +13:00
parent e9a6998761
commit 729a20707a
3 changed files with 23 additions and 5 deletions

View File

@@ -154,12 +154,13 @@ namespace dropshell
// Validate service.env matches template service.env // Validate service.env matches template service.env
{ {
std::filesystem::path template_service_env = tinfo.local_template_path() / "config" / "service.env"; std::filesystem::path template_service_env = tinfo.local_template_path() / "config" / "service.env";
std::filesystem::path template_info_env = tinfo.local_template_path() / "config" / ".template_info.env";
std::string service_env_file = localfile::service_env(server, service); std::string service_env_file = localfile::service_env(server, service);
std::vector<std::string> missing_vars; std::vector<std::string> missing_vars;
std::vector<std::string> extra_vars; std::vector<std::string> extra_vars;
if (!validate_and_fix_service_env(template_service_env.string(), service_env_file, missing_vars, extra_vars)) if (!validate_and_fix_service_env(template_service_env.string(), service_env_file, missing_vars, extra_vars, template_info_env.string()))
{ {
error << "Service environment file validation failed for " << service << std::endl; error << "Service environment file validation failed for " << service << std::endl;

View File

@@ -16,7 +16,8 @@ bool validate_and_fix_service_env(
const std::string& template_service_env_path, const std::string& template_service_env_path,
const std::string& service_env_path, const std::string& service_env_path,
std::vector<std::string>& missing_vars, std::vector<std::string>& missing_vars,
std::vector<std::string>& extra_vars std::vector<std::string>& extra_vars,
const std::string& template_info_env_path
) { ) {
missing_vars.clear(); missing_vars.clear();
extra_vars.clear(); extra_vars.clear();
@@ -37,6 +38,19 @@ bool validate_and_fix_service_env(
template_var_names.insert(key); template_var_names.insert(key);
} }
// Also load template_info.env if provided - these variables are allowed in service.env
std::set<std::string> template_info_var_names;
if (!template_info_env_path.empty() && std::filesystem::exists(template_info_env_path)) {
envmanager template_info_env(template_info_env_path);
if (template_info_env.load()) {
ordered_env_vars template_info_vars;
template_info_env.get_all_variables(template_info_vars);
for (const auto& [key, value] : template_info_vars) {
template_info_var_names.insert(key);
}
}
}
// Load service service.env // Load service service.env
envmanager service_env(service_env_path); envmanager service_env(service_env_path);
if (!service_env.load()) { if (!service_env.load()) {
@@ -60,9 +74,10 @@ bool validate_and_fix_service_env(
} }
} }
// Find extra variables (in service but not in template) // Find extra variables (in service but not in template or template_info)
for (const auto& service_var_name : service_var_names) { for (const auto& service_var_name : service_var_names) {
if (template_var_names.find(service_var_name) == template_var_names.end()) { if (template_var_names.find(service_var_name) == template_var_names.end() &&
template_info_var_names.find(service_var_name) == template_info_var_names.end()) {
extra_vars.push_back(service_var_name); extra_vars.push_back(service_var_name);
} }
} }

View File

@@ -15,11 +15,13 @@ namespace dropshell {
// service_env_path: Full path to the service's service.env file // service_env_path: Full path to the service's service.env file
// missing_vars: Output parameter - list of variable names that were missing and added // missing_vars: Output parameter - list of variable names that were missing and added
// extra_vars: Output parameter - list of variable names that were extra and commented out // extra_vars: Output parameter - list of variable names that were extra and commented out
// template_info_env_path: Optional path to .template_info.env - variables from this file are allowed in service.env
bool validate_and_fix_service_env( bool validate_and_fix_service_env(
const std::string& template_service_env_path, const std::string& template_service_env_path,
const std::string& service_env_path, const std::string& service_env_path,
std::vector<std::string>& missing_vars, std::vector<std::string>& missing_vars,
std::vector<std::string>& extra_vars std::vector<std::string>& extra_vars,
const std::string& template_info_env_path = ""
); );
} // namespace dropshell } // namespace dropshell