Skip to content

Commit 40033c3

Browse files
committed
Fix snapshot url
Use the 'snapshot_bucket_name' instead of 'cardao-testnet' in snapshot url builder.
1 parent 416d9bf commit 40033c3

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

mithril-aggregator/src/configuration.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ impl Configuration {
132132
/// Create a snapshot uploader from configuration settings.
133133
pub fn build_snapshot_uploader(&self) -> Result<Arc<dyn SnapshotUploader>, Box<dyn Error>> {
134134
match self.snapshot_uploader_type {
135-
SnapshotUploaderType::Gcp => Ok(Arc::new(RemoteSnapshotUploader::new(Box::new(
136-
GcpFileUploader::new(self.snapshot_bucket_name.to_owned().ok_or_else(|| {
135+
SnapshotUploaderType::Gcp => {
136+
let bucket = self.snapshot_bucket_name.to_owned().ok_or_else(|| {
137137
ConfigError::Message("missing snapshot bucket name".to_string())
138-
})?),
139-
)))),
138+
})?;
139+
Ok(Arc::new(RemoteSnapshotUploader::new(
140+
Box::new(GcpFileUploader::new(bucket.clone())),
141+
bucket,
142+
)))
143+
}
140144
SnapshotUploaderType::Local => Ok(Arc::new(LocalSnapshotUploader::new(
141145
self.get_server_url(),
142146
&self.snapshot_directory,

mithril-aggregator/src/snapshot_uploaders/remote_snapshot_uploader.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ use slog_scope::debug;
77

88
/// GCPSnapshotUploader is a snapshot uploader working using Google Cloud Platform services
99
pub struct RemoteSnapshotUploader {
10+
bucket: String,
1011
file_uploader: Box<dyn RemoteFileUploader>,
1112
}
1213

1314
impl RemoteSnapshotUploader {
1415
/// GCPSnapshotUploader factory
15-
pub fn new(file_uploader: Box<dyn RemoteFileUploader>) -> Self {
16+
pub fn new(file_uploader: Box<dyn RemoteFileUploader>, bucket: String) -> Self {
1617
debug!("New GCPSnapshotUploader created");
17-
Self { file_uploader }
18+
Self {
19+
bucket,
20+
file_uploader,
21+
}
1822
}
1923
}
2024

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

3034
self.file_uploader.upload_file(snapshot_filepath).await?;
@@ -44,7 +48,8 @@ mod tests {
4448
async fn test_upload_snapshot_ok() {
4549
let mut file_uploader = MockRemoteFileUploader::new();
4650
file_uploader.expect_upload_file().return_const(Ok(()));
47-
let snapshot_uploader = RemoteSnapshotUploader::new(Box::new(file_uploader));
51+
let snapshot_uploader =
52+
RemoteSnapshotUploader::new(Box::new(file_uploader), "cardano-testnet".to_string());
4853
let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz");
4954
let expected_location =
5055
"https://storage.googleapis.com/cardano-testnet/snapshot.xxx.tar.gz".to_string();
@@ -61,7 +66,8 @@ mod tests {
6166
file_uploader
6267
.expect_upload_file()
6368
.return_const(Err("unexpected error".to_string()));
64-
let snapshot_uploader = RemoteSnapshotUploader::new(Box::new(file_uploader));
69+
let snapshot_uploader =
70+
RemoteSnapshotUploader::new(Box::new(file_uploader), "".to_string());
6571
let snapshot_filepath = Path::new("test/snapshot.xxx.tar.gz");
6672

6773
let result = snapshot_uploader.upload_snapshot(snapshot_filepath).await;

0 commit comments

Comments
 (0)