diff --git a/rustfmt.toml b/rustfmt.toml index 4d32ee1..a5e340b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,4 +2,4 @@ reorder_impl_items = true use_small_heuristics = "Max" -imports_granularity = "Crate" +imports_granularity = "Module" diff --git a/src/bin/detee-cli.rs b/src/bin/detee-cli.rs index 6feaac2..98e284e 100644 --- a/src/bin/detee-cli.rs +++ b/src/bin/detee-cli.rs @@ -1,12 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 -use clap::{builder::PossibleValue, Arg, Command}; -use detee_cli::{ - general::cli_handler::{handle_account, handle_completion, handle_operators, handle_packagers}, - sgx::cli_handler::{handle_app, handle_app_nodes}, - snp::cli_handler::{handle_vm, handle_vm_nodes}, - *, +use clap::builder::PossibleValue; +use clap::{Arg, Command}; +use detee_cli::general::cli_handler::{ + handle_account, handle_completion, handle_operators, handle_packagers, }; +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. All software runs within Trusted Execution Environments on a distributed network. @@ -54,15 +55,15 @@ fn main() { fn clap_cmd() -> Command { let snp_locations = [ - PossibleValue::new("GB").help("London, England, GB"), - PossibleValue::new("Canada").help("Montréal or Vancouver"), - PossibleValue::new("Montreal").help("Montréal, Quebec, CA"), - PossibleValue::new("Vancouver").help("Vancouver, British Columbia, CA"), - PossibleValue::new("California").help("San Jose, California, US"), - PossibleValue::new("US").help("San Jose, California, US"), - PossibleValue::new("France").help("Paris, Île-de-France, FR"), - PossibleValue::new("Any").help("List offers for any location."), - ]; + PossibleValue::new("GB").help("London, England, GB"), + PossibleValue::new("Canada").help("Montréal or Vancouver"), + PossibleValue::new("Montreal").help("Montréal, Quebec, CA"), + PossibleValue::new("Vancouver").help("Vancouver, British Columbia, CA"), + PossibleValue::new("California").help("San Jose, California, US"), + PossibleValue::new("US").help("San Jose, California, US"), + PossibleValue::new("France").help("Paris, Île-de-France, FR"), + PossibleValue::new("Any").help("List offers for any location."), + ]; Command::new("detee-cli") .version(build::CLAP_LONG_VERSION) .author("https://detee.ltd") diff --git a/src/config.rs b/src/config.rs index 30735ec..33f16e0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 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 log::{debug, info, warn}; use openssl::bn::BigNum; @@ -9,7 +10,9 @@ use openssl::hash::{Hasher, MessageDigest}; use openssl::pkey::{PKey, Private}; use openssl::rsa::Rsa; 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)] pub struct AccountData { diff --git a/src/constants.rs b/src/constants.rs index 4ae3f61..d2c589d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -7,8 +7,8 @@ pub const HRATLS_APP_PORT: u32 = 34500; pub const MAX_REDIRECTS: u16 = 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 2 - "https://156.146.63.216:31337", // staging brain 3 + "https://156.146.63.216:31337", // staging brain 2 + "https://156.146.63.216:31337", // staging brain 3 ]; pub const TESTNET_BRAIN_URLS: [&str; 3] = [ diff --git a/src/general/cli_handler.rs b/src/general/cli_handler.rs index 02dc1fe..e0c29f5 100644 --- a/src/general/cli_handler.rs +++ b/src/general/cli_handler.rs @@ -1,10 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use super::operators; -use super::packagers; +use super::{operators, packagers}; use crate::{cli_print, config}; -use clap::ArgMatches; -use clap::Command; +use clap::{ArgMatches, Command}; use clap_complete::{generate, Shell}; use std::error::Error; use std::io; diff --git a/src/name_generator.rs b/src/name_generator.rs index b8b7378..d365928 100644 --- a/src/name_generator.rs +++ b/src/name_generator.rs @@ -380,4 +380,3 @@ const APP_SUBSTANTIVES: [&str; 70] = [ "gecko", "zebra", ]; - diff --git a/src/sgx/cli_handler.rs b/src/sgx/cli_handler.rs index 347c39c..d0e54a2 100644 --- a/src/sgx/cli_handler.rs +++ b/src/sgx/cli_handler.rs @@ -9,18 +9,16 @@ use crate::sgx::packaging::package_enclave; use crate::sgx::utils::{ deploy_new_app_and_update_config, fetch_config, override_envs_and_args_launch_config, }; -use crate::sgx::AppDeleteResponse; use crate::sgx::{ 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::{cli_print, SimpleOutput}; use clap::ArgMatches; use detee_shared::app_proto::ListAppContractsReq; -use detee_shared::sgx::types::brain::AppDeployConfig; -use detee_shared::sgx::types::brain::Resource; +use detee_shared::sgx::types::brain::{AppDeployConfig, Resource}; pub fn handle_app(app_matche: &ArgMatches) { match app_matche.subcommand() { diff --git a/src/sgx/config.rs b/src/sgx/config.rs index 0dcb250..e8aa14e 100644 --- a/src/sgx/config.rs +++ b/src/sgx/config.rs @@ -1,6 +1,7 @@ // 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)] pub enum Error { diff --git a/src/sgx/grpc_dtpm.rs b/src/sgx/grpc_dtpm.rs index 88b8ae1..5a06186 100644 --- a/src/sgx/grpc_dtpm.rs +++ b/src/sgx/grpc_dtpm.rs @@ -1,27 +1,21 @@ // SPDX-License-Identifier: Apache-2.0 -use detee_sgx::{prelude::*, HRaTlsConfigBuilder}; -use detee_shared::{ - common_proto::Empty, - sgx::{pb::dtpm_proto::DtpmGetConfigRes, types::dtpm::FileEntry}, -}; +use detee_sgx::prelude::*; +use detee_sgx::HRaTlsConfigBuilder; +use detee_shared::common_proto::Empty; +use detee_shared::sgx::pb::dtpm_proto::DtpmGetConfigRes; +use detee_shared::sgx::types::dtpm::FileEntry; use hyper_rustls::HttpsConnectorBuilder; use rustls::ClientConfig; use std::sync::{Arc, RwLock}; use tokio::sync::mpsc; use tokio_stream::wrappers::ReceiverStream; -use tonic::{ - codec::CompressionEncoding, - transport::{Channel, Endpoint}, -}; +use tonic::codec::CompressionEncoding; +use tonic::transport::{Channel, Endpoint}; -use detee_shared::sgx::{ - pb::dtpm_proto::{ - dtpm_config_manager_client::DtpmConfigManagerClient, DtpmSetConfigReq, - FileEntry as FileEntryPb, - }, - types::dtpm::DtpmConfig, -}; +use detee_shared::sgx::pb::dtpm_proto::dtpm_config_manager_client::DtpmConfigManagerClient; +use detee_shared::sgx::pb::dtpm_proto::{DtpmSetConfigReq, FileEntry as FileEntryPb}; +use detee_shared::sgx::types::dtpm::DtpmConfig; use crate::config::Config; use crate::sgx::utils::hratls_url_and_mr_enclave_from_app_id; diff --git a/src/sgx/mod.rs b/src/sgx/mod.rs index d8a0161..398e457 100644 --- a/src/sgx/mod.rs +++ b/src/sgx/mod.rs @@ -8,16 +8,14 @@ pub mod packaging; pub mod utils; use crate::config::Config; +use crate::constants::HRATLS_APP_PORT; use crate::snp; -use crate::utils::shorten_string; -use crate::{constants::HRATLS_APP_PORT, utils::block_on}; -use detee_shared::{ - app_proto::{ - AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource, - ListAppContractsReq, NewAppRes, - }, - sgx::types::brain::Resource, +use crate::utils::{block_on, shorten_string}; +use detee_shared::app_proto::{ + AppContract as AppContractPB, AppNodeFilters, AppNodeListResp, AppResource, + ListAppContractsReq, NewAppRes, }; +use detee_shared::sgx::types::brain::Resource; use grpc_brain::get_one_app_node; use serde::{Deserialize, Serialize}; 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> { - use std::{fs::OpenOptions, io::prelude::*}; + use std::fs::OpenOptions; + use std::io::prelude::*; let mut file = OpenOptions::new().create(true).append(true).open(Config::app_uuid_list_path()?).unwrap(); writeln!(file, "{uuid}\t{app_name}")?; diff --git a/src/sgx/utils.rs b/src/sgx/utils.rs index a65b37d..a3a1e2b 100644 --- a/src/sgx/utils.rs +++ b/src/sgx/utils.rs @@ -1,17 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 use crate::constants::HRATLS_APP_PORT; -use crate::sgx::get_one_contract; use crate::sgx::grpc_brain::new_app; -use crate::sgx::grpc_dtpm::connect_app_dtpm_client; -use crate::sgx::grpc_dtpm::set_config_pb; -use crate::sgx::grpc_dtpm::upload_files_pb; -use crate::sgx::package_entry_from_name; +use crate::sgx::grpc_dtpm::{connect_app_dtpm_client, set_config_pb, upload_files_pb}; +use crate::sgx::{get_one_contract, package_entry_from_name}; use detee_shared::app_proto::NewAppRes; use detee_shared::sgx::pb::dtpm_proto::DtpmSetConfigReq; use detee_shared::sgx::types::brain::AppDeployConfig; -use detee_shared::sgx::types::dtpm::DtpmConfig; -use detee_shared::sgx::types::dtpm::EnvironmentEntry; +use detee_shared::sgx::types::dtpm::{DtpmConfig, EnvironmentEntry}; use tokio_retry::strategy::FixedInterval; use tokio_retry::Retry; diff --git a/src/snp/deploy.rs b/src/snp/deploy.rs index d802eee..6d83c0a 100644 --- a/src/snp/deploy.rs +++ b/src/snp/deploy.rs @@ -1,10 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -use super::{ - grpc::{self, proto}, - injector, Distro, Dtrfs, Error, VmSshArgs, DEFAULT_ARCHLINUX, DEFAULT_DTRFS, -}; -use crate::{config::Config, utils::block_on}; +use super::grpc::{self, proto}; +use super::{injector, Distro, Dtrfs, Error, VmSshArgs, DEFAULT_ARCHLINUX, DEFAULT_DTRFS}; +use crate::config::Config; +use crate::utils::block_on; use log::{debug, info}; use serde::{Deserialize, Serialize}; diff --git a/src/snp/grpc.rs b/src/snp/grpc.rs index cade76f..9e32ebe 100644 --- a/src/snp/grpc.rs +++ b/src/snp/grpc.rs @@ -10,9 +10,10 @@ use crate::config::Config; use crate::utils::{self, sign_request}; use lazy_static::lazy_static; use log::{debug, info, warn}; +use proto::brain_vm_cli_client::BrainVmCliClient; use proto::{ - brain_vm_cli_client::BrainVmCliClient, DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq, - NewVmResp, UpdateVmReq, UpdateVmResp, VmContract, VmNodeFilters, VmNodeListResp, + DeleteVmReq, ExtendVmReq, ListVmContractsReq, NewVmReq, NewVmResp, UpdateVmReq, UpdateVmResp, + VmContract, VmNodeFilters, VmNodeListResp, }; use tokio_stream::StreamExt; use tonic::metadata::errors::InvalidMetadataValue; diff --git a/src/snp/injector.rs b/src/snp/injector.rs index 4edc22a..f2195f0 100644 --- a/src/snp/injector.rs +++ b/src/snp/injector.rs @@ -1,6 +1,7 @@ // 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 std::net::IpAddr; diff --git a/src/snp/mod.rs b/src/snp/mod.rs index 80682fd..e80c53c 100644 --- a/src/snp/mod.rs +++ b/src/snp/mod.rs @@ -6,11 +6,9 @@ pub mod grpc; mod injector; pub mod update; -use crate::{ - config::{self, Config}, - snp, - utils::{block_on, display_mib_or_gib, shorten_string}, -}; +use crate::config::{self, Config}; +use crate::snp; +use crate::utils::{block_on, display_mib_or_gib, shorten_string}; use grpc::proto; use lazy_static::lazy_static; 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> { - use std::{fs::OpenOptions, io::prelude::*}; + use std::fs::OpenOptions; + use std::io::prelude::*; let mut file = OpenOptions::new().create(true).append(true).open(Config::vm_uuid_list_path()?)?; writeln!(file, "{uuid}\t{hostname}")?; diff --git a/src/snp/update.rs b/src/snp/update.rs index da34991..c35e1b0 100644 --- a/src/snp/update.rs +++ b/src/snp/update.rs @@ -1,9 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use super::{ - grpc::{self, proto}, - injector, Dtrfs, Error, -}; +use super::grpc::{self, proto}; +use super::{injector, Dtrfs, Error}; use crate::config::Config; use crate::utils::block_on; use log::{debug, info}; @@ -34,7 +32,8 @@ impl Request { 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() { log::info!("Skipping hardware upgrade (no arguments specified)."); return Ok(()); @@ -70,12 +69,7 @@ impl Request { }; let measurement = measurement_args.get_measurement()?; - injector::execute( - measurement, - args.dtrfs_api_endpoint, - None, - &updated_contract.hostname, - )?; + injector::execute(measurement, args.dtrfs_api_endpoint, None, &updated_contract.hostname)?; Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index e16ed89..8fa0bf9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,10 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 use crate::config::Config; -use tonic::{ - metadata::{errors::InvalidMetadataValue, AsciiMetadataValue}, - Request, -}; +use tonic::metadata::errors::InvalidMetadataValue; +use tonic::metadata::AsciiMetadataValue; +use tonic::Request; #[derive(thiserror::Error, Debug)] pub enum Error {