about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-12T14·08+0200
committerflokli <flokli@flokli.de>2023-10-14T12·26+0000
commit3f011d276253852c58559fc12cf9e26bd17ed853 (patch)
tree9a98fcf8ac274179f20e91c21f992f9c147dd06a /tvix
parent199e5e0339ee7d58f9e8a6958c8f9aad5b82e26d (diff)
refactor(tvix/*store): reorganize from_url r/6801
Move the channel creation depending on the string-based URL into its
own block.

Change-Id: I546b769acd2296b548eb966b62c495f910266df5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9706
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/castore/src/blobservice/grpc.rs19
-rw-r--r--tvix/castore/src/directoryservice/grpc.rs21
-rw-r--r--tvix/store/src/pathinfoservice/grpc.rs23
3 files changed, 27 insertions, 36 deletions
diff --git a/tvix/castore/src/blobservice/grpc.rs b/tvix/castore/src/blobservice/grpc.rs
index 52adf2c6dde5..627f011a5041 100644
--- a/tvix/castore/src/blobservice/grpc.rs
+++ b/tvix/castore/src/blobservice/grpc.rs
@@ -48,20 +48,18 @@ impl BlobService for GRPCBlobService {
         match url.scheme().strip_prefix("grpc+") {
             None => Err(crate::Error::StorageError("invalid scheme".to_string())),
             Some(rest) => {
-                if rest == "unix" {
+                let channel = if rest == "unix" {
                     if url.host_str().is_some() {
                         return Err(crate::Error::StorageError(
                             "host may not be set".to_string(),
                         ));
                     }
                     let path = url.path().to_string();
-                    let channel = tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
+                    tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
                         .unwrap()
                         .connect_with_connector_lazy(tower::service_fn(
                             move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
-                        ));
-                    let grpc_client = proto::blob_service_client::BlobServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
+                        ))
                 } else {
                     // ensure path is empty, not supported with gRPC.
                     if !url.path().is_empty() {
@@ -79,13 +77,14 @@ impl BlobService for GRPCBlobService {
                         let s_stripped = url_str.strip_prefix("grpc+").unwrap();
                         url::Url::parse(s_stripped).unwrap()
                     };
-                    let channel = tonic::transport::Endpoint::try_from(url.to_string())
+                    tonic::transport::Endpoint::try_from(url.to_string())
                         .unwrap()
-                        .connect_lazy();
+                        .connect_lazy()
+                };
 
-                    let grpc_client = proto::blob_service_client::BlobServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
-                }
+                Ok(Self::from_client(
+                    proto::blob_service_client::BlobServiceClient::new(channel),
+                ))
             }
         }
     }
diff --git a/tvix/castore/src/directoryservice/grpc.rs b/tvix/castore/src/directoryservice/grpc.rs
index 4ee2d28e97c0..c3207ad064c3 100644
--- a/tvix/castore/src/directoryservice/grpc.rs
+++ b/tvix/castore/src/directoryservice/grpc.rs
@@ -46,21 +46,18 @@ impl DirectoryService for GRPCDirectoryService {
         match url.scheme().strip_prefix("grpc+") {
             None => Err(crate::Error::StorageError("invalid scheme".to_string())),
             Some(rest) => {
-                if rest == "unix" {
+                let channel = if rest == "unix" {
                     if url.host_str().is_some() {
                         return Err(crate::Error::StorageError(
                             "host may not be set".to_string(),
                         ));
                     }
                     let path = url.path().to_string();
-                    let channel = tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
+                    tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
                         .unwrap()
                         .connect_with_connector_lazy(tower::service_fn(
                             move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
-                        ));
-                    let grpc_client =
-                        proto::directory_service_client::DirectoryServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
+                        ))
                 } else {
                     // ensure path is empty, not supported with gRPC.
                     if !url.path().is_empty() {
@@ -78,14 +75,14 @@ impl DirectoryService for GRPCDirectoryService {
                         let s_stripped = url_str.strip_prefix("grpc+").unwrap();
                         url::Url::parse(s_stripped).unwrap()
                     };
-                    let channel = tonic::transport::Endpoint::try_from(url.to_string())
+                    tonic::transport::Endpoint::try_from(url.to_string())
                         .unwrap()
-                        .connect_lazy();
+                        .connect_lazy()
+                };
 
-                    let grpc_client =
-                        proto::directory_service_client::DirectoryServiceClient::new(channel);
-                    Ok(Self::from_client(grpc_client))
-                }
+                Ok(Self::from_client(
+                    proto::directory_service_client::DirectoryServiceClient::new(channel),
+                ))
             }
         }
     }
diff --git a/tvix/store/src/pathinfoservice/grpc.rs b/tvix/store/src/pathinfoservice/grpc.rs
index 3fe1903a14a2..9bb09e86137f 100644
--- a/tvix/store/src/pathinfoservice/grpc.rs
+++ b/tvix/store/src/pathinfoservice/grpc.rs
@@ -44,20 +44,16 @@ impl PathInfoService for GRPCPathInfoService {
         match url.scheme().strip_prefix("grpc+") {
             None => Err(Error::StorageError("invalid scheme".to_string())),
             Some(rest) => {
-                if rest == "unix" {
+                let channel = if rest == "unix" {
                     if url.host_str().is_some() {
                         return Err(Error::StorageError("host may not be set".to_string()));
                     }
                     let path = url.path().to_string();
-                    let channel = tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
+                    tonic::transport::Endpoint::try_from("http://[::]:50051") // doesn't matter
                         .unwrap()
                         .connect_with_connector_lazy(tower::service_fn(
                             move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
-                        ));
-
-                    Ok(Self::from_client(
-                        proto::path_info_service_client::PathInfoServiceClient::new(channel),
-                    ))
+                        ))
                 } else {
                     // ensure path is empty, not supported with gRPC.
                     if !url.path().is_empty() {
@@ -75,14 +71,13 @@ impl PathInfoService for GRPCPathInfoService {
                         let s_stripped = url_str.strip_prefix("grpc+").unwrap();
                         url::Url::parse(s_stripped).unwrap()
                     };
-                    let channel = tonic::transport::Endpoint::try_from(url.to_string())
+                    tonic::transport::Endpoint::try_from(url.to_string())
                         .unwrap()
-                        .connect_lazy();
-
-                    Ok(Self::from_client(
-                        proto::path_info_service_client::PathInfoServiceClient::new(channel),
-                    ))
-                }
+                        .connect_lazy()
+                };
+                Ok(Self::from_client(
+                    proto::path_info_service_client::PathInfoServiceClient::new(channel),
+                ))
             }
         }
     }