Update remote agent scripts and add override validation
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 25s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m5s

This commit is contained in:
j
2026-03-30 10:50:51 +13:00
parent 735e2f083a
commit 284183fdf1
3 changed files with 718 additions and 403 deletions

View File

@@ -0,0 +1 @@
36f6a765ce8cbd6264e650e1535004866ef9131f826a85ee425f42ca01fe673e

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,12 @@
#include "directories.hpp"
#include "envmanager.hpp"
#include "service_env_validator.hpp"
#include "services.hpp"
#include "templates.hpp"
#include "output.hpp"
#include <filesystem>
#include <set>
namespace dropshell {
@@ -31,13 +35,47 @@ std::vector<OverrideChange> apply_overrides(
if (override_vars.empty())
return changes;
// Build set of allowed variable names from template service.env and template_info.env
std::set<std::string> allowed_vars;
LocalServiceInfo service_info = get_service_info(server_name, service_name);
if (!service_info.template_name.empty()) {
template_info tinfo = gTemplateManager().get_template_info(service_info.template_name);
if (tinfo.is_set()) {
std::filesystem::path template_service_env = tinfo.local_template_service_env_path();
if (std::filesystem::exists(template_service_env)) {
envmanager tmpl_env(template_service_env.string());
if (tmpl_env.load()) {
ordered_env_vars tmpl_vars;
tmpl_env.get_all_variables(tmpl_vars);
for (const auto& [key, value] : tmpl_vars)
allowed_vars.insert(key);
}
}
std::filesystem::path template_info_env = tinfo.local_template_info_env_path();
if (std::filesystem::exists(template_info_env)) {
envmanager info_env(template_info_env.string());
if (info_env.load()) {
ordered_env_vars info_vars;
info_env.get_all_variables(info_vars);
for (const auto& [key, value] : info_vars)
allowed_vars.insert(key);
}
}
}
}
// Load current service env
envmanager service_env(service_env_path);
if (!service_env.load())
return changes;
// Apply each override
// Apply each override, skipping variables not defined in the template
for (const auto& [key, new_val] : override_vars) {
if (!allowed_vars.empty() && allowed_vars.find(key) == allowed_vars.end()) {
warning << "Override skipped: " << key << " is not defined in the template for " << service_name << std::endl;
continue;
}
std::string current_val = service_env.get_variable(key);
if (current_val != new_val) {
set_env_variable(service_env_path, key, new_val);