Skip to content

Commit

Permalink
Merge pull request #573 from input-output-hk/jpraynaud/542-fix-snapsh…
Browse files Browse the repository at this point in the history
…ot-url

Fix Aggregator snapshot url
  • Loading branch information
jpraynaud authored Oct 27, 2022
2 parents c2d466c + 40033c3 commit ce3d42d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 8 additions & 4 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ impl Configuration {
/// Create a snapshot uploader from configuration settings.
pub fn build_snapshot_uploader(&self) -> Result<Arc<dyn SnapshotUploader>, Box<dyn Error>> {
match self.snapshot_uploader_type {
SnapshotUploaderType::Gcp => Ok(Arc::new(RemoteSnapshotUploader::new(Box::new(
GcpFileUploader::new(self.snapshot_bucket_name.to_owned().ok_or_else(|| {
SnapshotUploaderType::Gcp => {
let bucket = self.snapshot_bucket_name.to_owned().ok_or_else(|| {
ConfigError::Message("missing snapshot bucket name".to_string())
})?),
)))),
})?;
Ok(Arc::new(RemoteSnapshotUploader::new(
Box::new(GcpFileUploader::new(bucket.clone())),
bucket,
)))
}
SnapshotUploaderType::Local => Ok(Arc::new(LocalSnapshotUploader::new(
self.get_server_url(),
&self.snapshot_directory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use slog_scope::debug;

/// GCPSnapshotUploader is a snapshot uploader working using Google Cloud Platform services
pub struct RemoteSnapshotUploader {
bucket: String,
file_uploader: Box<dyn RemoteFileUploader>,
}

impl RemoteSnapshotUploader {
/// GCPSnapshotUploader factory
pub fn new(file_uploader: Box<dyn RemoteFileUploader>) -> Self {
pub fn new(file_uploader: Box<dyn RemoteFileUploader>, bucket: String) -> Self {
debug!("New GCPSnapshotUploader created");
Self { file_uploader }
Self {
bucket,
file_uploader,
}
}
}

Expand All @@ -23,8 +27,8 @@ impl SnapshotUploader for RemoteSnapshotUploader {
async fn upload_snapshot(&self, snapshot_filepath: &Path) -> Result<SnapshotLocation, String> {
let archive_name = snapshot_filepath.file_name().unwrap().to_str().unwrap();
let location = format!(
"https://storage.googleapis.com/cardano-testnet/{}",
archive_name
"https://storage.googleapis.com/{}/{}",
self.bucket, archive_name
);

self.file_uploader.upload_file(snapshot_filepath).await?;
Expand All @@ -44,7 +48,8 @@ mod tests {
async fn test_upload_snapshot_ok() {
let mut file_uploader = MockRemoteFileUploader::new();
file_uploader.expect_upload_file().return_const(Ok(()));
let snapshot_uploader = RemoteSnapshotUploader::new(Box::new(file_uploader));
let snapshot_uploader =
RemoteSnapshotUploader::new(Box::new(file_uploader), "cardano-testnet".to_string());
let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz");
let expected_location =
"https://storage.googleapis.com/cardano-testnet/snapshot.xxx.tar.gz".to_string();
Expand All @@ -61,7 +66,8 @@ mod tests {
file_uploader
.expect_upload_file()
.return_const(Err("unexpected error".to_string()));
let snapshot_uploader = RemoteSnapshotUploader::new(Box::new(file_uploader));
let snapshot_uploader =
RemoteSnapshotUploader::new(Box::new(file_uploader), "".to_string());
let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz");

let result = snapshot_uploader.upload_snapshot(snapshot_filepath).await;
Expand Down

0 comments on commit ce3d42d

Please sign in to comment.