manta_shared/common/
check_network_connectivity.rs

1//! Tiny TCP-reachability probe for backend API endpoints.
2//!
3//! Used at startup to fail fast with a clear error when the
4//! configured `shasta_base_url` isn't reachable, rather than
5//! deferring the failure until the first real request.
6
7use std::time::Duration;
8
9use manta_backend_dispatcher::error::Error;
10
11/// Timeout in seconds for the backend connectivity check.
12const BACKEND_CONNECT_TIMEOUT_SECS: u64 = 3;
13
14/// Verify that the backend API endpoint is reachable
15/// (3-second connect timeout).
16pub async fn check_network_connectivity_to_backend(
17  shasta_base_url: &str,
18) -> Result<(), Error> {
19  let client = reqwest::Client::builder()
20    .connect_timeout(Duration::from_secs(BACKEND_CONNECT_TIMEOUT_SECS))
21    .build()?;
22
23  tracing::info!("Validate CSM token against {}", shasta_base_url);
24
25  client
26    .get(shasta_base_url)
27    .send()
28    .await?
29    .error_for_status()
30    .map(|_| ())?;
31
32  Ok(())
33}