use futures::{future::LocalBoxFuture, prelude::*};
use omaha_client::cup_ecdsa::RequestMetadata;
use omaha_client::installer::{AppInstallResult, Installer, Plan, ProgressObserver};
use omaha_client::protocol::response::Response;
use omaha_client::request_builder::RequestParams;
use thiserror::Error;
#[derive(Debug, Error, Eq, PartialEq)]
pub enum MinimalInstallErrors {
#[error("Minimal Installer Failure")]
Failed,
}
pub enum MinimalInstallResult {
Installed,
Failed,
}
pub struct MinimalInstallPlan;
impl Plan for MinimalInstallPlan {
fn id(&self) -> String {
String::new()
}
}
#[derive(Debug, Default)]
pub struct MinimalInstaller {
pub should_fail: bool,
}
impl Installer for MinimalInstaller {
type InstallPlan = MinimalInstallPlan;
type Error = MinimalInstallErrors;
type InstallResult = MinimalInstallResult;
fn perform_install(
&mut self,
_install_plan: &MinimalInstallPlan,
_observer: Option<&dyn ProgressObserver>,
) -> LocalBoxFuture<'_, (Self::InstallResult, Vec<AppInstallResult<Self::Error>>)> {
if self.should_fail {
future::ready((
MinimalInstallResult::Failed,
vec![AppInstallResult::Failed(MinimalInstallErrors::Failed)],
))
.boxed_local()
} else {
future::ready((
MinimalInstallResult::Installed,
vec![AppInstallResult::Installed],
))
.boxed_local()
}
}
fn perform_reboot(&mut self) -> LocalBoxFuture<'_, Result<(), anyhow::Error>> {
future::ready(Ok(())).boxed_local()
}
fn try_create_install_plan<'a>(
&'a self,
_request_params: &'a RequestParams,
_request_metadata: Option<&'a RequestMetadata>,
response: &'a Response,
_response_bytes: Vec<u8>,
_ecdsa_signature: Option<Vec<u8>>,
) -> LocalBoxFuture<'a, Result<Self::InstallPlan, Self::Error>> {
if response.protocol_version != "3.0" {
future::ready(Err(MinimalInstallErrors::Failed)).boxed_local()
} else {
future::ready(Ok(MinimalInstallPlan)).boxed_local()
}
}
}