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.
This commit is contained in:
40
apps/nxmesh-master/src/service/mod.rs
Normal file
40
apps/nxmesh-master/src/service/mod.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{connector::agent::AgentConnectorTrait, service::certificate::CertificateService};
|
||||
|
||||
pub mod agent;
|
||||
pub mod certificate;
|
||||
|
||||
pub async fn start_master_server(
|
||||
settings: crate::config::settings::Settings,
|
||||
cli: crate::cli::Cli,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
// Initialize database connection
|
||||
let db_connection = crate::db::establish_connection(&settings.database.url).await?;
|
||||
|
||||
// Initialize certificate service with default cert folder path
|
||||
let cert_service = Arc::new(crate::service::certificate::CertificateServiceImpl::new(
|
||||
db_connection.clone(),
|
||||
settings.grpc.certificate.cert_dir.clone(),
|
||||
Arc::new(settings.clone()),
|
||||
));
|
||||
|
||||
// if generate_ca is set, generate a new certificate and exit
|
||||
if cli.generate_ca {
|
||||
// TODO: check the error type and return a more specific error message
|
||||
cert_service.generate_ca_cert().await.ok();
|
||||
println!("Certificate generated and stored successfully.");
|
||||
}
|
||||
|
||||
// Initialize agent connector
|
||||
let mut agent_connector = crate::connector::agent::AgentConnector::new(Box::new(
|
||||
crate::connector::agent::ssh::SshAgentConnector::new(settings.clone())?,
|
||||
));
|
||||
|
||||
// Start the agent server
|
||||
agent_connector
|
||||
.start_server(&settings, cert_service, db_connection)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user