1// Copyright 2019 The Fuchsia Authors
2//
3// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6// This file may not be copied, modified, or distributed except according to
7// those terms.
89use super::*;
10use crate::{
11 cup_ecdsa::RequestMetadata, protocol::response::Response, request_builder::RequestParams,
12};
13use futures::future::LocalBoxFuture;
14use futures::prelude::*;
15use thiserror::Error;
1617/// This is the collection of Errors that can occur during the installation of an update.
18///
19/// This is a placeholder stub implementation.
20///
21#[derive(Debug, Error, Eq, PartialEq)]
22pub enum StubInstallErrors {
23#[error("Stub Installer Failure")]
24Failed,
25}
2627/// A stub implementation of the Install Plan.
28///
29pub struct StubPlan;
3031impl Plan for StubPlan {
32fn id(&self) -> String {
33 String::new()
34 }
35}
3637/// The Installer is responsible for performing (or triggering) the installation of the update
38/// that's referred to by the InstallPlan.
39///
40#[derive(Debug, Default)]
41pub struct StubInstaller {
42pub should_fail: bool,
43}
4445impl Installer for StubInstaller {
46type InstallPlan = StubPlan;
47type Error = StubInstallErrors;
48type InstallResult = ();
4950/// Perform the installation as given by the install plan (as parsed form the Omaha server
51 /// response). If given, provide progress via the observer, and a final finished or Error
52 /// indication via the Future.
53fn perform_install(
54&mut self,
55 _install_plan: &StubPlan,
56 _observer: Option<&dyn ProgressObserver>,
57 ) -> LocalBoxFuture<'_, (Self::InstallResult, Vec<AppInstallResult<Self::Error>>)> {
58if self.should_fail {
59 future::ready((
60 (),
61vec![AppInstallResult::Failed(StubInstallErrors::Failed)],
62 ))
63 .boxed_local()
64 } else {
65 future::ready(((), vec![AppInstallResult::Installed])).boxed_local()
66 }
67 }
6869fn perform_reboot(&mut self) -> LocalBoxFuture<'_, Result<(), anyhow::Error>> {
70 future::ready(Ok(())).boxed_local()
71 }
7273fn try_create_install_plan<'a>(
74&'a self,
75 _request_params: &'a RequestParams,
76 _request_metadata: Option<&'a RequestMetadata>,
77 response: &'a Response,
78 _response_bytes: Vec<u8>,
79 _ecdsa_signature: Option<Vec<u8>>,
80 ) -> LocalBoxFuture<'a, Result<Self::InstallPlan, Self::Error>> {
81if response.protocol_version != "3.0" {
82 future::ready(Err(StubInstallErrors::Failed)).boxed_local()
83 } else {
84 future::ready(Ok(StubPlan)).boxed_local()
85 }
86 }
87}