Skip to main content

max / makenotwork

1.2 KB · 53 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 use crate::rate_limit::AuthRateLimiter;
14
15 /// SSH server that spawns a new handler per connection.
16 pub struct MnwServer {
17 api: MnwApiClient,
18 staging_dir: Arc<PathBuf>,
19 git_user: Arc<str>,
20 rate_limiter: Arc<AuthRateLimiter>,
21 }
22
23 impl MnwServer {
24 pub fn new(
25 api: MnwApiClient,
26 staging_dir: Arc<PathBuf>,
27 git_user: String,
28 rate_limiter: Arc<AuthRateLimiter>,
29 ) -> Self {
30 Self {
31 api,
32 staging_dir,
33 git_user: Arc::from(git_user),
34 rate_limiter,
35 }
36 }
37 }
38
39 impl russh::server::Server for MnwServer {
40 type Handler = handler::MnwHandler;
41
42 fn new_client(&mut self, peer_addr: Option<SocketAddr>) -> Self::Handler {
43 tracing::info!(?peer_addr, "new SSH connection");
44 handler::MnwHandler::new(
45 self.api.clone(),
46 peer_addr,
47 Arc::clone(&self.staging_dir),
48 Arc::clone(&self.git_user),
49 Arc::clone(&self.rate_limiter),
50 )
51 }
52 }
53