From af208b5612ca9945242b40be4f65e76e0a32e8fa Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 1 Apr 2026 13:48:19 +0200 Subject: consul env token refresh (#912) - Improvement: Consul token is now re-read from the environment variable on every request, allowing token rotation without restarting the service --- src/zenutil/consul/consul.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/zenutil/consul/consul.cpp') diff --git a/src/zenutil/consul/consul.cpp b/src/zenutil/consul/consul.cpp index c9144e589..ad1b92b38 100644 --- a/src/zenutil/consul/consul.cpp +++ b/src/zenutil/consul/consul.cpp @@ -107,7 +107,7 @@ ConsulProcess::StopConsulAgent() ////////////////////////////////////////////////////////////////////////// -ConsulClient::ConsulClient(std::string_view BaseUri, std::string_view Token) : m_Token(Token), m_HttpClient(BaseUri) +ConsulClient::ConsulClient(const Configuration& Config) : m_Config(Config), m_HttpClient(m_Config.BaseUri) { } @@ -241,9 +241,19 @@ ConsulClient::DeregisterService(std::string_view ServiceId) void ConsulClient::ApplyCommonHeaders(HttpClient::KeyValueMap& InOutHeaderMap) { - if (!m_Token.empty()) + std::string Token; + if (!m_Config.StaticToken.empty()) { - InOutHeaderMap.Entries.emplace("X-Consul-Token", m_Token); + Token = m_Config.StaticToken; + } + else if (!m_Config.TokenEnvName.empty()) + { + Token = GetEnvVariable(m_Config.TokenEnvName); + } + + if (!Token.empty()) + { + InOutHeaderMap.Entries.emplace("X-Consul-Token", Token); } } -- cgit v1.2.3