mirror of
https://github.com/Portabase/agent.git
synced 2026-10-22 20:26:02 +00:00
fix: status.rs
This commit is contained in:
+10
-12
@@ -1,18 +1,18 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::core::context::Context;
|
||||
use crate::domain::factory::DatabaseFactory;
|
||||
use crate::services::api::endpoints::status::DatabasePayload;
|
||||
use crate::services::api::models::agent::status::PingResult;
|
||||
use crate::services::api::models::agent::status::DatabaseStorage;
|
||||
use crate::services::api::models::agent::status::PingResult;
|
||||
use crate::services::config::DatabaseConfig;
|
||||
use crate::settings::CONFIG;
|
||||
use crate::utils::file::decrypt_json_gcm;
|
||||
use futures_util::future::try_join_all;
|
||||
use reqwest::Client;
|
||||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
use futures_util::future::try_join_all;
|
||||
use tracing::info;
|
||||
use crate::domain::factory::DatabaseFactory;
|
||||
|
||||
pub struct StatusService {
|
||||
ctx: Arc<Context>,
|
||||
@@ -30,12 +30,12 @@ impl StatusService {
|
||||
pub async fn ping(&self, databases: &[DatabaseConfig]) -> Result<PingResult, Box<dyn Error>> {
|
||||
let edge_key = &self.ctx.edge_key;
|
||||
|
||||
let databases_payload: Vec<DatabasePayload> = try_join_all(
|
||||
databases.into_iter().map(|db| async move {
|
||||
let databases_payload: Vec<DatabasePayload> =
|
||||
try_join_all(databases.into_iter().map(|db| async move {
|
||||
let db_engine = DatabaseFactory::create_for_backup(db.clone()).await;
|
||||
|
||||
let reachable = db_engine.ping().await?;
|
||||
info!("Ping {} => {:?}",db.name, reachable);
|
||||
info!("Ping {} => {:?}", db.name, reachable);
|
||||
|
||||
Ok::<DatabasePayload, anyhow::Error>(DatabasePayload {
|
||||
name: &db.name,
|
||||
@@ -43,8 +43,8 @@ impl StatusService {
|
||||
generated_id: &db.generated_id,
|
||||
ping_status: reachable,
|
||||
})
|
||||
})
|
||||
).await?;
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let version_str = CONFIG.app_version.as_str();
|
||||
let mut result = self
|
||||
@@ -61,15 +61,13 @@ impl StatusService {
|
||||
.as_deref()
|
||||
.ok_or("storages_encrypted set but storages_ciphertext missing")?;
|
||||
|
||||
let plaintext =
|
||||
decrypt_json_gcm(ciphertext, &edge_key.master_key_b64)
|
||||
.map_err(|e| format!("Failed to decrypt storages: {e}"))?;
|
||||
let plaintext = decrypt_json_gcm(ciphertext, &edge_key.master_key_b64)
|
||||
.map_err(|e| format!("Failed to decrypt storages: {e}"))?;
|
||||
|
||||
db.storages = serde_json::from_slice::<Vec<DatabaseStorage>>(&plaintext)
|
||||
.map_err(|e| format!("Failed to parse decrypted storages: {e}"))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user