refactor(tvix/*store): reorganize from_url
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
This commit is contained in:
parent
199e5e0339
commit
3f011d2762
3 changed files with 27 additions and 36 deletions
|
@ -48,20 +48,18 @@ impl BlobService for GRPCBlobService {
|
||||||
match url.scheme().strip_prefix("grpc+") {
|
match url.scheme().strip_prefix("grpc+") {
|
||||||
None => Err(crate::Error::StorageError("invalid scheme".to_string())),
|
None => Err(crate::Error::StorageError("invalid scheme".to_string())),
|
||||||
Some(rest) => {
|
Some(rest) => {
|
||||||
if rest == "unix" {
|
let channel = if rest == "unix" {
|
||||||
if url.host_str().is_some() {
|
if url.host_str().is_some() {
|
||||||
return Err(crate::Error::StorageError(
|
return Err(crate::Error::StorageError(
|
||||||
"host may not be set".to_string(),
|
"host may not be set".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let path = url.path().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()
|
.unwrap()
|
||||||
.connect_with_connector_lazy(tower::service_fn(
|
.connect_with_connector_lazy(tower::service_fn(
|
||||||
move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
|
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 {
|
} else {
|
||||||
// ensure path is empty, not supported with gRPC.
|
// ensure path is empty, not supported with gRPC.
|
||||||
if !url.path().is_empty() {
|
if !url.path().is_empty() {
|
||||||
|
@ -79,13 +77,14 @@ impl BlobService for GRPCBlobService {
|
||||||
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
||||||
url::Url::parse(s_stripped).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()
|
.unwrap()
|
||||||
.connect_lazy();
|
.connect_lazy()
|
||||||
|
};
|
||||||
|
|
||||||
let grpc_client = proto::blob_service_client::BlobServiceClient::new(channel);
|
Ok(Self::from_client(
|
||||||
Ok(Self::from_client(grpc_client))
|
proto::blob_service_client::BlobServiceClient::new(channel),
|
||||||
}
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,21 +46,18 @@ impl DirectoryService for GRPCDirectoryService {
|
||||||
match url.scheme().strip_prefix("grpc+") {
|
match url.scheme().strip_prefix("grpc+") {
|
||||||
None => Err(crate::Error::StorageError("invalid scheme".to_string())),
|
None => Err(crate::Error::StorageError("invalid scheme".to_string())),
|
||||||
Some(rest) => {
|
Some(rest) => {
|
||||||
if rest == "unix" {
|
let channel = if rest == "unix" {
|
||||||
if url.host_str().is_some() {
|
if url.host_str().is_some() {
|
||||||
return Err(crate::Error::StorageError(
|
return Err(crate::Error::StorageError(
|
||||||
"host may not be set".to_string(),
|
"host may not be set".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let path = url.path().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()
|
.unwrap()
|
||||||
.connect_with_connector_lazy(tower::service_fn(
|
.connect_with_connector_lazy(tower::service_fn(
|
||||||
move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
|
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 {
|
} else {
|
||||||
// ensure path is empty, not supported with gRPC.
|
// ensure path is empty, not supported with gRPC.
|
||||||
if !url.path().is_empty() {
|
if !url.path().is_empty() {
|
||||||
|
@ -78,14 +75,14 @@ impl DirectoryService for GRPCDirectoryService {
|
||||||
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
||||||
url::Url::parse(s_stripped).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()
|
.unwrap()
|
||||||
.connect_lazy();
|
.connect_lazy()
|
||||||
|
};
|
||||||
|
|
||||||
let grpc_client =
|
Ok(Self::from_client(
|
||||||
proto::directory_service_client::DirectoryServiceClient::new(channel);
|
proto::directory_service_client::DirectoryServiceClient::new(channel),
|
||||||
Ok(Self::from_client(grpc_client))
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,20 +44,16 @@ impl PathInfoService for GRPCPathInfoService {
|
||||||
match url.scheme().strip_prefix("grpc+") {
|
match url.scheme().strip_prefix("grpc+") {
|
||||||
None => Err(Error::StorageError("invalid scheme".to_string())),
|
None => Err(Error::StorageError("invalid scheme".to_string())),
|
||||||
Some(rest) => {
|
Some(rest) => {
|
||||||
if rest == "unix" {
|
let channel = if rest == "unix" {
|
||||||
if url.host_str().is_some() {
|
if url.host_str().is_some() {
|
||||||
return Err(Error::StorageError("host may not be set".to_string()));
|
return Err(Error::StorageError("host may not be set".to_string()));
|
||||||
}
|
}
|
||||||
let path = url.path().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()
|
.unwrap()
|
||||||
.connect_with_connector_lazy(tower::service_fn(
|
.connect_with_connector_lazy(tower::service_fn(
|
||||||
move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
|
move |_: tonic::transport::Uri| UnixStream::connect(path.clone()),
|
||||||
));
|
))
|
||||||
|
|
||||||
Ok(Self::from_client(
|
|
||||||
proto::path_info_service_client::PathInfoServiceClient::new(channel),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
// ensure path is empty, not supported with gRPC.
|
// ensure path is empty, not supported with gRPC.
|
||||||
if !url.path().is_empty() {
|
if !url.path().is_empty() {
|
||||||
|
@ -75,14 +71,13 @@ impl PathInfoService for GRPCPathInfoService {
|
||||||
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
let s_stripped = url_str.strip_prefix("grpc+").unwrap();
|
||||||
url::Url::parse(s_stripped).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()
|
.unwrap()
|
||||||
.connect_lazy();
|
.connect_lazy()
|
||||||
|
};
|
||||||
Ok(Self::from_client(
|
Ok(Self::from_client(
|
||||||
proto::path_info_service_client::PathInfoServiceClient::new(channel),
|
proto::path_info_service_client::PathInfoServiceClient::new(channel),
|
||||||
))
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue