From e3e597b299ae153c8dc2fd8edff4a6f0557ff594 Mon Sep 17 00:00:00 2001 From: hashableric Date: Tue, 28 Nov 2023 18:15:09 +0700 Subject: [PATCH] feat: add configuration --- .../src/settings/checkpoint_syncer.rs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/rust/hyperlane-base/src/settings/checkpoint_syncer.rs b/rust/hyperlane-base/src/settings/checkpoint_syncer.rs index 342f44732c..14a9d3b7e5 100644 --- a/rust/hyperlane-base/src/settings/checkpoint_syncer.rs +++ b/rust/hyperlane-base/src/settings/checkpoint_syncer.rs @@ -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)] @@ -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, + /// GCS Region + region: String, + }, } impl FromStr for CheckpointSyncerConf { @@ -52,6 +61,21 @@ impl FromStr for CheckpointSyncerConf { .context("Invalid region when parsing storage location")?, }) } + "gcs" => { + let url_components = suffix.split('/').collect::>(); + let (bucket, region, folder): (&str, &str, Option) = 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(), }), @@ -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, + )), }) } }