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::{
21 ConsoleAttachment, ConsoleTrait, TermSize,
22};
23use manta_backend_dispatcher::types::K8sDetails;
24
25use crate::dispatcher::StaticBackendDispatcher;
26
27/// Attach an interactive PTY console to a node.
28///
29/// Callers must validate group-member access for `xname` and resolve
30/// vault/k8s URLs BEFORE calling this; see
31/// [`crate::service::authorization::validate_user_group_members_access`].
32pub async fn attach_to_node_console(
33 backend: &StaticBackendDispatcher,
34 token: &str,
35 site_name: &str,
36 xname: &str,
37 term_size: TermSize,
38 k8s: &K8sDetails,
39) -> Result<ConsoleAttachment, Error> {
40 backend
41 .attach_to_node_console(token, site_name, xname, term_size, k8s)
42 .await
43}
44
45/// Attach an interactive PTY console to a running CFS session pod.
46///
47/// Callers must validate session access and session liveness BEFORE
48/// calling this; see [`crate::service::session::validate_session_access`]
49/// and [`crate::service::session::validate_console_session`].
50pub async fn attach_to_session_console(
51 backend: &StaticBackendDispatcher,
52 token: &str,
53 site_name: &str,
54 session_name: &str,
55 term_size: TermSize,
56 k8s: &K8sDetails,
57) -> Result<ConsoleAttachment, Error> {
58 backend
59 .attach_to_session_console(token, site_name, session_name, term_size, k8s)
60 .await
61}