Update secrets and email types
All checks were successful
BotServer CI/CD / build (push) Successful in 10m52s
All checks were successful
BotServer CI/CD / build (push) Successful in 10m52s
- Refactor secrets module structure - Remove unused type in email types - Improve error handling in secrets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0ac8178baa
commit
3502c61faf
2 changed files with 18 additions and 14 deletions
|
|
@ -7,7 +7,6 @@ use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Arc as StdArc;
|
use std::sync::Arc as StdArc;
|
||||||
use tokio::sync::RwLock;
|
|
||||||
use std::sync::RwLock as StdRwLock;
|
use std::sync::RwLock as StdRwLock;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use vaultrs::client::{VaultClient, VaultClientSettingsBuilder};
|
use vaultrs::client::{VaultClient, VaultClientSettingsBuilder};
|
||||||
|
|
@ -147,7 +146,7 @@ impl SecretsManager {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
client: Some(StdArc::new(client)),
|
client: Some(StdArc::new(client)),
|
||||||
cache: Arc::new(RwLock::new(HashMap::new())),
|
cache: Arc::new(StdRwLock::new(HashMap::new())),
|
||||||
cache_ttl,
|
cache_ttl,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
|
|
@ -599,18 +598,21 @@ impl SecretsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn clear_cache(&self) {
|
pub async fn clear_cache(&self) {
|
||||||
self.cache.write().await.clear();
|
if let Ok(mut cache) = self.cache.write() {
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cached(&self, path: &str) -> Option<HashMap<String, String>> {
|
async fn get_cached(&self, path: &str) -> Option<HashMap<String, String>> {
|
||||||
let cache = self.cache.read().await;
|
let cache = self.cache.read().ok()?;
|
||||||
cache
|
cache
|
||||||
.get(path)
|
.get(path)
|
||||||
.and_then(|c| (c.expires_at > std::time::Instant::now()).then(|| c.data.clone()))
|
.and_then(|c| (c.expires_at > std::time::Instant::now()).then(|| c.data.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cache_secret(&self, path: &str, data: HashMap<String, String>) {
|
async fn cache_secret(&self, path: &str, data: HashMap<String, String>) {
|
||||||
self.cache.write().await.insert(
|
if let Ok(mut cache) = self.cache.write() {
|
||||||
|
cache.insert(
|
||||||
path.to_string(),
|
path.to_string(),
|
||||||
CachedSecret {
|
CachedSecret {
|
||||||
data,
|
data,
|
||||||
|
|
@ -619,9 +621,12 @@ impl SecretsManager {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn invalidate_cache(&self, path: &str) {
|
async fn invalidate_cache(&self, path: &str) {
|
||||||
self.cache.write().await.remove(path);
|
if let Ok(mut cache) = self.cache.write() {
|
||||||
|
cache.remove(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_from_env(path: &str) -> Result<HashMap<String, String>> {
|
fn get_from_env(path: &str) -> Result<HashMap<String, String>> {
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,6 @@ impl EmailService {
|
||||||
file_data: Vec<u8>,
|
file_data: Vec<u8>,
|
||||||
filename: &str,
|
filename: &str,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
use lettre::message::header::ContentType;
|
|
||||||
use lettre::message::{Attachment, Body, Message, MultiPart, SinglePart};
|
use lettre::message::{Attachment, Body, Message, MultiPart, SinglePart};
|
||||||
use lettre::transport::smtp::authentication::Credentials;
|
use lettre::transport::smtp::authentication::Credentials;
|
||||||
use lettre::{SmtpTransport, Transport};
|
use lettre::{SmtpTransport, Transport};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue