diff --git a/mithril-aggregator/src/dependency_injection/builder.rs b/mithril-aggregator/src/dependency_injection/builder.rs index 71f5b63c36..bf987fc467 100644 --- a/mithril-aggregator/src/dependency_injection/builder.rs +++ b/mithril-aggregator/src/dependency_injection/builder.rs @@ -79,8 +79,8 @@ use crate::{ AggregatorConfig, AggregatorRunner, AggregatorRuntime, CompressedArchiveSnapshotter, Configuration, DependencyContainer, DumbSnapshotter, DumbUploader, EpochSettingsStorer, FileUploader, LocalUploader, MetricsService, MithrilSignerRegisterer, MultiSigner, - MultiSignerImpl, RemoteUploader, SingleSignatureAuthenticator, SnapshotUploaderType, - Snapshotter, SnapshotterCompressionAlgorithm, VerificationKeyStorer, + MultiSignerImpl, SingleSignatureAuthenticator, SnapshotUploaderType, Snapshotter, + SnapshotterCompressionAlgorithm, VerificationKeyStorer, }; const SQLITE_FILE: &str = "aggregator.sqlite3"; @@ -462,13 +462,10 @@ impl DependenciesBuilder { ) })?; - Ok(Arc::new(RemoteUploader::new( - Box::new(GcpUploader::new( - bucket, - self.configuration.snapshot_use_cdn_domain, - logger.clone(), - )), - logger, + Ok(Arc::new(GcpUploader::new( + bucket, + self.configuration.snapshot_use_cdn_domain, + logger.clone(), ))) } SnapshotUploaderType::Local => Ok(Arc::new(LocalUploader::new( diff --git a/mithril-aggregator/src/file_uploaders/mod.rs b/mithril-aggregator/src/file_uploaders/mod.rs index 1148322dfd..8ec7ef0f70 100644 --- a/mithril-aggregator/src/file_uploaders/mod.rs +++ b/mithril-aggregator/src/file_uploaders/mod.rs @@ -2,14 +2,12 @@ mod dumb_uploader; mod gcp_uploader; mod interface; mod local_uploader; -mod remote_uploader; pub use dumb_uploader::*; pub use gcp_uploader::GcpUploader; pub use interface::FileLocation; pub use interface::FileUploader; pub use local_uploader::LocalUploader; -pub use remote_uploader::RemoteUploader; #[cfg(test)] pub use interface::MockFileUploader; diff --git a/mithril-aggregator/src/file_uploaders/remote_uploader.rs b/mithril-aggregator/src/file_uploaders/remote_uploader.rs deleted file mode 100644 index f794107e2b..0000000000 --- a/mithril-aggregator/src/file_uploaders/remote_uploader.rs +++ /dev/null @@ -1,84 +0,0 @@ -use async_trait::async_trait; -use slog::{debug, Logger}; -use std::path::Path; - -use mithril_common::logging::LoggerExtensions; -use mithril_common::StdResult; - -use crate::file_uploaders::{FileLocation, FileUploader}; - -/// RemoteUploader is a snapshot uploader working using Google Cloud Platform services -pub struct RemoteUploader { - file_uploader: Box, - logger: Logger, -} - -impl RemoteUploader { - /// RemoteUploader factory - pub fn new(file_uploader: Box, logger: Logger) -> Self { - let logger = logger.new_with_component_name::(); - debug!(logger, "New RemoteUploader created"); - Self { - file_uploader, - logger, - } - } -} - -#[async_trait] -impl FileUploader for RemoteUploader { - async fn upload(&self, snapshot_filepath: &Path) -> StdResult { - let location = self.file_uploader.upload(snapshot_filepath).await?; - debug!(self.logger, "Snapshot upload to remote storage completed"; "location" => &location); - - Ok(location) - } -} - -#[cfg(test)] -mod tests { - use anyhow::anyhow; - use mockall::predicate::eq; - use std::path::Path; - - use crate::file_uploaders::{FileUploader, MockFileUploader}; - use crate::test_tools::TestLogger; - - use super::RemoteUploader; - - #[tokio::test] - async fn upload_call_uploader_and_return_location() { - let mut file_uploader = MockFileUploader::new(); - file_uploader - .expect_upload() - .with(eq(Path::new("test/snapshot.xxx.tar.gz"))) - .times(1) - .returning(|_| Ok("https://cdn.mithril.network/snapshot.xxx.tar.gz".to_string())); - let snapshot_uploader = RemoteUploader::new(Box::new(file_uploader), TestLogger::stdout()); - let filepath = Path::new("test/snapshot.xxx.tar.gz"); - let expected_location = "https://cdn.mithril.network/snapshot.xxx.tar.gz".to_string(); - - let location = snapshot_uploader - .upload(filepath) - .await - .expect("remote upload should not fail"); - - assert_eq!(expected_location, location); - } - - #[tokio::test] - async fn upload_return_error_when_uploader_error() { - let mut file_uploader = MockFileUploader::new(); - file_uploader - .expect_upload() - .returning(|_| Err(anyhow!("unexpected error"))); - let snapshot_uploader = RemoteUploader::new(Box::new(file_uploader), TestLogger::stdout()); - let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz"); - - let result = snapshot_uploader - .upload(snapshot_filepath) - .await - .expect_err("remote upload should fail"); - assert_eq!("unexpected error".to_string(), result.to_string()); - } -} diff --git a/mithril-aggregator/src/lib.rs b/mithril-aggregator/src/lib.rs index b101ad9d6a..4d7c4c03d0 100644 --- a/mithril-aggregator/src/lib.rs +++ b/mithril-aggregator/src/lib.rs @@ -38,7 +38,7 @@ pub use crate::configuration::{ pub use crate::multi_signer::{MultiSigner, MultiSignerImpl}; pub use commands::{CommandType, MainOpts}; pub use dependency_injection::DependencyContainer; -pub use file_uploaders::{DumbUploader, FileUploader, LocalUploader, RemoteUploader}; +pub use file_uploaders::{DumbUploader, FileUploader, LocalUploader}; pub use message_adapters::{FromRegisterSignerAdapter, ToCertificatePendingMessageAdapter}; pub use metrics::*; pub use runtime::{