Skip to main content

bestool_canopy/
restore.rs

1//! Request bodies for the managed-restore endpoints that canopy's OpenAPI
2//! document doesn't expose as named schemas.
3//!
4//! The restore responses and the verification report are generated wire types —
5//! see [`schema::WorklistEntry`](crate::schema::WorklistEntry),
6//! [`schema::RestoreCredentials`](crate::schema::RestoreCredentials), and
7//! [`schema::VerificationArgs`](crate::schema::VerificationArgs). Only the two
8//! request bodies below live here, because canopy declares them inline rather
9//! than as reusable schema components.
10
11use serde::Serialize;
12use uuid::Uuid;
13
14/// Body for `POST /restore-capabilities`: the restore intents this consumer supports.
15///
16/// Replaces the registered intent set wholesale; canopy dispatches only matching
17/// worklist entries.
18#[derive(Debug, Clone, Serialize)]
19pub struct RestoreCapabilitiesRequest<'a> {
20	pub intents: &'a [&'a str],
21}
22
23/// Body for `POST /restore-credentials`.
24#[derive(Debug, Clone, Serialize)]
25pub struct RestoreCredentialsRequest<'a> {
26	pub group: Uuid,
27	pub r#type: &'a str,
28}
29
30#[cfg(test)]
31mod tests {
32	use serde_json::json;
33
34	use super::*;
35
36	#[test]
37	fn capabilities_request_lists_intents() {
38		let intents = ["verify", "analytics", "disaster-recovery"];
39		let req = RestoreCapabilitiesRequest { intents: &intents };
40		assert_eq!(
41			serde_json::to_value(&req).unwrap(),
42			json!({"intents": ["verify", "analytics", "disaster-recovery"]})
43		);
44	}
45
46	#[test]
47	fn credentials_request_carries_group_and_type() {
48		let group = "11111111-1111-1111-1111-111111111111".parse().unwrap();
49		let req = RestoreCredentialsRequest {
50			group,
51			r#type: "tamanu-postgres",
52		};
53		assert_eq!(
54			serde_json::to_value(&req).unwrap(),
55			json!({
56				"group": "11111111-1111-1111-1111-111111111111",
57				"type": "tamanu-postgres",
58			})
59		);
60	}
61}