Skip to content

Commit

Permalink
Miscellany cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Santtu Lakkala <[email protected]>
  • Loading branch information
slakkala committed Oct 9, 2024
1 parent 093055b commit 9df483d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl AdminClient {
pub async fn watch(&self) -> anyhow::Result<WatchResult> {
use pb::admin::watch_item::Status;
use pb::admin::WatchItem;
let (tx, rx) = async_channel::bounded::<Event>(10);
let (tx, rx) = async_channel::bounded(10);
let (quittx, mut quitrx) = mpsc::channel(1);

let mut watch = self
Expand Down
29 changes: 9 additions & 20 deletions client/src/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;

use anyhow::anyhow;
Expand Down Expand Up @@ -40,11 +41,11 @@ impl TlsConfig {
let client_identity = Identity::from_pem(client_cert, client_key);
let tls_name = self
.tls_name
.as_ref()
.as_deref()
.ok_or_else(|| anyhow!("Missing TLS name"))?;
Ok(ClientTlsConfig::new()
.ca_certificate(ca)
.domain_name(tls_name.as_str())
.domain_name(tls_name)
.identity(client_identity))
}

Expand All @@ -69,32 +70,20 @@ fn transport_config_to_url(ea: &EndpointAddress, with_tls: bool) -> String {
}

async fn connect_unix_socket(endpoint: Endpoint, path: &String) -> anyhow::Result<Channel> {
let mut path = Some(path.to_owned());
let path = Arc::new(path.to_owned());
let ch = endpoint
.connect_with_connector(service_fn(move |_: Uri| {
let path = path.take();
async move {
if let Some(path) = path {
// Connect to a Uds socket
Ok::<_, std::io::Error>(TokioIo::new(UnixStream::connect(path).await?))
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Path already taken",
))
}
}
let path = path.clone();
async move { UnixStream::connect(path.as_ref()).await.map(TokioIo::new) }
}))
.await?;
Ok(ch)
}

async fn connect_vsock_socket(endpoint: Endpoint, vs: &VsockAddr) -> anyhow::Result<Channel> {
let vs = vs.to_owned();
async fn connect_vsock_socket(endpoint: Endpoint, vs: VsockAddr) -> anyhow::Result<Channel> {
let ch = endpoint
.connect_with_connector(service_fn(move |_: Uri| async move {
let stream = VsockStream::connect(vs).await?;
Ok::<_, std::io::Error>(TokioIo::new(stream))
VsockStream::connect(vs).await.map(TokioIo::new)
}))
.await?;
Ok(ch)
Expand All @@ -114,7 +103,7 @@ impl EndpointConfig {
EndpointAddress::Tcp { .. } => endpoint.connect().await?,
EndpointAddress::Unix(unix) => connect_unix_socket(endpoint, unix).await?,
EndpointAddress::Abstract(abs) => connect_unix_socket(endpoint, abs).await?,
EndpointAddress::Vsock(vs) => connect_vsock_socket(endpoint, vs).await?,
EndpointAddress::Vsock(vs) => connect_vsock_socket(endpoint, *vs).await?,
};
Ok(channel)
}
Expand Down
2 changes: 1 addition & 1 deletion src/admin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl AdminServiceImpl {
error!("could not get status of unit {}: {}", &entry.name, err);
self.handle_error(entry)
.await
.with_context(|| "during handle error")?
.context("during handle error")?
}
Ok(status) => {
let inactive = status.active_state != "active";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn parse_application_name(name: &str) -> anyhow::Result<(&str, i32)> {
if let Some(name_no_suffix) = name.strip_suffix(".service") {
if let Some((left, right)) = name_no_suffix.rsplit_once('@') {
let num = right
.parse::<i32>()
.parse()
.with_context(|| format!("While parsing number part of {name}"))?;
return Ok((left, num));
}
Expand Down

0 comments on commit 9df483d

Please sign in to comment.