incus_client/config.rs
1use std::path::PathBuf;
2use std::time::Duration;
3
4/// Default per-request timeout applied to every plain HTTP call made over
5/// the transport (see `transport::unix::execute_capped`). Chosen as a sane
6/// default for a local Unix-socket daemon call - `wait_for_operation`'s own
7/// explicit `timeout` parameter is unrelated and unaffected by this (it
8/// already has its own bounded semantics via the server-side `timeout`
9/// query param on Incus's long-poll `.../wait` endpoint).
10pub(crate) const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
11
12/// Connection configuration for [`crate::Client`].
13///
14/// This epic only supports a local Unix-socket target. A `remote(url)`
15/// constructor for the mutual-TLS transport is intentionally absent - see
16/// the crate root doc comment.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct ClientConfig {
19 pub(crate) socket_path: PathBuf,
20 pub(crate) request_timeout: Option<Duration>,
21}
22
23impl ClientConfig {
24 /// Configure a client that connects to the Incus daemon over the given
25 /// Unix domain socket path (e.g. `/var/lib/incus/unix.socket`).
26 ///
27 /// Defaults to a 30-second per-request timeout - override it with
28 /// [`ClientConfig::with_request_timeout`].
29 #[must_use]
30 pub fn unix_socket(path: impl Into<PathBuf>) -> Self {
31 Self {
32 socket_path: path.into(),
33 request_timeout: Some(DEFAULT_REQUEST_TIMEOUT),
34 }
35 }
36
37 /// Overrides the default 30-second per-request timeout. Pass `None` to
38 /// disable it and wait indefinitely.
39 #[must_use]
40 pub fn with_request_timeout(mut self, timeout: Option<Duration>) -> Self {
41 self.request_timeout = timeout;
42 self
43 }
44}
45
46#[cfg(test)]
47#[path = "config_tests.rs"]
48mod tests;