api: nodes: rustfmt

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-09-15 11:42:28 +02:00
parent 957133077f
commit a332040a7f
1 changed files with 18 additions and 20 deletions

View File

@ -17,8 +17,8 @@ use proxmox::api::{
api, schema::*, ApiHandler, ApiMethod, ApiResponseFuture, Permission, RpcEnvironment, api, schema::*, ApiHandler, ApiMethod, ApiResponseFuture, Permission, RpcEnvironment,
}; };
use proxmox::list_subdirs_api_method; use proxmox::list_subdirs_api_method;
use proxmox_http::websocket::WebSocket;
use proxmox::{identity, sortable}; use proxmox::{identity, sortable};
use proxmox_http::websocket::WebSocket;
use pbs_api_types::{Authid, NODE_SCHEMA, PRIV_SYS_CONSOLE}; use pbs_api_types::{Authid, NODE_SCHEMA, PRIV_SYS_CONSOLE};
use pbs_tools::auth::private_auth_key; use pbs_tools::auth::private_auth_key;
@ -33,17 +33,17 @@ pub mod config;
pub mod disks; pub mod disks;
pub mod dns; pub mod dns;
pub mod network; pub mod network;
pub mod tasks;
pub mod subscription; pub mod subscription;
pub mod tasks;
pub(crate) mod rrd; pub(crate) mod rrd;
mod journal; mod journal;
mod report;
pub(crate) mod services; pub(crate) mod services;
mod status; mod status;
mod syslog; mod syslog;
mod time; mod time;
mod report;
pub const SHELL_CMD_SCHEMA: Schema = StringSchema::new("The command to run.") pub const SHELL_CMD_SCHEMA: Schema = StringSchema::new("The command to run.")
.format(&ApiStringFormat::Enum(&[ .format(&ApiStringFormat::Enum(&[
@ -93,10 +93,7 @@ pub const SHELL_CMD_SCHEMA: Schema = StringSchema::new("The command to run.")
} }
)] )]
/// Call termproxy and return shell ticket /// Call termproxy and return shell ticket
async fn termproxy( async fn termproxy(cmd: Option<String>, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
cmd: Option<String>,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
// intentionally user only for now // intentionally user only for now
let auth_id: Authid = rpcenv let auth_id: Authid = rpcenv
.get_auth_id() .get_auth_id()
@ -119,11 +116,10 @@ async fn termproxy(
let listener = TcpListener::bind("localhost:0")?; let listener = TcpListener::bind("localhost:0")?;
let port = listener.local_addr()?.port(); let port = listener.local_addr()?.port();
let ticket = Ticket::new(ticket::TERM_PREFIX, &Empty)? let ticket = Ticket::new(ticket::TERM_PREFIX, &Empty)?.sign(
.sign( private_auth_key(),
private_auth_key(), Some(&tools::ticket::term_aad(&userid, &path, port)),
Some(&tools::ticket::term_aad(&userid, &path, port)), )?;
)?;
let mut command = Vec::new(); let mut command = Vec::new();
match cmd.as_deref() { match cmd.as_deref() {
@ -202,7 +198,7 @@ async fn termproxy(
}; };
let mut needs_kill = false; let mut needs_kill = false;
let res = tokio::select!{ let res = tokio::select! {
res = child.wait() => { res = child.wait() => {
let exit_code = res?; let exit_code = res?;
if !exit_code.success() { if !exit_code.success() {
@ -291,17 +287,19 @@ fn upgrade_to_websocket(
let port: u16 = pbs_tools::json::required_integer_param(&param, "port")? as u16; let port: u16 = pbs_tools::json::required_integer_param(&param, "port")? as u16;
// will be checked again by termproxy // will be checked again by termproxy
Ticket::<Empty>::parse(ticket)? Ticket::<Empty>::parse(ticket)?.verify(
.verify( crate::auth_helpers::public_auth_key(),
crate::auth_helpers::public_auth_key(), ticket::TERM_PREFIX,
ticket::TERM_PREFIX, Some(&tools::ticket::term_aad(&userid, "/system", port)),
Some(&tools::ticket::term_aad(&userid, "/system", port)), )?;
)?;
let (ws, response) = WebSocket::new(parts.headers.clone())?; let (ws, response) = WebSocket::new(parts.headers.clone())?;
crate::server::spawn_internal_task(async move { crate::server::spawn_internal_task(async move {
let conn: Upgraded = match hyper::upgrade::on(Request::from_parts(parts, req_body)).map_err(Error::from).await { let conn: Upgraded = match hyper::upgrade::on(Request::from_parts(parts, req_body))
.map_err(Error::from)
.await
{
Ok(upgraded) => upgraded, Ok(upgraded) => upgraded,
_ => bail!("error"), _ => bail!("error"),
}; };