snix_castore/object_store/
mod.rs1use object_store::{ObjectStore, ObjectStoreScheme, path::Path};
4use url::Url;
5
6#[cfg(feature = "cloud")]
7mod aws;
8
9pub fn trim_objectstore_prefix(
11 url: &url::Url,
12) -> Result<url::Url, Box<dyn std::error::Error + Send + Sync>> {
13 let s = url.to_string();
16 let mut url = Url::parse(
17 s.strip_prefix("objectstore+")
18 .ok_or("Missing objectstore uri")?,
19 )?;
20 url.set_query(None);
22
23 Ok(url)
24}
25
26pub(crate) async fn setup_object_store<I, K, V>(
34 object_store_url: &Url,
35 opts: I,
36) -> Result<(Box<dyn ObjectStore>, Path), Box<dyn std::error::Error + Send + Sync>>
37where
38 I: IntoIterator<Item = (K, V)>,
39 K: AsRef<str>,
40 V: Into<String> + AsRef<str>,
41{
42 let (object_store_scheme, path) = ObjectStoreScheme::parse(object_store_url)?;
43
44 match object_store_scheme {
45 #[cfg(feature = "cloud")]
46 ObjectStoreScheme::AmazonS3 => {
47 if object_store_url.scheme() != "s3" {
49 return Err(Box::new(std::io::Error::new(
50 std::io::ErrorKind::InvalidInput,
51 "only s3://-style URLs supported",
52 )));
53 }
54
55 let store = aws::setup_aws_object_store(object_store_url, opts).await?;
56 Ok((Box::new(store) as Box<dyn ObjectStore>, path))
57 }
58 _ => Ok(object_store::parse_url_opts(object_store_url, opts)?),
59 }
60}