forked from NationTech/harmony
feat: Harmony inventory agent crate that exposes an endpoint listing the host hardware. Has to be reviewed, generated 99% by GLM-4.5
This commit is contained in:
29
harmony_inventory_agent/src/main.rs
Normal file
29
harmony_inventory_agent/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// src/main.rs
|
||||
use actix_web::{App, HttpServer, Responder, get};
|
||||
use hwinfo::PhysicalHost;
|
||||
use std::env;
|
||||
|
||||
mod hwinfo;
|
||||
|
||||
#[get("/inventory")]
|
||||
async fn inventory() -> impl Responder {
|
||||
log::info!("Received inventory request");
|
||||
let host = PhysicalHost::gather();
|
||||
log::info!("Inventory data gathered successfully");
|
||||
actix_web::HttpResponse::Ok().json(host)
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
|
||||
let bind_addr = format!("0.0.0.0:{}", port);
|
||||
|
||||
log::info!("Starting inventory agent on {}", bind_addr);
|
||||
|
||||
HttpServer::new(|| App::new().service(inventory))
|
||||
.bind(&bind_addr)?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user