Skip to main content

salix_agent/
lib.rs

1//! Salix agent
2
3use std::path::PathBuf;
4
5use anyhow::Result;
6use clap::Parser;
7use gethostname::gethostname;
8use salix_config::get_config;
9use salix_proto::{RegistrationRequest, controller_service_client::ControllerServiceClient};
10use uuid::Uuid;
11
12/// CLI arguments
13#[derive(Parser)]
14#[command(version, about, long_about = None)]
15pub struct Cli {
16    #[arg(short, long, value_name = "FILE")]
17    config: Option<PathBuf>,
18}
19
20/// Main function
21#[tokio::main]
22pub async fn run(cli: Cli) -> Result<()> {
23    let config = get_config(cli.config)?;
24
25    let agent_id = Uuid::now_v7();
26
27    let mut controller_client =
28        ControllerServiceClient::connect(config.agent.controller_address).await?;
29
30    let request = tonic::Request::new(RegistrationRequest {
31        agent_id: agent_id.to_string().into(),
32        hostname: gethostname().into_string().unwrap_or_default().into(),
33        version: env!("CARGO_PKG_VERSION").to_owned().into(),
34        timestamp: 0.into(),
35    });
36    let response = controller_client.register(request).await?;
37
38    println!("{:?}", &response);
39
40    Ok(())
41}