Skip to content

Commit

Permalink
feat: add configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hashableric committed Nov 28, 2023
1 parent 6f23741 commit e3e597b
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion rust/hyperlane-base/src/settings/checkpoint_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hyperlane_core::H160;
use prometheus::{IntGauge, IntGaugeVec};
use rusoto_core::Region;

use crate::{CheckpointSyncer, LocalStorage, MultisigCheckpointSyncer, S3Storage};
use crate::{CheckpointSyncer, GCSStorage, LocalStorage, MultisigCheckpointSyncer, S3Storage};

/// Checkpoint Syncer types
#[derive(Debug, Clone)]
Expand All @@ -25,6 +25,15 @@ pub enum CheckpointSyncerConf {
/// S3 Region
region: Region,
},
/// A checkpoint syncer on GCS
GCS {
/// Bucket name
bucket: String,
/// Folder name inside bucket - defaults to the root of the bucket
folder: Option<String>,
/// GCS Region
region: String,
},
}

impl FromStr for CheckpointSyncerConf {
Expand Down Expand Up @@ -52,6 +61,21 @@ impl FromStr for CheckpointSyncerConf {
.context("Invalid region when parsing storage location")?,
})
}
"gcs" => {
let url_components = suffix.split('/').collect::<Vec<&str>>();
let (bucket, region, folder): (&str, &str, Option<String>) = match url_components.len() {
2 => Ok((url_components[0], url_components[1], None)),
3 .. => Ok((url_components[0], url_components[1], Some(url_components[2..].join("/")))),
_ => Err(eyre!("Error parsing storage location; could not split bucket, region and folder ({suffix})"))
}?;
Ok(CheckpointSyncerConf::GCS {
bucket: bucket.into(),
folder,
region: region
.parse()
.context("Invalid region when parsing storage location")?,
})
}
"file" => Ok(CheckpointSyncerConf::LocalStorage {
path: suffix.into(),
}),
Expand Down Expand Up @@ -80,6 +104,16 @@ impl CheckpointSyncerConf {
region.clone(),
latest_index_gauge,
)),
CheckpointSyncerConf::GCS {
bucket,
folder,
region,
} => Box::new(GCSStorage::new(
bucket.clone(),
folder.clone(),
region.clone(),
latest_index_gauge,
)),
})
}
}
Expand Down

0 comments on commit e3e597b

Please sign in to comment.