From 96f77a6275c9ba55653bb66316b9601e560d74f5 Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Sat, 26 Nov 2022 15:10:39 -0700 Subject: [PATCH] filter out usb stick during install (#1974) * filter out usb stick during install * remove duplicate error kind * clean out newline --- backend/src/net/cert_resolver.rs | 12 ++++++------ backend/src/net/net_utils.rs | 7 +++++-- backend/src/net/proxy_controller.rs | 4 ++-- backend/src/os_install.rs | 26 +++++++++++++++++++++----- backend/src/util/http_reader.rs | 6 +++--- libs/models/src/errors.rs | 28 +++++++++++----------------- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/backend/src/net/cert_resolver.rs b/backend/src/net/cert_resolver.rs index 9a24144aa..f9ac8966f 100644 --- a/backend/src/net/cert_resolver.rs +++ b/backend/src/net/cert_resolver.rs @@ -147,21 +147,21 @@ impl EmbassyCertResolver { let private_keys = package_cert_data .0 .private_key_to_der() - .map_err(|err| Error::new(eyre!("err {}", err), crate::ErrorKind::BytesError))?; + .map_err(|err| Error::new(eyre!("{}", err), crate::ErrorKind::OpenSsl))?; let mut full_rustls_certs = Vec::new(); for cert in x509_cert_chain.iter() { - let cert = - Certificate(cert.to_der().map_err(|err| { - Error::new(eyre!("err: {}", err), crate::ErrorKind::BytesError) - })?); + let cert = Certificate( + cert.to_der() + .map_err(|err| Error::new(eyre!("{}", err), crate::ErrorKind::OpenSsl))?, + ); full_rustls_certs.push(cert); } let pre_sign_key = PrivateKey(private_keys); let actual_sign_key = any_supported_type(&pre_sign_key) - .map_err(|err| Error::new(eyre!("{}", err), crate::ErrorKind::SignError))?; + .map_err(|err| Error::new(eyre!("{}", err), crate::ErrorKind::OpenSsl))?; let cert_key = CertifiedKey::new(full_rustls_certs, actual_sign_key); diff --git a/backend/src/net/net_utils.rs b/backend/src/net/net_utils.rs index 97ca85999..380ec5f9b 100644 --- a/backend/src/net/net_utils.rs +++ b/backend/src/net/net_utils.rs @@ -15,7 +15,7 @@ pub fn host_addr_fqdn(req: &Request) -> Result { Some(host) => { let host_str = host .to_str() - .map_err(|e| Error::new(eyre!("{}", e), crate::ErrorKind::AsciiError))? + .map_err(|e| Error::new(eyre!("{}", e), crate::ErrorKind::Ascii))? .to_string(); let host_uri: ResourceFqdn = host_str.split(':').next().unwrap().parse()?; @@ -23,7 +23,10 @@ pub fn host_addr_fqdn(req: &Request) -> Result { Ok(host_uri) } - None => Err(Error::new(eyre!("No Host"), crate::ErrorKind::NoHost)), + None => Err(Error::new( + eyre!("No Host header"), + crate::ErrorKind::MissingHeader, + )), } } diff --git a/backend/src/net/proxy_controller.rs b/backend/src/net/proxy_controller.rs index a6855ff8f..c166bd46d 100644 --- a/backend/src/net/proxy_controller.rs +++ b/backend/src/net/proxy_controller.rs @@ -346,13 +346,13 @@ impl ProxyControllerInner { removed_server.shutdown.send(()).map_err(|_| { Error::new( eyre!("Hyper server did not quit properly"), - crate::ErrorKind::JoinError, + crate::ErrorKind::Unknown, ) })?; removed_server .handle .await - .with_kind(crate::ErrorKind::JoinError)?; + .with_kind(crate::ErrorKind::Unknown)?; self.docker_interfaces.remove(&package.clone()); self.docker_iface_lookups .remove(&(package.clone(), interface_id)); diff --git a/backend/src/os_install.rs b/backend/src/os_install.rs index 7bbcb1e4b..179490149 100644 --- a/backend/src/os_install.rs +++ b/backend/src/os_install.rs @@ -37,7 +37,23 @@ pub fn disk() -> Result<(), Error> { #[command(display(display_none))] pub async fn list() -> Result, Error> { - crate::disk::util::list(&Default::default()).await + let skip = Path::new( + &String::from_utf8( + Command::new("grub-probe-default") + .arg("-t") + .arg("disk") + .arg("/cdrom") + .invoke(crate::ErrorKind::Grub) + .await?, + )? + .trim(), + ) + .to_owned(); + Ok(crate::disk::util::list(&Default::default()) + .await? + .into_iter() + .filter(|i| &*i.logicalname != skip) + .collect()) } pub async fn find_wifi_iface() -> Result, Error> { @@ -253,14 +269,14 @@ pub async fn execute( Command::new("chroot") .arg(¤t) .arg("systemd-machine-id-setup") - .invoke(crate::ErrorKind::Unknown) // TODO systemd + .invoke(crate::ErrorKind::Systemd) .await?; Command::new("chroot") .arg(¤t) .arg("ssh-keygen") .arg("-A") - .invoke(crate::ErrorKind::Unknown) // TODO ssh + .invoke(crate::ErrorKind::OpenSsh) .await?; let dev = MountGuard::mount(&Bind::new("/dev"), current.join("dev"), ReadWrite).await?; @@ -270,14 +286,14 @@ pub async fn execute( Command::new("chroot") .arg(¤t) .arg("update-grub") - .invoke(crate::ErrorKind::Unknown) // TODO grub + .invoke(crate::ErrorKind::Grub) .await?; Command::new("chroot") .arg(¤t) .arg("grub-install") .arg("--target=i386-pc") .arg(&disk.logicalname) - .invoke(crate::ErrorKind::Unknown) // TODO grub + .invoke(crate::ErrorKind::Grub) .await?; dev.unmount().await?; diff --git a/backend/src/util/http_reader.rs b/backend/src/util/http_reader.rs index 534624118..a32dd113d 100644 --- a/backend/src/util/http_reader.rs +++ b/backend/src/util/http_reader.rs @@ -108,7 +108,7 @@ impl HttpReader { "{} HTTP range downloading not supported with this unit {value}", http_url ), - crate::ErrorKind::HttpRange, + crate::ErrorKind::MissingHeader, )); } } @@ -121,7 +121,7 @@ impl HttpReader { "{} HTTP range downloading not supported with this url", http_url ), - crate::ErrorKind::HttpRange, + crate::ErrorKind::MissingHeader, )) } }; @@ -136,7 +136,7 @@ impl HttpReader { None => { return Err(Error::new( eyre!("No content length headers for {}", http_url), - crate::ErrorKind::ContentLength, + crate::ErrorKind::MissingHeader, )) } }; diff --git a/libs/models/src/errors.rs b/libs/models/src/errors.rs index a6fedd547..681ec9086 100644 --- a/libs/models/src/errors.rs +++ b/libs/models/src/errors.rs @@ -70,14 +70,11 @@ pub enum ErrorKind { Javascript = 59, Pem = 60, TLSInit = 61, - HttpRange = 62, - ContentLength = 63, - BytesError = 64, - InvalidIP = 65, - JoinError = 66, - AsciiError = 67, - NoHost = 68, - SignError = 69, + Ascii = 62, + MissingHeader = 63, + Grub = 64, + Systemd = 65, + OpenSsh = 66, } impl ErrorKind { pub fn as_str(&self) -> &'static str { @@ -143,15 +140,12 @@ impl ErrorKind { LanPortConflict => "Incompatible LAN Port Configuration", Javascript => "Javascript Engine Error", Pem => "PEM Encoding Error", - TLSInit => "TLS Backend Initialize Error", - HttpRange => "No Support for Web Server HTTP Ranges", - ContentLength => "Request has no content length header", - BytesError => "Could not get the bytes for this request", - InvalidIP => "Could not parse this IP address", - JoinError => "Join Handle Error", - AsciiError => "Could not parse ascii text", - NoHost => "No Host header ", - SignError => "Signing error", + TLSInit => "TLS Backend Initialization Error", + Ascii => "ASCII Parse Error", + MissingHeader => "Missing Header", + Grub => "Grub Error", + Systemd => "Systemd Error", + OpenSsh => "OpenSSH Error", } } }