Skip to main content

max / mnw-cli

1004 B · 44 lines History Blame Raw
1 //! SSH server implementation using russh.
2
3 pub mod git;
4 pub mod handler;
5 pub mod sftp;
6 pub mod terminal;
7
8 use std::net::SocketAddr;
9 use std::path::PathBuf;
10 use std::sync::Arc;
11
12 use crate::api::MnwApiClient;
13
14 /// SSH server that spawns a new handler per connection.
15 pub struct MnwServer {
16 api: MnwApiClient,
17 staging_dir: Arc<PathBuf>,
18 git_user: Arc<str>,
19 }
20
21 impl MnwServer {
22 pub fn new(api: MnwApiClient, staging_dir: Arc<PathBuf>, git_user: String) -> Self {
23 Self {
24 api,
25 staging_dir,
26 git_user: Arc::from(git_user),
27 }
28 }
29 }
30
31 impl russh::server::Server for MnwServer {
32 type Handler = handler::MnwHandler;
33
34 fn new_client(&mut self, peer_addr: Option<SocketAddr>) -> Self::Handler {
35 tracing::info!(?peer_addr, "new SSH connection");
36 handler::MnwHandler::new(
37 self.api.clone(),
38 peer_addr,
39 Arc::clone(&self.staging_dir),
40 Arc::clone(&self.git_user),
41 )
42 }
43 }
44