Files
NxMesh-old-2/apps/nxmesh-master/src/cli/gen_agent_certs.rs
GW_MC f5eb25993b feat: Implement SSH Agent Connector and gRPC server
- Added `AgentConnectorTrait` and `AgentConnector` for managing agent connections.
- Introduced `SshAgentConnector` to handle SSH-related functionalities and start a gRPC server.
- Created database entities for `agents`, `certificates`, `organizations`, `public_key_revocations`, `setup_tokens`, `upstreams`, `users`, `virtual_hosts`, and `workspaces` using SeaORM.
- Developed `CertificateService` for managing certificate generation and retrieval.
- Implemented the main server logic to initialize the database connection and start the agent server.
- Configured development settings in `development.toml` for server and database connections.
2026-03-21 03:09:39 +00:00

53 lines
1.5 KiB
Rust

use std::sync::Arc;
use tracing::{error, info};
use crate::{config::settings::Settings, db, service};
pub async fn gen_agent_certs(
settings: &Settings,
output: String,
agent_id: String,
zip: bool,
) -> Result<(), Box<dyn std::error::Error>> {
info!("Generating certificates to output directory: {}", output);
use service::certificate::CertificateService;
//
let cert_service = service::certificate::CertificateServiceImpl::new(
#[expect(clippy::expect_used)]
db::establish_connection(&settings.database.url)
.await
.expect("Failed to connect to database"),
output.clone(),
Arc::new(settings.clone()),
);
let output = cert_service
.generate_agent_certs(&agent_id, &output)
.await
.map_err(|e| {
error!("Failed to generate agent certificates: {}", e);
std::process::exit(1);
})
.unwrap();
info!(
"Successfully generated agent certificates at: cert path: {}, key path: {}, ca cert path: {}",
output.cert_path, output.key_path, output.ca_cert_path
);
if zip {
// Implementation for zipping certificates
info!("Zipping generated certificates...");
if let Err(e) = cert_service
.zip_certificates(&output.cert_path, &output.key_path, &output.ca_cert_path)
.await
{
error!("Failed to zip certificates: {}", e);
std::process::exit(1);
}
info!("Successfully zipped certificates.");
}
Ok(())
}