Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Aggregator snapshot url #573

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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