WIP: Add groups support #146
@ -2,7 +2,7 @@ use crate::app_config::AppConfig;
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::extractors::auth_extractor::AuthExtractor;
|
||||
use crate::virtweb_client;
|
||||
use crate::virtweb_client::VMInfo;
|
||||
use crate::virtweb_client::{GroupID, VMInfo};
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
@ -27,7 +27,7 @@ pub struct Rights {
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct GroupInfo {
|
||||
name: String,
|
||||
id: GroupID,
|
||||
vms: Vec<VMInfo>,
|
||||
can_get_state: bool,
|
||||
can_start: bool,
|
||||
@ -62,6 +62,23 @@ pub async fn rights() -> HttpResult {
|
||||
sys_info: rights.can_retrieve_system_info(),
|
||||
};
|
||||
|
||||
for g in rights.list_groups() {
|
||||
let group_vms = virtweb_client::group_vm_info(&g).await?;
|
||||
|
||||
res.groups.push(GroupInfo {
|
||||
id: g,
|
||||
vms: group_vms,
|
||||
can_get_state: false, //TODO
|
||||
can_start: false,
|
||||
can_shutdown: false,
|
||||
can_kill: false,
|
||||
can_reset: false,
|
||||
can_suspend: false,
|
||||
can_resume: false,
|
||||
can_screenshot: false,
|
||||
})
|
||||
}
|
||||
|
||||
for v in rights.list_vm() {
|
||||
let vm_info = virtweb_client::vm_info(v).await?;
|
||||
|
||||
|
@ -12,6 +12,15 @@ pub enum VirtWebClientError {
|
||||
InvalidStatusCode(u16),
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct GroupID(String);
|
||||
|
||||
impl GroupID {
|
||||
pub fn route_vm_info(&self) -> String {
|
||||
format!("/api/group/{}/vm/info", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Copy, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct VMUuid(Uuid);
|
||||
|
||||
@ -147,6 +156,16 @@ impl TokenInfo {
|
||||
false
|
||||
}
|
||||
|
||||
/// List the groups with access
|
||||
pub fn list_groups(&self) -> Vec<GroupID> {
|
||||
self.rights
|
||||
.iter()
|
||||
.filter(|r| r.verb == "GET")
|
||||
.filter(|r| regex!("^/api/group/[^/]+/vm/info$").is_match(&r.path))
|
||||
.map(|r| GroupID(r.path.split("/").nth(3).unwrap().to_string()))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// List the virtual machines with access
|
||||
pub fn list_vm(&self) -> Vec<VMUuid> {
|
||||
self.rights
|
||||
@ -260,6 +279,11 @@ pub async fn vm_screenshot(id: VMUuid) -> anyhow::Result<Vec<u8>> {
|
||||
.to_vec())
|
||||
}
|
||||
|
||||
/// Get the VM of a group
|
||||
pub async fn group_vm_info(id: &GroupID) -> anyhow::Result<Vec<VMInfo>> {
|
||||
json_request(id.route_vm_info()).await
|
||||
}
|
||||
|
||||
/// Get current server information
|
||||
pub async fn get_server_info() -> anyhow::Result<SystemInfo> {
|
||||
json_request("/api/server/info").await
|
||||
|
Loading…
Reference in New Issue
Block a user