fix: use CachedSecret struct instead of tuples in sync methods
Some checks failed
BotServer CI/CD / build (push) Failing after 2s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-05 01:07:42 -03:00
parent 9383cf0e3a
commit 60dc273681
2 changed files with 8 additions and 3 deletions

View file

@ -232,6 +232,8 @@ rust-embed = { workspace = true, optional = true }
mockito = { workspace = true } mockito = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }
bigdecimal = { workspace = true } bigdecimal = { workspace = true }
[dependencies]
ureq = { version = "2", features = ["json"] } ureq = { version = "2", features = ["json"] }
[dev-dependencies] [dev-dependencies]

View file

@ -929,8 +929,8 @@ impl SecretsManager {
fn get_cached_sync(&self, path: &str) -> Option<HashMap<String, String>> { fn get_cached_sync(&self, path: &str) -> Option<HashMap<String, String>> {
let cache = self.cache.read().ok()?; let cache = self.cache.read().ok()?;
let entry = cache.get(path)?; let entry = cache.get(path)?;
if entry.1.elapsed() < std::time::Duration::from_secs(self.cache_ttl) { if entry.expires_at.elapsed() < std::time::Duration::from_secs(self.cache_ttl) {
Some(entry.0.clone()) Some(entry.data.clone())
} else { } else {
None None
} }
@ -939,7 +939,10 @@ impl SecretsManager {
fn cache_secret_sync(&self, path: &str, data: HashMap<String, String>) { fn cache_secret_sync(&self, path: &str, data: HashMap<String, String>) {
if self.cache_ttl > 0 { if self.cache_ttl > 0 {
if let Ok(mut cache) = self.cache.write() { if let Ok(mut cache) = self.cache.write() {
cache.insert(path.to_string(), (data, std::time::Instant::now())); cache.insert(path.to_string(), CachedSecret {
data,
expires_at: std::time::Instant::now(),
});
} }
} }
} }