Skip to main content

canic_backup/manifest/
types.rs

1//! Module: manifest::types
2//!
3//! Responsibility: define serialized backup manifest data contracts.
4//! Does not own: validation, discovery, snapshot capture, or restore actions.
5//! Boundary: stable JSON shapes shared by backup creation and restore flows.
6
7use serde::{Deserialize, Serialize};
8
9///
10/// DeploymentBackupManifest
11///
12/// Top-level deployment backup manifest persisted with a backup bundle.
13/// Owned by backup manifest contracts and consumed by restore planning.
14///
15
16#[derive(Clone, Debug, Deserialize, Serialize)]
17#[serde(deny_unknown_fields)]
18pub struct DeploymentBackupManifest {
19    pub manifest_version: u16,
20    pub backup_id: String,
21    pub created_at: String,
22    pub tool: ToolMetadata,
23    pub source: SourceMetadata,
24    pub consistency: ConsistencySection,
25    pub deployment: DeploymentSection,
26    pub verification: VerificationPlan,
27}
28
29///
30/// ToolMetadata
31///
32/// Tool identity recorded with one generated backup manifest.
33/// Owned by backup manifest contracts and written during backup creation.
34///
35
36#[derive(Clone, Debug, Deserialize, Serialize)]
37#[serde(deny_unknown_fields)]
38pub struct ToolMetadata {
39    pub name: String,
40    pub version: String,
41}
42
43///
44/// SourceMetadata
45///
46/// Source environment identity recorded for a backup bundle.
47/// Owned by backup manifest contracts and used by restore validation.
48///
49
50#[derive(Clone, Debug, Deserialize, Serialize)]
51#[serde(deny_unknown_fields)]
52pub struct SourceMetadata {
53    pub environment: String,
54    pub root_canister: String,
55}
56
57///
58/// ConsistencySection
59///
60/// Backup unit grouping used to validate deployment consistency.
61/// Owned by backup manifest contracts and checked before restore planning.
62///
63
64#[derive(Clone, Debug, Deserialize, Serialize)]
65#[serde(deny_unknown_fields)]
66pub struct ConsistencySection {
67    pub backup_units: Vec<BackupUnit>,
68}
69
70///
71/// BackupUnit
72///
73/// Role grouping that must be captured and restored as one consistency unit.
74/// Owned by backup manifest contracts and validated against deployment roles.
75///
76
77#[derive(Clone, Debug, Deserialize, Serialize)]
78#[serde(deny_unknown_fields)]
79pub struct BackupUnit {
80    pub unit_id: String,
81    pub kind: BackupUnitKind,
82    pub roles: Vec<String>,
83}
84
85///
86/// BackupUnitKind
87///
88/// Consistency grouping mode for a backup unit.
89/// Owned by backup manifest contracts and interpreted by validators.
90///
91
92#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
93#[serde(rename_all = "kebab-case")]
94pub enum BackupUnitKind {
95    Single,
96    Subtree,
97}
98
99///
100/// DeploymentSection
101///
102/// Captured deployment topology and member list for one backup.
103/// Owned by backup manifest contracts and consumed by restore planning.
104///
105
106#[derive(Clone, Debug, Deserialize, Serialize)]
107#[serde(deny_unknown_fields)]
108pub struct DeploymentSection {
109    pub topology_hash_algorithm: String,
110    pub topology_hash_input: String,
111    pub discovery_topology_hash: String,
112    pub pre_snapshot_topology_hash: String,
113    pub topology_hash: String,
114    pub members: Vec<DeploymentMember>,
115}
116
117///
118/// DeploymentMember
119///
120/// One canister member captured in a deployment backup manifest.
121/// Owned by backup manifest contracts and mapped into restore plan members.
122///
123
124#[derive(Clone, Debug, Deserialize, Serialize)]
125#[serde(deny_unknown_fields)]
126pub struct DeploymentMember {
127    pub role: String,
128    pub canister_id: String,
129    #[serde(deserialize_with = "crate::serialization::required_option")]
130    pub parent_canister_id: Option<String>,
131    #[serde(deserialize_with = "crate::serialization::required_option")]
132    pub subnet_canister_id: Option<String>,
133    #[serde(deserialize_with = "crate::serialization::required_option")]
134    pub controller_hint: Option<String>,
135    pub identity_mode: IdentityMode,
136    pub verification_checks: Vec<VerificationCheck>,
137    pub source_snapshot: SourceSnapshot,
138}
139
140///
141/// IdentityMode
142///
143/// Restore identity policy for one deployment member.
144/// Owned by backup manifest contracts and enforced during restore planning.
145///
146
147#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
148#[serde(rename_all = "kebab-case")]
149pub enum IdentityMode {
150    Fixed,
151    Relocatable,
152}
153
154///
155/// SourceSnapshot
156///
157/// Snapshot artifact metadata for one deployment member.
158/// Owned by backup manifest contracts and validated before restore execution.
159///
160
161#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
162#[serde(deny_unknown_fields)]
163pub struct SourceSnapshot {
164    pub snapshot_id: String,
165    #[serde(deserialize_with = "crate::serialization::required_option")]
166    pub module_hash: Option<String>,
167    #[serde(deserialize_with = "crate::serialization::required_option")]
168    pub code_version: Option<String>,
169    pub artifact_path: String,
170    pub checksum_algorithm: String,
171    #[serde(deserialize_with = "crate::serialization::required_option")]
172    pub checksum: Option<String>,
173}
174
175///
176/// VerificationPlan
177///
178/// Deployment and member verification checks required for a backup bundle.
179/// Owned by backup manifest contracts and consumed by restore validation.
180///
181
182#[derive(Clone, Debug, Default, Deserialize, Serialize)]
183#[serde(deny_unknown_fields)]
184pub struct VerificationPlan {
185    pub deployment_checks: Vec<VerificationCheck>,
186    pub member_checks: Vec<MemberVerificationChecks>,
187}
188
189///
190/// MemberVerificationChecks
191///
192/// Verification checks scoped to one deployment role.
193/// Owned by backup manifest contracts and validated against deployment members.
194///
195
196#[derive(Clone, Debug, Deserialize, Serialize)]
197#[serde(deny_unknown_fields)]
198pub struct MemberVerificationChecks {
199    pub role: String,
200    pub checks: Vec<VerificationCheck>,
201}
202
203///
204/// VerificationCheck
205///
206/// Named verification check and the deployment roles it covers.
207/// Owned by backup manifest contracts and interpreted by validators.
208///
209
210#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
211#[serde(deny_unknown_fields)]
212pub struct VerificationCheck {
213    pub kind: String,
214    pub roles: Vec<String>,
215}
216
217/// Stable manifest label for the supported canister-status verification.
218pub const VERIFICATION_KIND_STATUS: &str = "status";