diff --git a/tvix/castore/src/blobservice/from_addr.rs b/tvix/castore/src/blobservice/from_addr.rs index 1f73c802c..6803b415e 100644 --- a/tvix/castore/src/blobservice/from_addr.rs +++ b/tvix/castore/src/blobservice/from_addr.rs @@ -3,7 +3,8 @@ use url::Url; use crate::{proto::blob_service_client::BlobServiceClient, Error}; use super::{ - BlobService, GRPCBlobService, MemoryBlobService, SimpleFilesystemBlobService, SledBlobService, + BlobService, GRPCBlobService, MemoryBlobService, ObjectStoreBlobService, + SimpleFilesystemBlobService, SledBlobService, }; /// Constructs a new instance of a [BlobService] from an URI. @@ -62,6 +63,17 @@ pub async fn from_addr(uri: &str) -> Result, crate::Error> } Box::new(SimpleFilesystemBlobService::new(url.path().into()).await?) + } else if let Some(_trimmed_scheme) = url.scheme().strip_prefix("objectstore+") { + // We need to convert the URL to string, strip the prefix there, and then + // parse it back as url, as Url::set_scheme() rejects some of the transitions we want to do. + let trimmed_url = { + let s = url.to_string(); + Url::parse(s.strip_prefix("objectstore+").unwrap()).unwrap() + }; + return Ok(Box::new( + ObjectStoreBlobService::parse_url(&trimmed_url) + .map_err(|e| Error::StorageError(e.to_string()))?, + )); } else { Err(crate::Error::StorageError(format!( "unknown scheme: {}", @@ -114,6 +126,14 @@ mod tests { #[test_case("grpc+https://localhost", true; "grpc valid https host without port")] /// Correct scheme to connect to localhost over http, but with additional path, which is invalid. #[test_case("grpc+http://localhost/some-path", false; "grpc valid invalid host and path")] + /// An example for object store (Memory) + #[test_case("objectstore+memory:///", true; "objectstore valid memory url")] + /// An example for object store (File) + #[test_case("objectstore+file:///foo/bar", true; "objectstore valid file url")] // ?? + /// An example for object store (S3) + #[test_case("objectstore+s3://bucket/path", true; "objectstore valid s3 url")] + /// An example for object store (GCS) + #[test_case("objectstore+gs://bucket/path", true; "objectstore valid gcs url")] #[tokio::test] async fn test_from_addr_tokio(uri_str: &str, exp_succeed: bool) { if exp_succeed {