Skip to main content

agent_api/
client.rs

1use crate::agent::agent_client::AgentClient;
2use anyhow::Error;
3use std::result::Result::Ok;
4use tonic::transport::Channel;
5use tonic_reflection::pb::v1::server_reflection_client::ServerReflectionClient;
6
7const AGENT_IP: &str = "http://127.0.0.1:9090";
8
9#[cfg(feature = "client")]
10pub async fn connect_to_client() -> Result<AgentClient<Channel>, Error> {
11    //this methods force a HTTP/2 connection from a static string
12    //FIXME: this will require an update to ensure a protected connection
13    let channel = Channel::from_static(AGENT_IP).connect().await?;
14    let client = AgentClient::new(channel);
15    Ok(client)
16}
17#[cfg(feature = "client")]
18pub async fn connect_to_server_reflection() -> Result<ServerReflectionClient<Channel>, Error> {
19    //this methods force a HTTP/2 connection from a static string
20    let channel = Channel::from_static(AGENT_IP).connect().await?;
21    let client = ServerReflectionClient::new(channel);
22    Ok(client)
23}