fix clippy warnings
This commit is contained in:
parent
11ccdb54c7
commit
53a654577d
@ -104,7 +104,7 @@ impl Config {
|
|||||||
pub fn verify_and_install_artefacts(file_hash: &str) -> Result<(), Error> {
|
pub fn verify_and_install_artefacts(file_hash: &str) -> Result<(), Error> {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
let artefacts_dir = Config::artefacts_dir()? + "/";
|
let artefacts_dir = Config::artefacts_dir()? + "/";
|
||||||
let file_path = Path::new(&artefacts_dir).join(&file_hash);
|
let file_path = Path::new(&artefacts_dir).join(file_hash);
|
||||||
|
|
||||||
if file_path.exists() {
|
if file_path.exists() {
|
||||||
log::debug!("Artefact '{}' already exists", file_hash);
|
log::debug!("Artefact '{}' already exists", file_hash);
|
||||||
@ -158,7 +158,7 @@ impl Config {
|
|||||||
if !Path::new(&dir).exists() {
|
if !Path::new(&dir).exists() {
|
||||||
std::fs::create_dir_all(dir.clone())?;
|
std::fs::create_dir_all(dir.clone())?;
|
||||||
}
|
}
|
||||||
Ok(String::from(dir + "/uuid_list"))
|
Ok(dir + "/uuid_list")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn path_dir() -> Result<String, Error> {
|
pub fn path_dir() -> Result<String, Error> {
|
||||||
@ -191,11 +191,13 @@ impl Config {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Could not load config due to error: {e}");
|
debug!("Could not load config due to error: {e}");
|
||||||
eprintln!("Config file not found. Creating new config file!");
|
eprintln!("Config file not found. Creating new config file!");
|
||||||
let mut config = Self::default();
|
let config = Self {
|
||||||
config.hratls_pubkey = Self::get_hratls_pubkey_hex();
|
hratls_pubkey: Self::get_hratls_pubkey_hex(),
|
||||||
config.hratls_path = Self::hratls_private_key_path();
|
hratls_path: Self::hratls_private_key_path(),
|
||||||
config.mrsigner = Self::get_mr_signer();
|
mrsigner: Self::get_mr_signer(),
|
||||||
config.signing_key_path = Self::signing_key_path();
|
signing_key_path: Self::signing_key_path(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
if let Err(e) = config.save_to_disk() {
|
if let Err(e) = config.save_to_disk() {
|
||||||
log::error!("Could not save config to disk: {e}");
|
log::error!("Could not save config to disk: {e}");
|
||||||
panic!("Could not initialize config.");
|
panic!("Could not initialize config.");
|
||||||
|
@ -33,18 +33,15 @@ pub fn register(escrow: u64, email: String) -> Result<crate::SimpleOutput, grpc:
|
|||||||
|
|
||||||
impl crate::HumanOutput for brain::InspectOperatorResp {
|
impl crate::HumanOutput for brain::InspectOperatorResp {
|
||||||
fn human_cli_print(&self) {
|
fn human_cli_print(&self) {
|
||||||
match &self.operator {
|
if let Some(op) = &self.operator {
|
||||||
Some(op) => {
|
println!("The operator {} supplies {} nanoLP as escrow,", op.pubkey, op.escrow,);
|
||||||
println!("The operator {} supplies {} nanoLP as escrow,", op.pubkey, op.escrow,);
|
println!(
|
||||||
println!(
|
"has {} app servers, {} VM servers, and {} total reports for all servers.",
|
||||||
"has {} app servers, {} VM servers, and {} total reports for all servers.",
|
op.app_nodes, op.vm_nodes, op.reports
|
||||||
op.app_nodes, op.vm_nodes, op.reports
|
);
|
||||||
);
|
println!("He can be contacted at {}", op.email);
|
||||||
println!("He can be contacted at {}", op.email);
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
if self.vm_nodes.len() == 0 {
|
if self.vm_nodes.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("\n-- VM NODES --");
|
println!("\n-- VM NODES --");
|
||||||
@ -77,7 +74,7 @@ impl crate::HumanOutput for Vec<brain::ListOperatorsResp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_operators() -> Result<Vec<brain::ListOperatorsResp>, grpc::Error> {
|
pub fn print_operators() -> Result<Vec<brain::ListOperatorsResp>, grpc::Error> {
|
||||||
Ok(block_on(grpc::list_operators())?)
|
block_on(grpc::list_operators())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kick(contract_uuid: String, reason: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
pub fn kick(contract_uuid: String, reason: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
||||||
|
@ -7,8 +7,8 @@ pub fn random_app_name() -> String {
|
|||||||
let adjective = ADJECTIVES[random_index].to_string();
|
let adjective = ADJECTIVES[random_index].to_string();
|
||||||
let random_index = rng.gen_range(0..97);
|
let random_index = rng.gen_range(0..97);
|
||||||
let substantive = SUBSTANTIVES[random_index].to_string();
|
let substantive = SUBSTANTIVES[random_index].to_string();
|
||||||
let app_name = adjective + "-" + &substantive;
|
|
||||||
app_name
|
adjective + "-" + &substantive
|
||||||
}
|
}
|
||||||
pub fn random_vm_name() -> String {
|
pub fn random_vm_name() -> String {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
|
@ -51,18 +51,18 @@ fn handle_deploy(
|
|||||||
{
|
{
|
||||||
AppDeployConfig::from_path(file_path).unwrap()
|
AppDeployConfig::from_path(file_path).unwrap()
|
||||||
} else {
|
} else {
|
||||||
let vcpu = deploy_match.get_one::<u32>("vcpus").unwrap().clone();
|
let vcpu = *deploy_match.get_one::<u32>("vcpus").unwrap();
|
||||||
let memory_mb = deploy_match.get_one::<u32>("memory").unwrap().clone();
|
let memory_mb = *deploy_match.get_one::<u32>("memory").unwrap();
|
||||||
let disk_mb = deploy_match.get_one::<u32>("disk").unwrap().clone();
|
let disk_mb = *deploy_match.get_one::<u32>("disk").unwrap();
|
||||||
let port =
|
let port =
|
||||||
deploy_match.get_many::<u32>("port").unwrap_or_default().cloned().collect::<Vec<_>>();
|
deploy_match.get_many::<u32>("port").unwrap_or_default().cloned().collect::<Vec<_>>();
|
||||||
let package_url = deploy_match.get_one::<String>("package-url").unwrap().clone();
|
let package_url = deploy_match.get_one::<String>("package-url").unwrap().clone();
|
||||||
// let package_type = deploy_match.get_one::<String>("package-type").unwrap().clone();
|
// let package_type = deploy_match.get_one::<String>("package-type").unwrap().clone();
|
||||||
let hours = deploy_match.get_one::<u64>("hours").unwrap().clone();
|
let hours = *deploy_match.get_one::<u64>("hours").unwrap();
|
||||||
let node_unit_price = deploy_match.get_one::<u64>("price").unwrap().clone();
|
let node_unit_price = *deploy_match.get_one::<u64>("price").unwrap();
|
||||||
let location = deploy_match.get_one::<String>("location").unwrap().as_str();
|
let location = deploy_match.get_one::<String>("location").unwrap().as_str();
|
||||||
let app_name =
|
let app_name =
|
||||||
deploy_match.get_one::<String>("name").cloned().unwrap_or_else(|| random_app_name());
|
deploy_match.get_one::<String>("name").cloned().unwrap_or_else(random_app_name);
|
||||||
|
|
||||||
// let private_package = package_type == "private";
|
// let private_package = package_type == "private";
|
||||||
let private_package = false;
|
let private_package = false;
|
||||||
@ -88,7 +88,7 @@ fn handle_deploy(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if app_deploy_config.app_name == "" {
|
if app_deploy_config.app_name.is_empty() {
|
||||||
app_deploy_config.app_name = random_app_name();
|
app_deploy_config.app_name = random_app_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ fn handle_deploy(
|
|||||||
override_envs_and_args_launch_config(&mut launch_config, envs, args);
|
override_envs_and_args_launch_config(&mut launch_config, envs, args);
|
||||||
|
|
||||||
match block_on(deploy_new_app_and_update_config(app_deploy_config, launch_config)) {
|
match block_on(deploy_new_app_and_update_config(app_deploy_config, launch_config)) {
|
||||||
Ok(new_app_res) if new_app_res.error == "" => Ok(new_app_res.into()),
|
Ok(new_app_res) if new_app_res.error.is_empty() => Ok(new_app_res.into()),
|
||||||
Ok(new_app_res) => Err(Box::new(std::io::Error::other(new_app_res.error))),
|
Ok(new_app_res) => Err(Box::new(std::io::Error::other(new_app_res.error))),
|
||||||
Err(e) => Err(Box::new(e)),
|
Err(e) => Err(Box::new(e)),
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ fn handle_config_sub_validate(
|
|||||||
check_matche: &ArgMatches,
|
check_matche: &ArgMatches,
|
||||||
) -> Result<SimpleOutput, Box<dyn std::error::Error>> {
|
) -> Result<SimpleOutput, Box<dyn std::error::Error>> {
|
||||||
if let Some(file_path) = check_matche.get_one::<String>("config") {
|
if let Some(file_path) = check_matche.get_one::<String>("config") {
|
||||||
let _config = validate_yaml(&file_path);
|
let _config = validate_yaml(file_path);
|
||||||
Ok(SimpleOutput::from("The YAML file is valid!"))
|
Ok(SimpleOutput::from("The YAML file is valid!"))
|
||||||
} else {
|
} else {
|
||||||
Err(Box::new(std::io::Error::other("config file path argument required")))
|
Err(Box::new(std::io::Error::other("config file path argument required")))
|
||||||
@ -167,7 +167,7 @@ fn handle_config_sub_update(
|
|||||||
if let (Some(file_path), Some(uuid)) =
|
if let (Some(file_path), Some(uuid)) =
|
||||||
(update_matche.get_one::<String>("config"), update_matche.get_one::<String>("uuid"))
|
(update_matche.get_one::<String>("config"), update_matche.get_one::<String>("uuid"))
|
||||||
{
|
{
|
||||||
let loaded_config = validate_yaml(&file_path).unwrap();
|
let loaded_config = validate_yaml(file_path).unwrap();
|
||||||
match block_on(attest_and_send_config(loaded_config, uuid)) {
|
match block_on(attest_and_send_config(loaded_config, uuid)) {
|
||||||
Ok(_) => Ok(SimpleOutput::from("App launch config updated successfully")),
|
Ok(_) => Ok(SimpleOutput::from("App launch config updated successfully")),
|
||||||
Err(e) => Err(Box::new(std::io::Error::other(format!(
|
Err(e) => Err(Box::new(std::io::Error::other(format!(
|
||||||
|
@ -14,13 +14,13 @@ type Result<T> = std::result::Result<T, Error>;
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait DeteeCliExt {
|
pub trait DeteeCliExt {
|
||||||
fn from_path(path: &String) -> Result<Self>
|
fn from_path(path: &str) -> Result<Self>
|
||||||
where
|
where
|
||||||
Self: std::marker::Sized;
|
Self: std::marker::Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeteeCliExt for AppDeployConfig {
|
impl DeteeCliExt for AppDeployConfig {
|
||||||
fn from_path(path: &String) -> Result<Self> {
|
fn from_path(path: &str) -> Result<Self> {
|
||||||
let config_str = std::fs::read_to_string(path)?;
|
let config_str = std::fs::read_to_string(path)?;
|
||||||
Ok(serde_yaml::from_str(&config_str)?)
|
Ok(serde_yaml::from_str(&config_str)?)
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ fn display_mins(minutes: &u64) -> String {
|
|||||||
format!("{hours}h {mins}m")
|
format!("{hours}h {mins}m")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_ports(ports: &Vec<(u32, u32)>) -> String {
|
fn display_ports(ports: &[(u32, u32)]) -> String {
|
||||||
ports.iter().map(|port| format!("({}:{})", port.0, port.1,)).collect::<Vec<_>>().join(", ")
|
ports.iter().map(|port| format!("({}:{})", port.0, port.1,)).collect::<Vec<_>>().join(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,19 +119,16 @@ pub fn override_envs_and_args_launch_config(
|
|||||||
let value =
|
let value =
|
||||||
env.next().expect("environment variable pair must be in the format 'key=value'");
|
env.next().expect("environment variable pair must be in the format 'key=value'");
|
||||||
|
|
||||||
if launch_config.environments.iter().find(|env| env.name == key).is_some() {
|
if launch_config.environments.iter().any(|env| env.name == key) {
|
||||||
let existing_env =
|
let existing_env =
|
||||||
launch_config.environments.iter_mut().find(|env| env.name == key).unwrap();
|
launch_config.environments.iter_mut().find(|env| env.name == key).unwrap();
|
||||||
|
|
||||||
existing_env.name = key.to_string();
|
existing_env.name = key.to_string();
|
||||||
existing_env.value = value.to_string();
|
existing_env.value = value.to_string();
|
||||||
} else {
|
} else {
|
||||||
let mut new_env = EnvironmentEntry::default();
|
launch_config
|
||||||
|
.environments
|
||||||
new_env.name = key.to_string();
|
.push(EnvironmentEntry { name: key.to_string(), value: value.to_string() });
|
||||||
new_env.value = value.to_string();
|
|
||||||
|
|
||||||
launch_config.environments.push(new_env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +142,7 @@ pub async fn deploy_new_app_and_update_config(
|
|||||||
launch_config: DtpmConfig,
|
launch_config: DtpmConfig,
|
||||||
) -> Result<NewAppRes, Error> {
|
) -> Result<NewAppRes, Error> {
|
||||||
let new_app_res = new_app(app_deploy_config).await?;
|
let new_app_res = new_app(app_deploy_config).await?;
|
||||||
if new_app_res.error == "" {
|
if new_app_res.error.is_empty() {
|
||||||
println!("Deploying...");
|
println!("Deploying...");
|
||||||
tokio::time::sleep(tokio::time::Duration::from_millis(3100)).await;
|
tokio::time::sleep(tokio::time::Duration::from_millis(3100)).await;
|
||||||
Retry::spawn(FixedInterval::from_millis(500).take(5), || {
|
Retry::spawn(FixedInterval::from_millis(500).take(5), || {
|
||||||
@ -153,7 +150,7 @@ pub async fn deploy_new_app_and_update_config(
|
|||||||
attest_and_send_config(launch_config.clone(), &new_app_res.uuid)
|
attest_and_send_config(launch_config.clone(), &new_app_res.uuid)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(new_app_res.into())
|
Ok(new_app_res)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Deployment(new_app_res.error))
|
Err(Error::Deployment(new_app_res.error))
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ impl TryFrom<grpc::brain::VmContract> for VmSshArgs {
|
|||||||
args.user = "root".to_string();
|
args.user = "root".to_string();
|
||||||
args.key_path =
|
args.key_path =
|
||||||
Config::init_config().get_ssh_pubkey()?.trim_end_matches(".pub").to_string();
|
Config::init_config().get_ssh_pubkey()?.trim_end_matches(".pub").to_string();
|
||||||
if contract.public_ipv4 != "" {
|
if !contract.public_ipv4.is_empty() {
|
||||||
args.ip = contract.public_ipv4;
|
args.ip = contract.public_ipv4;
|
||||||
args.port = "22".to_string();
|
args.port = "22".to_string();
|
||||||
} else {
|
} else {
|
||||||
@ -96,11 +96,13 @@ pub struct Dtrfs {
|
|||||||
|
|
||||||
impl Dtrfs {
|
impl Dtrfs {
|
||||||
pub fn print_dtrfs_list() -> Vec<Self> {
|
pub fn print_dtrfs_list() -> Vec<Self> {
|
||||||
let mut dtrfs_vec = Vec::new();
|
// let mut dtrfs_vec = Vec::new();
|
||||||
dtrfs_vec.push(DEFAULT_DTRFS.clone());
|
// dtrfs_vec.push(DEFAULT_DTRFS.clone());
|
||||||
dtrfs_vec.push(ALTERNATIVE_INIT[0].clone());
|
// dtrfs_vec.push(ALTERNATIVE_INIT[0].clone());
|
||||||
dtrfs_vec.push(ALTERNATIVE_INIT[1].clone());
|
// dtrfs_vec.push(ALTERNATIVE_INIT[1].clone());
|
||||||
dtrfs_vec
|
// dtrfs_vec
|
||||||
|
|
||||||
|
vec![DEFAULT_DTRFS.clone(), ALTERNATIVE_INIT[0].clone(), ALTERNATIVE_INIT[1].clone()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_from_file(config_path: &str) -> Result<Self, Error> {
|
fn load_from_file(config_path: &str) -> Result<Self, Error> {
|
||||||
@ -131,14 +133,23 @@ impl super::HumanOutput for Vec<Distro> {
|
|||||||
|
|
||||||
impl Distro {
|
impl Distro {
|
||||||
pub fn get_template_list() -> Vec<Self> {
|
pub fn get_template_list() -> Vec<Self> {
|
||||||
let mut distro_vec = Vec::new();
|
// let mut distro_vec = Vec::new();
|
||||||
distro_vec.push(DEFAULT_ARCHLINUX.clone());
|
// distro_vec.push(DEFAULT_ARCHLINUX.clone());
|
||||||
distro_vec.push(DEFAULT_UBUNTU.clone());
|
// distro_vec.push(DEFAULT_UBUNTU.clone());
|
||||||
distro_vec.push(DEFAULT_FEDORA.clone());
|
// distro_vec.push(DEFAULT_FEDORA.clone());
|
||||||
distro_vec.push(ALTERNATIVE_DISTROS[0].clone());
|
// distro_vec.push(ALTERNATIVE_DISTROS[0].clone());
|
||||||
distro_vec.push(ALTERNATIVE_DISTROS[1].clone());
|
// distro_vec.push(ALTERNATIVE_DISTROS[1].clone());
|
||||||
distro_vec.push(ALTERNATIVE_DISTROS[2].clone());
|
// distro_vec.push(ALTERNATIVE_DISTROS[2].clone());
|
||||||
distro_vec
|
// distro_vec
|
||||||
|
|
||||||
|
vec![
|
||||||
|
DEFAULT_ARCHLINUX.clone(),
|
||||||
|
DEFAULT_UBUNTU.clone(),
|
||||||
|
DEFAULT_FEDORA.clone(),
|
||||||
|
ALTERNATIVE_DISTROS[0].clone(),
|
||||||
|
ALTERNATIVE_DISTROS[1].clone(),
|
||||||
|
ALTERNATIVE_DISTROS[2].clone(),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string(distro: &str) -> Distro {
|
pub fn from_string(distro: &str) -> Distro {
|
||||||
@ -250,7 +261,7 @@ pub fn ssh(uuid: &str, just_print: bool) -> Result<VmSshArgs, Error> {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let contracts = block_on(snp::grpc::list_contracts(req))?;
|
let contracts = block_on(snp::grpc::list_contracts(req))?;
|
||||||
if contracts.len() == 0 {
|
if contracts.is_empty() {
|
||||||
return Err(Error::VmContractNotFound(uuid.to_string()));
|
return Err(Error::VmContractNotFound(uuid.to_string()));
|
||||||
}
|
}
|
||||||
let args: VmSshArgs = contracts[0].clone().try_into()?;
|
let args: VmSshArgs = contracts[0].clone().try_into()?;
|
||||||
@ -315,7 +326,7 @@ pub fn list_contracts(as_operator: bool) -> Result<Vec<VmContract>, Error> {
|
|||||||
Ok(contracts)
|
Ok(contracts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_uuid_list(contracts: &Vec<VmContract>) -> Result<(), Error> {
|
fn write_uuid_list(contracts: &[VmContract]) -> Result<(), Error> {
|
||||||
let vm_uuid_list_path = Config::vm_uuid_list_path()?;
|
let vm_uuid_list_path = Config::vm_uuid_list_path()?;
|
||||||
let mut file = std::fs::File::create(vm_uuid_list_path)?;
|
let mut file = std::fs::File::create(vm_uuid_list_path)?;
|
||||||
let output: String = contracts
|
let output: String = contracts
|
||||||
@ -330,7 +341,7 @@ fn write_uuid_list(contracts: &Vec<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, io::prelude::*};
|
||||||
let mut file = OpenOptions::new().write(true).append(true).open(Config::vm_uuid_list_path()?)?;
|
let mut file = OpenOptions::new().append(true).open(Config::vm_uuid_list_path()?)?;
|
||||||
writeln!(file, "{uuid}\t{hostname}")?;
|
writeln!(file, "{uuid}\t{hostname}")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -384,8 +395,8 @@ pub fn calculate_nanolp(
|
|||||||
node_price as f64 / 1_000_000_000.0,
|
node_price as f64 / 1_000_000_000.0,
|
||||||
total_units,
|
total_units,
|
||||||
);
|
);
|
||||||
eprint!(
|
eprintln!(
|
||||||
"Locking {} LP (offering the VM for {} hours).\n",
|
"Locking {} LP (offering the VM for {} hours).",
|
||||||
locked_nano as f64 / 1_000_000_000.0,
|
locked_nano as f64 / 1_000_000_000.0,
|
||||||
hours
|
hours
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user