From 729a20707a19bc45628d4a1afc0315f66394a3ab Mon Sep 17 00:00:00 2001 From: j Date: Sun, 12 Oct 2025 11:51:32 +1300 Subject: [PATCH] feat: Update 3 files --- source/src/commands/install.cpp | 3 ++- source/src/utils/env_validator.cpp | 21 ++++++++++++++++++--- source/src/utils/env_validator.hpp | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index 26a8fbb..7ce9e0a 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -154,12 +154,13 @@ namespace dropshell // Validate service.env matches template 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::vector missing_vars; std::vector 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; diff --git a/source/src/utils/env_validator.cpp b/source/src/utils/env_validator.cpp index 1c98337..1f579ca 100644 --- a/source/src/utils/env_validator.cpp +++ b/source/src/utils/env_validator.cpp @@ -16,7 +16,8 @@ bool validate_and_fix_service_env( const std::string& template_service_env_path, const std::string& service_env_path, std::vector& missing_vars, - std::vector& extra_vars + std::vector& extra_vars, + const std::string& template_info_env_path ) { missing_vars.clear(); extra_vars.clear(); @@ -37,6 +38,19 @@ bool validate_and_fix_service_env( template_var_names.insert(key); } + // Also load template_info.env if provided - these variables are allowed in service.env + std::set 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 envmanager service_env(service_env_path); 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) { - 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); } } diff --git a/source/src/utils/env_validator.hpp b/source/src/utils/env_validator.hpp index 478812e..833adb1 100644 --- a/source/src/utils/env_validator.hpp +++ b/source/src/utils/env_validator.hpp @@ -15,11 +15,13 @@ namespace dropshell { // 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 // 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( const std::string& template_service_env_path, const std::string& service_env_path, std::vector& missing_vars, - std::vector& extra_vars + std::vector& extra_vars, + const std::string& template_info_env_path = "" ); } // namespace dropshell