saluki_env/host/providers/
remote_agent.rs1use async_trait::async_trait;
2use memory_accounting::{MemoryBounds, MemoryBoundsBuilder};
3use saluki_config::GenericConfiguration;
4use saluki_error::GenericError;
5use tokio::sync::OnceCell;
6
7use crate::{helpers::remote_agent::RemoteAgentClient, HostProvider};
8
9#[derive(Clone)]
14pub struct RemoteAgentHostProvider {
15 client: RemoteAgentClient,
16 cached_hostname: OnceCell<String>,
17}
18
19impl RemoteAgentHostProvider {
20 pub async fn from_configuration(config: &GenericConfiguration) -> Result<Self, GenericError> {
27 let client = RemoteAgentClient::from_configuration(config).await?;
28
29 Ok(Self {
30 client,
31 cached_hostname: OnceCell::new(),
32 })
33 }
34
35 async fn get_or_fetch_hostname(&self) -> Result<String, GenericError> {
36 self.cached_hostname
37 .get_or_try_init(|| {
38 let mut client = self.client.clone();
39 async move { client.get_hostname().await }
40 })
41 .await
42 .cloned()
43 }
44}
45
46#[async_trait]
47impl HostProvider for RemoteAgentHostProvider {
48 type Error = GenericError;
49
50 async fn get_hostname(&self) -> Result<String, Self::Error> {
51 self.get_or_fetch_hostname().await
52 }
53}
54
55impl MemoryBounds for RemoteAgentHostProvider {
56 fn specify_bounds(&self, builder: &mut MemoryBoundsBuilder) {
57 builder.minimum().with_single_value::<Self>("component struct");
58 }
59}