about summary refs log tree commit diff
path: root/tvix/store/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/store/src/utils.rs')
-rw-r--r--tvix/store/src/utils.rs87
1 files changed, 73 insertions, 14 deletions
diff --git a/tvix/store/src/utils.rs b/tvix/store/src/utils.rs
index a09786386eba..8f97651a03a5 100644
--- a/tvix/store/src/utils.rs
+++ b/tvix/store/src/utils.rs
@@ -29,16 +29,81 @@ pub struct CompositionConfigs {
     >,
 }
 
+#[derive(clap::Parser, Clone)]
+pub struct ServiceUrls {
+    #[arg(
+        long,
+        env,
+        default_value = "objectstore+file:///var/lib/tvix-store/blobs.object_store"
+    )]
+    blob_service_addr: String,
+
+    #[arg(
+        long,
+        env,
+        default_value = "sled:///var/lib/tvix-store/directories.sled"
+    )]
+    directory_service_addr: String,
+
+    #[arg(long, env, default_value = "sled:///var/lib/tvix-store/pathinfo.sled")]
+    path_info_service_addr: String,
+}
+
+/// like ServiceUrls, but with different clap defaults
+#[derive(clap::Parser, Clone)]
+pub struct ServiceUrlsGrpc {
+    #[arg(long, env, default_value = "grpc+http://[::1]:8000")]
+    blob_service_addr: String,
+
+    #[arg(long, env, default_value = "grpc+http://[::1]:8000")]
+    directory_service_addr: String,
+
+    #[arg(long, env, default_value = "grpc+http://[::1]:8000")]
+    path_info_service_addr: String,
+}
+
+/// like ServiceUrls, but with different clap defaults
+#[derive(clap::Parser, Clone)]
+pub struct ServiceUrlsMemory {
+    #[arg(long, env, default_value = "memory://")]
+    blob_service_addr: String,
+
+    #[arg(long, env, default_value = "memory://")]
+    directory_service_addr: String,
+
+    #[arg(long, env, default_value = "memory://")]
+    path_info_service_addr: String,
+}
+
+impl From<ServiceUrlsGrpc> for ServiceUrls {
+    fn from(urls: ServiceUrlsGrpc) -> ServiceUrls {
+        ServiceUrls {
+            blob_service_addr: urls.blob_service_addr,
+            directory_service_addr: urls.directory_service_addr,
+            path_info_service_addr: urls.path_info_service_addr,
+        }
+    }
+}
+
+impl From<ServiceUrlsMemory> for ServiceUrls {
+    fn from(urls: ServiceUrlsMemory) -> ServiceUrls {
+        ServiceUrls {
+            blob_service_addr: urls.blob_service_addr,
+            directory_service_addr: urls.directory_service_addr,
+            path_info_service_addr: urls.path_info_service_addr,
+        }
+    }
+}
+
 pub fn addrs_to_configs(
-    blob_service_addr: impl AsRef<str>,
-    directory_service_addr: impl AsRef<str>,
-    path_info_service_addr: impl AsRef<str>,
+    urls: impl Into<ServiceUrls>,
 ) -> Result<CompositionConfigs, Box<dyn std::error::Error + Send + Sync>> {
+    let urls: ServiceUrls = urls.into();
     let mut configs: CompositionConfigs = Default::default();
 
-    let blob_service_url = Url::parse(blob_service_addr.as_ref())?;
-    let directory_service_url = Url::parse(directory_service_addr.as_ref())?;
-    let path_info_service_url = Url::parse(path_info_service_addr.as_ref())?;
+    let blob_service_url = Url::parse(&urls.blob_service_addr)?;
+    let directory_service_url = Url::parse(&urls.directory_service_addr)?;
+    let path_info_service_url = Url::parse(&urls.path_info_service_addr)?;
 
     configs.blobservices.insert(
         "default".into(),
@@ -58,9 +123,7 @@ pub fn addrs_to_configs(
 
 /// Construct the store handles from their addrs.
 pub async fn construct_services(
-    blob_service_addr: impl AsRef<str>,
-    directory_service_addr: impl AsRef<str>,
-    path_info_service_addr: impl AsRef<str>,
+    urls: impl Into<ServiceUrls>,
 ) -> Result<
     (
         Arc<dyn BlobService>,
@@ -70,11 +133,7 @@ pub async fn construct_services(
     ),
     Box<dyn std::error::Error + Send + Sync>,
 > {
-    let configs = addrs_to_configs(
-        blob_service_addr,
-        directory_service_addr,
-        path_info_service_addr,
-    )?;
+    let configs = addrs_to_configs(urls)?;
     construct_services_from_configs(configs).await
 }