Add overrides.env support for per-location service env overrides
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 48s
Build-Test-Publish / build (linux/arm64) (push) Successful in 3m44s

This commit is contained in:
j
2026-03-30 08:04:23 +13:00
parent bf9cdeccc7
commit 735e2f083a
7 changed files with 169 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
#include "service_env_overrides.hpp"
#include "directories.hpp"
#include "envmanager.hpp"
#include "service_env_validator.hpp"
#include <filesystem>
namespace dropshell {
std::vector<OverrideChange> apply_overrides(
const std::string& server_name,
const std::string& service_name)
{
std::vector<OverrideChange> changes;
std::string overrides_path = localfile::overrides_env_for_server(server_name);
if (overrides_path.empty() || !std::filesystem::exists(overrides_path))
return changes;
std::string service_env_path = localfile::service_env(server_name, service_name);
if (service_env_path.empty() || !std::filesystem::exists(service_env_path))
return changes;
// Load overrides
envmanager overrides(overrides_path);
if (!overrides.load())
return changes;
ordered_env_vars override_vars;
overrides.get_all_variables(override_vars);
if (override_vars.empty())
return changes;
// Load current service env
envmanager service_env(service_env_path);
if (!service_env.load())
return changes;
// Apply each override
for (const auto& [key, new_val] : override_vars) {
std::string current_val = service_env.get_variable(key);
if (current_val != new_val) {
set_env_variable(service_env_path, key, new_val);
changes.push_back({key, current_val, new_val});
}
}
return changes;
}
} // namespace dropshell