Skip to main content

bestool_canopy/
lib.rs

1use std::fmt;
2
3use serde::{Deserialize, Deserializer, Serialize, Serializer};
4
5mod backup;
6mod client;
7pub mod registration;
8mod restore;
9
10/// Wire types generated at build time from canopy's OpenAPI document.
11///
12/// These track canopy's API as it evolves: the build script fetches the live
13/// spec (falling back to a committed snapshot) and regenerates on each build,
14/// so nothing here is hand-maintained or committed. Use them with the generic
15/// [`CanopyClient::request`]/[`CanopyClient::request_json`] methods; the
16/// bespoke endpoint methods keep their own hand-written types.
17pub mod schema {
18	include!(concat!(env!("OUT_DIR"), "/canopy_schema.rs"));
19}
20
21pub use backup::{
22	BackupCredentials, BackupCredentialsRequest, BackupReport, BackupTarget, CapabilitiesRequest,
23	ContainerCreds, Outcome, Purpose, TargetOutcome,
24};
25pub use client::{
26	CERT_RENEW_AFTER, CanopyClient, ClientBuilderFactory, DEFAULT_CANOPY_URL, NewEvent, Severity,
27	TAILSCALE_URL, client_builder, device_identity, tailscale_client, user_agent,
28};
29pub use reqwest;
30pub use restore::{
31	RestoreCapabilitiesRequest, RestoreCredentials, RestoreCredentialsRequest, RestoreVerification,
32	WorklistEntry,
33};
34
35/// Wraps a sensitive value so its `Debug` output doesn't leak the contents.
36#[derive(Clone)]
37pub struct Redacted<T>(pub T);
38
39impl<T> fmt::Debug for Redacted<T> {
40	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41		f.write_str("<redacted>")
42	}
43}
44
45impl<T> std::ops::Deref for Redacted<T> {
46	type Target = T;
47	fn deref(&self) -> &T {
48		&self.0
49	}
50}
51
52impl<T: Serialize> Serialize for Redacted<T> {
53	fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
54		self.0.serialize(serializer)
55	}
56}
57
58impl<'de, T: Deserialize<'de>> Deserialize<'de> for Redacted<T> {
59	fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
60		T::deserialize(deserializer).map(Redacted)
61	}
62}