Issue tokens to initialize VNC connections

This commit is contained in:
2023-10-18 12:27:50 +02:00
parent 3042bbdac6
commit 4f75cd918d
10 changed files with 173 additions and 2 deletions

View File

@ -1,3 +1,4 @@
use crate::actors::vnc_tokens_actor::VNCTokensManager;
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::{DomainState, DomainXMLUuid};
use crate::libvirt_rest_structures::VMInfo;
@ -208,3 +209,25 @@ pub async fn screenshot(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> H
}
})
}
#[derive(serde::Serialize)]
struct IssueVNCTokenResponse {
token: String,
}
/// Issue a VNC connection token
pub async fn vnc_token(
manager: web::Data<VNCTokensManager>,
id: web::Path<SingleVMUUidReq>,
) -> HttpResult {
Ok(match manager.issue_token(id.uid).await {
Ok(token) => HttpResponse::Ok().json(IssueVNCTokenResponse { token }),
Err(e) => {
log::error!(
"Failed to issue a token for a domain domain {:?} ! {e}",
id.uid
);
HttpResponse::InternalServerError().json("Failed to issue a token for the domain!")
}
})
}