Format all code following migration to Rust edition 2024
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -25,6 +25,7 @@ steps:
 | 
			
		||||
  - rustup component add clippy
 | 
			
		||||
  - cd virtweb_backend
 | 
			
		||||
  - cargo clippy -- -D warnings
 | 
			
		||||
  - cargo clippy --examples -- -D warnings
 | 
			
		||||
  - cargo test
 | 
			
		||||
 | 
			
		||||
- name: backend_compile
 | 
			
		||||
 
 | 
			
		||||
@@ -55,12 +55,13 @@ fn main() {
 | 
			
		||||
 | 
			
		||||
    let jwt = key.sign_jwt(&claims).expect("Failed to sign JWT!");
 | 
			
		||||
 | 
			
		||||
    Command::new("curl")
 | 
			
		||||
    let err = Command::new("curl")
 | 
			
		||||
        .args(["-X", &args.verb])
 | 
			
		||||
        .args(["-H", &format!("x-token-id: {}", args.token_id)])
 | 
			
		||||
        .args(["-H", &format!("x-token-content: {jwt}")])
 | 
			
		||||
        .args(args.run)
 | 
			
		||||
        .arg(full_url)
 | 
			
		||||
        .exec();
 | 
			
		||||
    panic!("Failed to run curl!")
 | 
			
		||||
 | 
			
		||||
    panic!("Failed to run cURL! {err}")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
 | 
			
		||||
use crate::api_tokens;
 | 
			
		||||
use crate::api_tokens::{NewToken, TokenID, TokenRights};
 | 
			
		||||
use crate::controllers::api_tokens_controller::rest_token::RestToken;
 | 
			
		||||
use crate::controllers::HttpResult;
 | 
			
		||||
use actix_web::{web, HttpResponse};
 | 
			
		||||
use crate::controllers::api_tokens_controller::rest_token::RestToken;
 | 
			
		||||
use actix_web::{HttpResponse, web};
 | 
			
		||||
use basic_jwt::JWTPrivateKey;
 | 
			
		||||
 | 
			
		||||
/// Create a special module for REST token to enforce usage of constructor function
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
use actix_remote_ip::RemoteIP;
 | 
			
		||||
use actix_web::web::Data;
 | 
			
		||||
use actix_web::{web, HttpResponse, Responder};
 | 
			
		||||
use actix_web::{HttpResponse, Responder, web};
 | 
			
		||||
use light_openid::basic_state_manager::BasicStateManager;
 | 
			
		||||
 | 
			
		||||
use crate::app_config::AppConfig;
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,9 @@ use crate::constants;
 | 
			
		||||
use crate::controllers::HttpResult;
 | 
			
		||||
use crate::utils::files_utils;
 | 
			
		||||
use actix_files::NamedFile;
 | 
			
		||||
use actix_multipart::form::tempfile::TempFile;
 | 
			
		||||
use actix_multipart::form::MultipartForm;
 | 
			
		||||
use actix_web::{web, HttpRequest, HttpResponse};
 | 
			
		||||
use actix_multipart::form::tempfile::TempFile;
 | 
			
		||||
use actix_web::{HttpRequest, HttpResponse, web};
 | 
			
		||||
use futures_util::StreamExt;
 | 
			
		||||
use std::fs::File;
 | 
			
		||||
use std::io::Write;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use crate::libvirt_client::LibVirtClient;
 | 
			
		||||
use actix_http::StatusCode;
 | 
			
		||||
use actix_web::body::BoxBody;
 | 
			
		||||
use actix_web::{web, HttpResponse};
 | 
			
		||||
use actix_web::{HttpResponse, web};
 | 
			
		||||
use std::error::Error;
 | 
			
		||||
use std::fmt::{Display, Formatter};
 | 
			
		||||
use std::io::ErrorKind;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use crate::controllers::{HttpResult, LibVirtReq};
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_rest_structures::net::NetworkInfo;
 | 
			
		||||
use actix_web::{web, HttpResponse};
 | 
			
		||||
use actix_web::{HttpResponse, web};
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct NetworkID {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ use crate::constants;
 | 
			
		||||
use crate::controllers::{HttpResult, LibVirtReq};
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_rest_structures::nw_filter::NetworkFilter;
 | 
			
		||||
use actix_web::{web, HttpResponse};
 | 
			
		||||
use actix_web::{HttpResponse, web};
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
			
		||||
pub struct NetworkFilterID {
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ mod serve_static_debug {
 | 
			
		||||
 | 
			
		||||
#[cfg(not(debug_assertions))]
 | 
			
		||||
mod serve_static_release {
 | 
			
		||||
    use actix_web::{web, HttpResponse, Responder};
 | 
			
		||||
    use actix_web::{HttpResponse, Responder, web};
 | 
			
		||||
    use rust_embed::RustEmbed;
 | 
			
		||||
 | 
			
		||||
    #[derive(RustEmbed)]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
use crate::actors::vnc_handler;
 | 
			
		||||
use crate::actors::vnc_tokens_actor::VNCTokensManager;
 | 
			
		||||
use crate::controllers::{HttpResult, LibVirtReq};
 | 
			
		||||
use crate::libvirt_lib_structures::domain::DomainState;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::DomainState;
 | 
			
		||||
use crate::libvirt_rest_structures::vm::VMInfo;
 | 
			
		||||
use actix_web::{rt, web, HttpRequest, HttpResponse};
 | 
			
		||||
use actix_web::{HttpRequest, HttpResponse, rt, web};
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
use tokio::net::UnixStream;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use actix_identity::Identity;
 | 
			
		||||
use actix_web::dev::Payload;
 | 
			
		||||
use actix_web::{Error, FromRequest, HttpMessage, HttpRequest};
 | 
			
		||||
use futures_util::future::{ready, Ready};
 | 
			
		||||
use futures_util::future::{Ready, ready};
 | 
			
		||||
use std::fmt::Display;
 | 
			
		||||
 | 
			
		||||
pub struct AuthExtractor {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
use crate::controllers::LibVirtReq;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::DomainXML;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::DomainXML;
 | 
			
		||||
use crate::libvirt_rest_structures::vm::VMGroupId;
 | 
			
		||||
use actix_http::Payload;
 | 
			
		||||
use actix_web::error::ErrorBadRequest;
 | 
			
		||||
use actix_web::web::Query;
 | 
			
		||||
use actix_web::{web, Error, FromRequest, HttpRequest};
 | 
			
		||||
use actix_web::{Error, FromRequest, HttpRequest, web};
 | 
			
		||||
use std::future::Future;
 | 
			
		||||
use std::pin::Pin;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use crate::app_config::AppConfig;
 | 
			
		||||
use actix_web::dev::Payload;
 | 
			
		||||
use actix_web::{Error, FromRequest, HttpRequest};
 | 
			
		||||
use futures_util::future::{ready, Ready};
 | 
			
		||||
use futures_util::future::{Ready, ready};
 | 
			
		||||
use std::ops::Deref;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Copy, Clone, PartialEq)]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
use crate::actors::libvirt_actor;
 | 
			
		||||
use crate::actors::libvirt_actor::LibVirtActor;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::{DomainState, DomainXML};
 | 
			
		||||
use crate::libvirt_lib_structures::network::NetworkXML;
 | 
			
		||||
use crate::libvirt_lib_structures::nwfilter::NetworkFilterXML;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_rest_structures::hypervisor::HypervisorInfo;
 | 
			
		||||
use crate::libvirt_rest_structures::net::NetworkInfo;
 | 
			
		||||
use crate::libvirt_rest_structures::nw_filter::NetworkFilter;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
use crate::libvirt_lib_structures::network::*;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::network::*;
 | 
			
		||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
			
		||||
use crate::nat::nat_definition::Nat;
 | 
			
		||||
use crate::nat::nat_lib;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::nwfilter::{
 | 
			
		||||
    NetworkFilterRefXML, NetworkFilterRuleProtocolAllXML, NetworkFilterRuleProtocolArpXML,
 | 
			
		||||
    NetworkFilterRuleProtocolIpvx, NetworkFilterRuleProtocolLayer4, NetworkFilterRuleProtocolMac,
 | 
			
		||||
    NetworkFilterRuleXML, NetworkFilterXML,
 | 
			
		||||
};
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_rest_structures::LibVirtStructError;
 | 
			
		||||
use crate::libvirt_rest_structures::LibVirtStructError::{
 | 
			
		||||
    NetworkFilterExtraction, StructureExtraction,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use crate::app_config::AppConfig;
 | 
			
		||||
use crate::constants;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::*;
 | 
			
		||||
use crate::libvirt_lib_structures::XMLUuid;
 | 
			
		||||
use crate::libvirt_lib_structures::domain::*;
 | 
			
		||||
use crate::libvirt_rest_structures::LibVirtStructError;
 | 
			
		||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
			
		||||
use crate::utils::disks_utils::Disk;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,17 @@
 | 
			
		||||
use actix::Actor;
 | 
			
		||||
use actix_cors::Cors;
 | 
			
		||||
use actix_identity::config::LogoutBehaviour;
 | 
			
		||||
use actix_identity::IdentityMiddleware;
 | 
			
		||||
use actix_multipart::form::tempfile::TempFileConfig;
 | 
			
		||||
use actix_identity::config::LogoutBehaviour;
 | 
			
		||||
use actix_multipart::form::MultipartFormConfig;
 | 
			
		||||
use actix_multipart::form::tempfile::TempFileConfig;
 | 
			
		||||
use actix_remote_ip::RemoteIPConfig;
 | 
			
		||||
use actix_session::storage::CookieSessionStore;
 | 
			
		||||
use actix_session::SessionMiddleware;
 | 
			
		||||
use actix_session::storage::CookieSessionStore;
 | 
			
		||||
use actix_web::cookie::{Key, SameSite};
 | 
			
		||||
use actix_web::http::header;
 | 
			
		||||
use actix_web::middleware::Logger;
 | 
			
		||||
use actix_web::web::Data;
 | 
			
		||||
use actix_web::{web, App, HttpServer};
 | 
			
		||||
use actix_web::{App, HttpServer, web};
 | 
			
		||||
use light_openid::basic_state_manager::BasicStateManager;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
use virtweb_backend::actors::libvirt_actor::LibVirtActor;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
use std::future::{ready, Ready};
 | 
			
		||||
use std::future::{Ready, ready};
 | 
			
		||||
use std::rc::Rc;
 | 
			
		||||
 | 
			
		||||
use crate::app_config::AppConfig;
 | 
			
		||||
@@ -8,8 +8,8 @@ use crate::extractors::auth_extractor::AuthExtractor;
 | 
			
		||||
use actix_web::body::EitherBody;
 | 
			
		||||
use actix_web::dev::Payload;
 | 
			
		||||
use actix_web::{
 | 
			
		||||
    dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
 | 
			
		||||
    Error, FromRequest, HttpResponse,
 | 
			
		||||
    dev::{Service, ServiceRequest, ServiceResponse, Transform, forward_ready},
 | 
			
		||||
};
 | 
			
		||||
use futures_util::future::LocalBoxFuture;
 | 
			
		||||
 | 
			
		||||
@@ -68,7 +68,10 @@ where
 | 
			
		||||
                    .unwrap();
 | 
			
		||||
 | 
			
		||||
            if !AppConfig::get().is_allowed_ip(remote_ip.0) {
 | 
			
		||||
                log::error!("An attempt to access VirtWeb from an unauthorized network has been intercepted! {:?}", remote_ip);
 | 
			
		||||
                log::error!(
 | 
			
		||||
                    "An attempt to access VirtWeb from an unauthorized network has been intercepted! {:?}",
 | 
			
		||||
                    remote_ip
 | 
			
		||||
                );
 | 
			
		||||
                return Ok(req
 | 
			
		||||
                    .into_response(
 | 
			
		||||
                        HttpResponse::MethodNotAllowed()
 | 
			
		||||
@@ -86,8 +89,8 @@ where
 | 
			
		||||
                        Ok(auth) => auth,
 | 
			
		||||
                        Err(e) => {
 | 
			
		||||
                            log::error!(
 | 
			
		||||
                            "Failed to extract API authentication information from request! {e}"
 | 
			
		||||
                        );
 | 
			
		||||
                                "Failed to extract API authentication information from request! {e}"
 | 
			
		||||
                            );
 | 
			
		||||
                            return Ok(req
 | 
			
		||||
                                .into_response(HttpResponse::PreconditionFailed().finish())
 | 
			
		||||
                                .map_into_right_body());
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,9 @@ pub async fn sub_main() -> anyhow::Result<()> {
 | 
			
		||||
    let args = NatArgs::parse();
 | 
			
		||||
 | 
			
		||||
    if !args.network_file().exists() {
 | 
			
		||||
        log::warn!("Cannot do anything for the network, because the NAT configuration file does not exixsts!");
 | 
			
		||||
        log::warn!(
 | 
			
		||||
            "Cannot do anything for the network, because the NAT configuration file does not exixsts!"
 | 
			
		||||
        );
 | 
			
		||||
        return Ok(());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -184,7 +186,9 @@ fn toggle_port_forwarding(
 | 
			
		||||
        false => "tcp",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    log::info!("Forward (add={enable}) incoming {protocol} connections for {host_ip}:{host_port} to {guest_ip}:{guest_port} int {net_interface}");
 | 
			
		||||
    log::info!(
 | 
			
		||||
        "Forward (add={enable}) incoming {protocol} connections for {host_ip}:{host_port} to {guest_ip}:{guest_port} int {net_interface}"
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // Rule 1
 | 
			
		||||
    let cmd = Command::new(program)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user