cargo fmt

This commit is contained in:
Noor 2025-06-25 19:20:31 +05:30
parent af22741ade
commit fd8dbd9ce7
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146
17 changed files with 74 additions and 92 deletions

@ -2,4 +2,4 @@
reorder_impl_items = true reorder_impl_items = true
use_small_heuristics = "Max" use_small_heuristics = "Max"
imports_granularity = "Crate" imports_granularity = "Module"

@ -1,12 +1,13 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use clap::{builder::PossibleValue, Arg, Command}; use clap::builder::PossibleValue;
use detee_cli::{ use clap::{Arg, Command};
general::cli_handler::{handle_account, handle_completion, handle_operators, handle_packagers}, use detee_cli::general::cli_handler::{
sgx::cli_handler::{handle_app, handle_app_nodes}, handle_account, handle_completion, handle_operators, handle_packagers,
snp::cli_handler::{handle_vm, handle_vm_nodes},
*,
}; };
use detee_cli::sgx::cli_handler::{handle_app, handle_app_nodes};
use detee_cli::snp::cli_handler::{handle_vm, handle_vm_nodes};
use detee_cli::*;
const ABOUT: &str = r#"The DeTEE CLI allows you to manage and deploy applications and virtual machines. const ABOUT: &str = r#"The DeTEE CLI allows you to manage and deploy applications and virtual machines.
All software runs within Trusted Execution Environments on a distributed network. All software runs within Trusted Execution Environments on a distributed network.
@ -54,15 +55,15 @@ fn main() {
fn clap_cmd() -> Command { fn clap_cmd() -> Command {
let snp_locations = [ let snp_locations = [
PossibleValue::new("GB").help("London, England, GB"), PossibleValue::new("GB").help("London, England, GB"),
PossibleValue::new("Canada").help("Montréal or Vancouver"), PossibleValue::new("Canada").help("Montréal or Vancouver"),
PossibleValue::new("Montreal").help("Montréal, Quebec, CA"), PossibleValue::new("Montreal").help("Montréal, Quebec, CA"),
PossibleValue::new("Vancouver").help("Vancouver, British Columbia, CA"), PossibleValue::new("Vancouver").help("Vancouver, British Columbia, CA"),
PossibleValue::new("California").help("San Jose, California, US"), PossibleValue::new("California").help("San Jose, California, US"),
PossibleValue::new("US").help("San Jose, California, US"), PossibleValue::new("US").help("San Jose, California, US"),
PossibleValue::new("France").help("Paris, Île-de-France, FR"), PossibleValue::new("France").help("Paris, Île-de-France, FR"),
PossibleValue::new("Any").help("List offers for any location."), PossibleValue::new("Any").help("List offers for any location."),
]; ];
Command::new("detee-cli") Command::new("detee-cli")
.version(build::CLAP_LONG_VERSION) .version(build::CLAP_LONG_VERSION)
.author("https://detee.ltd") .author("https://detee.ltd")

@ -1,7 +1,8 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use crate::constants::{BRAIN_STAGING, BRAIN_TESTING}; use crate::constants::{BRAIN_STAGING, BRAIN_TESTING};
use crate::{general, utils::block_on}; use crate::general;
use crate::utils::block_on;
use ed25519_dalek::SigningKey; use ed25519_dalek::SigningKey;
use log::{debug, info, warn}; use log::{debug, info, warn};
use openssl::bn::BigNum; use openssl::bn::BigNum;
@ -9,7 +10,9 @@ use openssl::hash::{Hasher, MessageDigest};
use openssl::pkey::{PKey, Private}; use openssl::pkey::{PKey, Private};
use openssl::rsa::Rsa; use openssl::rsa::Rsa;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs::File, io::Write, path::Path}; use std::fs::File;
use std::io::Write;
use std::path::Path;
#[derive(Serialize, Default)] #[derive(Serialize, Default)]
pub struct AccountData { pub struct AccountData {

@ -7,8 +7,8 @@ pub const HRATLS_APP_PORT: u32 = 34500;
pub const MAX_REDIRECTS: u16 = 3; pub const MAX_REDIRECTS: u16 = 3;
pub const STAGING_BRAIN_URLS: [&str; 3] = [ pub const STAGING_BRAIN_URLS: [&str; 3] = [
"https://156.146.63.216:31337", // staging brain 1 "https://156.146.63.216:31337", // staging brain 1
"https://156.146.63.216:31337", // staging brain 2 "https://156.146.63.216:31337", // staging brain 2
"https://156.146.63.216:31337", // staging brain 3 "https://156.146.63.216:31337", // staging brain 3
]; ];
pub const TESTNET_BRAIN_URLS: [&str; 3] = [ pub const TESTNET_BRAIN_URLS: [&str; 3] = [

@ -1,10 +1,8 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use super::operators; use super::{operators, packagers};
use super::packagers;
use crate::{cli_print, config}; use crate::{cli_print, config};
use clap::ArgMatches; use clap::{ArgMatches, Command};
use clap::Command;
use clap_complete::{generate, Shell}; use clap_complete::{generate, Shell};
use std::error::Error; use std::error::Error;
use std::io; use std::io;

@ -380,4 +380,3 @@ const APP_SUBSTANTIVES: [&str; 70] = [
"gecko", "gecko",
"zebra", "zebra",
]; ];

@ -9,18 +9,16 @@ use crate::sgx::packaging::package_enclave;
use crate::sgx::utils::{ use crate::sgx::utils::{
deploy_new_app_and_update_config, fetch_config, override_envs_and_args_launch_config, deploy_new_app_and_update_config, fetch_config, override_envs_and_args_launch_config,
}; };
use crate::sgx::AppDeleteResponse;
use crate::sgx::{ use crate::sgx::{
append_uuid_list, get_app_node, get_app_node_by_contract, get_one_contract, inspect_node, append_uuid_list, get_app_node, get_app_node_by_contract, get_one_contract, inspect_node,
package_entry_from_name, print_nodes, write_uuid_list, package_entry_from_name, print_nodes, write_uuid_list, AppContract, AppDeleteResponse,
AppDeployResponse,
}; };
use crate::sgx::{AppContract, AppDeployResponse};
use crate::utils::block_on; use crate::utils::block_on;
use crate::{cli_print, SimpleOutput}; use crate::{cli_print, SimpleOutput};
use clap::ArgMatches; use clap::ArgMatches;
use detee_shared::app_proto::ListAppContractsReq; use detee_shared::app_proto::ListAppContractsReq;
use detee_shared::sgx::types::brain::AppDeployConfig; use detee_shared::sgx::types::brain::{AppDeployConfig, Resource};
use detee_shared::sgx::types::brain::Resource;
pub fn handle_app(app_matche: &ArgMatches) { pub fn handle_app(app_matche: &ArgMatches) {
match app_matche.subcommand() { match app_matche.subcommand() {

@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use detee_shared::sgx::types::{brain::AppDeployConfig, dtpm::DtpmConfig}; use detee_shared::sgx::types::brain::AppDeployConfig;
use detee_shared::sgx::types::dtpm::DtpmConfig;
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum Error { pub enum Error {

@ -1,27 +1,21 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use detee_sgx::{prelude::*, HRaTlsConfigBuilder}; use detee_sgx::prelude::*;
use detee_shared::{ use detee_sgx::HRaTlsConfigBuilder;
common_proto::Empty, use detee_shared::common_proto::Empty;
sgx::{pb::dtpm_proto::DtpmGetConfigRes, types::dtpm::FileEntry}, use detee_shared::sgx::pb::dtpm_proto::DtpmGetConfigRes;
}; use detee_shared::sgx::types::dtpm::FileEntry;
use hyper_rustls::HttpsConnectorBuilder; use hyper_rustls::HttpsConnectorBuilder;
use rustls::ClientConfig; use rustls::ClientConfig;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
use tonic::{ use tonic::codec::CompressionEncoding;
codec::CompressionEncoding, use tonic::transport::{Channel, Endpoint};
transport::{Channel, Endpoint},
};
use detee_shared::sgx::{ use detee_shared::sgx::pb::dtpm_proto::dtpm_config_manager_client::DtpmConfigManagerClient;
pb::dtpm_proto::{ use detee_shared::sgx::pb::dtpm_proto::{DtpmSetConfigReq, FileEntry as FileEntryPb};
dtpm_config_manager_client::DtpmConfigManagerClient, DtpmSetConfigReq, use detee_shared::sgx::types::dtpm::DtpmConfig;
FileEntry as FileEntryPb,
},
types::dtpm::DtpmConfig,
};
use crate::config::Config; use crate::config::Config;
use crate::sgx::utils::hratls_url_and_mr_enclave_from_app_id; use crate::sgx::utils::hratls_url_and_mr_enclave_from_app_id;

@ -8,16 +8,14 @@ pub mod packaging;
pub mod utils; pub mod utils;
use crate::config::Config; use crate::config::Config;
use crate::constants::HRATLS_APP_PORT;
use crate::snp; use crate::snp;
use crate::utils::shorten_string; use crate::utils::{block_on, shorten_string};
use crate::{constants::HRATLS_APP_PORT, utils::block_on}; use detee_shared::app_proto::{
use detee_shared::{ AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource,
app_proto::{ ListAppContractsReq, NewAppRes,
AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource,
ListAppContractsReq, NewAppRes,
},
sgx::types::brain::Resource,
}; };
use detee_shared::sgx::types::brain::Resource;
use grpc_brain::get_one_app_node; use grpc_brain::get_one_app_node;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::LazyLock; use std::sync::LazyLock;
@ -310,7 +308,8 @@ fn write_uuid_list(app_contracts: &[AppContract]) -> Result<(), Error> {
} }
pub fn append_uuid_list(uuid: &str, app_name: &str) -> Result<(), Error> { pub fn append_uuid_list(uuid: &str, app_name: &str) -> Result<(), Error> {
use std::{fs::OpenOptions, io::prelude::*}; use std::fs::OpenOptions;
use std::io::prelude::*;
let mut file = let mut file =
OpenOptions::new().create(true).append(true).open(Config::app_uuid_list_path()?).unwrap(); OpenOptions::new().create(true).append(true).open(Config::app_uuid_list_path()?).unwrap();
writeln!(file, "{uuid}\t{app_name}")?; writeln!(file, "{uuid}\t{app_name}")?;

@ -1,17 +1,13 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use crate::constants::HRATLS_APP_PORT; use crate::constants::HRATLS_APP_PORT;
use crate::sgx::get_one_contract;
use crate::sgx::grpc_brain::new_app; use crate::sgx::grpc_brain::new_app;
use crate::sgx::grpc_dtpm::connect_app_dtpm_client; use crate::sgx::grpc_dtpm::{connect_app_dtpm_client, set_config_pb, upload_files_pb};
use crate::sgx::grpc_dtpm::set_config_pb; use crate::sgx::{get_one_contract, package_entry_from_name};
use crate::sgx::grpc_dtpm::upload_files_pb;
use crate::sgx::package_entry_from_name;
use detee_shared::app_proto::NewAppRes; use detee_shared::app_proto::NewAppRes;
use detee_shared::sgx::pb::dtpm_proto::DtpmSetConfigReq; use detee_shared::sgx::pb::dtpm_proto::DtpmSetConfigReq;
use detee_shared::sgx::types::brain::AppDeployConfig; use detee_shared::sgx::types::brain::AppDeployConfig;
use detee_shared::sgx::types::dtpm::DtpmConfig; use detee_shared::sgx::types::dtpm::{DtpmConfig, EnvironmentEntry};
use detee_shared::sgx::types::dtpm::EnvironmentEntry;
use tokio_retry::strategy::FixedInterval; use tokio_retry::strategy::FixedInterval;
use tokio_retry::Retry; use tokio_retry::Retry;

@ -1,10 +1,9 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use super::{ use super::grpc::{self, proto};
grpc::{self, proto}, use super::{injector, Distro, Dtrfs, Error, VmSshArgs, DEFAULT_ARCHLINUX, DEFAULT_DTRFS};
injector, Distro, Dtrfs, Error, VmSshArgs, DEFAULT_ARCHLINUX, DEFAULT_DTRFS, use crate::config::Config;
}; use crate::utils::block_on;
use crate::{config::Config, utils::block_on};
use log::{debug, info}; use log::{debug, info};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

@ -10,9 +10,10 @@ use crate::config::Config;
use crate::utils::{self, sign_request}; use crate::utils::{self, sign_request};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{debug, info, warn}; use log::{debug, info, warn};
use proto::brain_vm_cli_client::BrainVmCliClient;
use proto::{ use proto::{
brain_vm_cli_client::BrainVmCliClient, DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq, DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq, NewVmResp, UpdateVmReq, UpdateVmResp,
NewVmResp, UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp, VmContract, VmNodeFilters, VmNodeListResp,
}; };
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use tonic::metadata::errors::InvalidMetadataValue; use tonic::metadata::errors::InvalidMetadataValue;

@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use crate::{config::Config, snp::grpc::proto}; use crate::config::Config;
use crate::snp::grpc::proto;
use log::debug; use log::debug;
use std::net::IpAddr; use std::net::IpAddr;

@ -6,11 +6,9 @@ pub mod grpc;
mod injector; mod injector;
pub mod update; pub mod update;
use crate::{ use crate::config::{self, Config};
config::{self, Config}, use crate::snp;
snp, use crate::utils::{block_on, display_mib_or_gib, shorten_string};
utils::{block_on, display_mib_or_gib, shorten_string},
};
use grpc::proto; use grpc::proto;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -352,7 +350,8 @@ fn write_uuid_list(contracts: &[VmContract]) -> Result<(), Error> {
} }
pub fn append_uuid_list(uuid: &str, hostname: &str) -> Result<(), Error> { pub fn append_uuid_list(uuid: &str, hostname: &str) -> Result<(), Error> {
use std::{fs::OpenOptions, io::prelude::*}; use std::fs::OpenOptions;
use std::io::prelude::*;
let mut file = let mut file =
OpenOptions::new().create(true).append(true).open(Config::vm_uuid_list_path()?)?; OpenOptions::new().create(true).append(true).open(Config::vm_uuid_list_path()?)?;
writeln!(file, "{uuid}\t{hostname}")?; writeln!(file, "{uuid}\t{hostname}")?;

@ -1,9 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use super::{ use super::grpc::{self, proto};
grpc::{self, proto}, use super::{injector, Dtrfs, Error};
injector, Dtrfs, Error,
};
use crate::config::Config; use crate::config::Config;
use crate::utils::block_on; use crate::utils::block_on;
use log::{debug, info}; use log::{debug, info};
@ -34,7 +32,8 @@ impl Request {
Some(Dtrfs::load_from_file(path)?) Some(Dtrfs::load_from_file(path)?)
} }
}; };
let req = Self { hostname, vcpus, memory_mib: memory_mb, disk_size_mib: disk_size_gb, dtrfs }; let req =
Self { hostname, vcpus, memory_mib: memory_mb, disk_size_mib: disk_size_gb, dtrfs };
if req == Self::default() { if req == Self::default() {
log::info!("Skipping hardware upgrade (no arguments specified)."); log::info!("Skipping hardware upgrade (no arguments specified).");
return Ok(()); return Ok(());
@ -70,12 +69,7 @@ impl Request {
}; };
let measurement = measurement_args.get_measurement()?; let measurement = measurement_args.get_measurement()?;
injector::execute( injector::execute(measurement, args.dtrfs_api_endpoint, None, &updated_contract.hostname)?;
measurement,
args.dtrfs_api_endpoint,
None,
&updated_contract.hostname,
)?;
Ok(()) Ok(())
} }

@ -1,10 +1,9 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use crate::config::Config; use crate::config::Config;
use tonic::{ use tonic::metadata::errors::InvalidMetadataValue;
metadata::{errors::InvalidMetadataValue, AsciiMetadataValue}, use tonic::metadata::AsciiMetadataValue;
Request, use tonic::Request;
};
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum Error { pub enum Error {