isothrum_client/proto/
console.rs1use std::fmt;
4use std::net::SocketAddr;
5
6use isothrum_runner::ConsoleProtocol;
7use serde::{Deserialize, Serialize};
8
9#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
13#[non_exhaustive]
14pub struct ReachedConsole {
15 pub machine: String,
17 pub protocol: ConsoleProtocol,
19 pub endpoint: ConsoleEndpoint,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub user: Option<String>,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub password: Option<String>,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
29 pub note: Option<String>,
30 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
32 pub tunnelled: bool,
33}
34
35#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
37#[serde(tag = "at", rename_all = "snake_case")]
38#[non_exhaustive]
39pub enum ConsoleEndpoint {
40 Loopback {
42 address: SocketAddr,
44 },
45 ProxmoxVnc {
48 websocket: String,
50 port: u16,
52 ticket: String,
54 header: String,
56 authorization: String,
58 insecure: bool,
60 },
61}
62
63impl ReachedConsole {
64 #[must_use]
66 pub fn of(console: &isothrum_runner::Console) -> Option<ReachedConsole> {
67 let endpoint = match &console.endpoint {
68 isothrum_runner::Endpoint::Loopback(address) => ConsoleEndpoint::Loopback { address: *address },
69 isothrum_runner::Endpoint::ProxmoxVnc(vnc) => ConsoleEndpoint::ProxmoxVnc {
70 websocket: vnc.websocket.expose().to_owned(),
71 port: vnc.port,
72 ticket: vnc.ticket.expose().to_owned(),
73 header: vnc.authorization.0.clone(),
74 authorization: vnc.authorization.1.expose().to_owned(),
75 insecure: vnc.insecure,
76 },
77 _ => return None,
78 };
79 Some(ReachedConsole {
80 machine: console.machine.clone(),
81 protocol: console.protocol,
82 endpoint,
83 user: console.user.clone(),
84 password: console.password.as_ref().map(|p| p.expose().to_owned()),
85 note: console.note.clone(),
86 tunnelled: console.tunnel.is_some(),
87 })
88 }
89}
90
91impl fmt::Debug for ReachedConsole {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 f.debug_struct("ReachedConsole")
94 .field("machine", &self.machine)
95 .field("protocol", &self.protocol)
96 .field("endpoint", &self.endpoint)
97 .field("user", &self.user)
98 .field("password", &self.password.as_ref().map(|_| "***"))
99 .field("note", &self.note)
100 .field("tunnelled", &self.tunnelled)
101 .finish()
102 }
103}
104
105impl fmt::Debug for ConsoleEndpoint {
106 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107 match self {
108 ConsoleEndpoint::Loopback { address } => f.debug_struct("Loopback").field("address", address).finish(),
109 ConsoleEndpoint::ProxmoxVnc { port, header, insecure, .. } => f
110 .debug_struct("ProxmoxVnc")
111 .field("port", port)
112 .field("header", header)
113 .field("insecure", insecure)
114 .finish_non_exhaustive(),
115 }
116 }
117}