fix: GCS correctly splitting storage location into bucket and folder (if present) (#4539)

### Description

Previously Checkpoint Syncer wasn't correctly parsing the storage
location string. If no folder was provided, it treated the object name
as folder, e.g. reading `gs://bucket-name/gcsLatestIndexKey` initialized
StorageClient with bucket `bucket-name` and folder `gcsLatestIndexKey`.
This was due to incorrect logic for splitting the string by `/` that
expected a folder to be present.

In this PR I fixed this logic, treating a location with only one `/` as
_bucket/object_ and with two `/`s as _bucket/folder/object_.

### Backward compatibility

Yes

### Testing

Manual

---------

Co-authored-by: Trevor Porter <tkporter4@gmail.com>
pull/4535/head
Roman V 1 month ago committed by GitHub
parent 0a22e96553
commit 8fee6aedc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs
  2. 2
      rust/main/hyperlane-base/tests/chain_config.rs

@ -73,21 +73,25 @@ impl FromStr for CheckpointSyncerConf {
"gs" => { "gs" => {
let service_account_key = env::var(GCS_SERVICE_ACCOUNT_KEY).ok(); let service_account_key = env::var(GCS_SERVICE_ACCOUNT_KEY).ok();
let user_secrets = env::var(GCS_USER_SECRET).ok(); let user_secrets = env::var(GCS_USER_SECRET).ok();
if let Some(ind) = suffix.find('/') { let url_components = suffix.split('/').collect::<Vec<&str>>();
let (bucket, folder) = suffix.split_at(ind); let (bucket, folder): (&str, Option<String>) = match url_components.len() {
Ok(Self::Gcs { 2 => Ok((url_components[0], None)),
3 => Ok((url_components[0], Some(url_components[1].to_owned()))),
_ => Err(eyre!("Error parsing storage location; could not split bucket and folder ({suffix})"))
}?;
match folder {
None => Ok(CheckpointSyncerConf::Gcs {
bucket: bucket.into(), bucket: bucket.into(),
folder: Some(folder.into()), folder: None,
service_account_key, service_account_key,
user_secrets, user_secrets,
}) }),
} else { Some(folder) => Ok(CheckpointSyncerConf::Gcs {
Ok(Self::Gcs { bucket: bucket.into(),
bucket: suffix.into(), folder: Some(folder),
folder: None,
service_account_key, service_account_key,
user_secrets, user_secrets,
}) }),
} }
} }
_ => Err(eyre!("Unknown storage location prefix `{prefix}`")), _ => Err(eyre!("Unknown storage location prefix `{prefix}`")),

@ -92,7 +92,7 @@ fn chain_name_domain_records() -> BTreeSet<ChainCoordinate> {
.flat_map(|x: &Settings| { .flat_map(|x: &Settings| {
x.chains.values().map(|v| ChainCoordinate { x.chains.values().map(|v| ChainCoordinate {
name: v.domain.name().into(), name: v.domain.name().into(),
domain: (&v.domain).try_into().expect("Invalid domain id"), domain: (&v.domain).into(),
}) })
}) })
.collect() .collect()

Loading…
Cancel
Save