diff options
| author | Dan Engelbrecht <[email protected]> | 2026-04-01 13:48:19 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-04-01 13:48:19 +0200 |
| commit | af208b5612ca9945242b40be4f65e76e0a32e8fa (patch) | |
| tree | 3c9629ed3506ebb5496e41db9d915837ab3db6c7 /src/zenutil/consul/consul.cpp | |
| parent | kill stale test processes (zenserver, minio, nomad, consul) before and after ... (diff) | |
| download | zen-af208b5612ca9945242b40be4f65e76e0a32e8fa.tar.xz zen-af208b5612ca9945242b40be4f65e76e0a32e8fa.zip | |
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
Diffstat (limited to 'src/zenutil/consul/consul.cpp')
| -rw-r--r-- | src/zenutil/consul/consul.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
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); } } |