manta_server/service/console.rs
1//! Console-attach service wrappers.
2//!
3//! [`crate::server::common::app_context::InfraContext`] borrows the
4//! backend and cannot outlive the handler frame. WebSocket upgrade
5//! closures need owned (move-captured) state that is
6//! `'static`-compatible, so these wrappers accept a cloned
7//! [`crate::dispatcher::StaticBackendDispatcher`] instead of
8//! `&InfraContext`.
9//!
10//! Handlers call [`crate::server::common::app_context::InfraContext::backend_clone`]
11//! before the borrowed `infra` is dropped and move the result into the
12//! WebSocket closure.
13//! The closure then delegates here rather than traversing
14//! `state.sites.get(&site_name).backend` directly.
15//!
16//! All authorization and vault/k8s URL checks must be performed in the
17//! handler BEFORE the backend is cloned and the closure is spawned.
18
19use manta_backend_dispatcher::error::Error;
20use manta_backend_dispatcher::interfaces::console::ConsoleTrait;
21use manta_backend_dispatcher::types::K8sDetails;
22use tokio::io::{AsyncRead, AsyncWrite};
23
24use crate::dispatcher::StaticBackendDispatcher;
25
26/// Attach an interactive PTY console to a node.
27///
28/// Callers must validate group-member access for `xname` and resolve
29/// vault/k8s URLs BEFORE calling this; see
30/// [`crate::service::authorization::validate_user_group_members_access`].
31pub async fn attach_to_node_console(
32 backend: &StaticBackendDispatcher,
33 token: &str,
34 site_name: &str,
35 xname: &str,
36 cols: u16,
37 rows: u16,
38 k8s: &K8sDetails,
39) -> Result<
40 (
41 Box<dyn AsyncWrite + Unpin + Send>,
42 Box<dyn AsyncRead + Unpin + Send>,
43 ),
44 Error,
45> {
46 backend
47 .attach_to_node_console(token, site_name, xname, cols, rows, k8s)
48 .await
49}
50
51/// Attach an interactive PTY console to a running CFS session pod.
52///
53/// Callers must validate session access and session liveness BEFORE
54/// calling this; see [`crate::service::session::validate_session_access`]
55/// and [`crate::service::session::validate_console_session`].
56pub async fn attach_to_session_console(
57 backend: &StaticBackendDispatcher,
58 token: &str,
59 site_name: &str,
60 session_name: &str,
61 cols: u16,
62 rows: u16,
63 k8s: &K8sDetails,
64) -> Result<
65 (
66 Box<dyn AsyncWrite + Unpin + Send>,
67 Box<dyn AsyncRead + Unpin + Send>,
68 ),
69 Error,
70> {
71 backend
72 .attach_to_session_console(token, site_name, session_name, cols, rows, k8s)
73 .await
74}