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    pub parent_canister_id: Option<String>,
130    pub subnet_canister_id: Option<String>,
131    pub controller_hint: Option<String>,
132    pub identity_mode: IdentityMode,
133    pub verification_checks: Vec<VerificationCheck>,
134    pub source_snapshot: SourceSnapshot,
135}
136
137///
138/// IdentityMode
139///
140/// Restore identity policy for one deployment member.
141/// Owned by backup manifest contracts and enforced during restore planning.
142///
143
144#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
145#[serde(rename_all = "kebab-case")]
146pub enum IdentityMode {
147    Fixed,
148    Relocatable,
149}
150
151///
152/// SourceSnapshot
153///
154/// Snapshot artifact metadata for one deployment member.
155/// Owned by backup manifest contracts and validated before restore execution.
156///
157
158#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
159#[serde(deny_unknown_fields)]
160pub struct SourceSnapshot {
161    pub snapshot_id: String,
162    pub module_hash: Option<String>,
163    pub code_version: Option<String>,
164    pub artifact_path: String,
165    pub checksum_algorithm: String,
166    #[serde(default)]
167    pub checksum: Option<String>,
168}
169
170///
171/// VerificationPlan
172///
173/// Deployment and member verification checks required for a backup bundle.
174/// Owned by backup manifest contracts and consumed by restore validation.
175///
176
177#[derive(Clone, Debug, Default, Deserialize, Serialize)]
178#[serde(deny_unknown_fields)]
179pub struct VerificationPlan {
180    pub deployment_checks: Vec<VerificationCheck>,
181    pub member_checks: Vec<MemberVerificationChecks>,
182}
183
184///
185/// MemberVerificationChecks
186///
187/// Verification checks scoped to one deployment role.
188/// Owned by backup manifest contracts and validated against deployment members.
189///
190
191#[derive(Clone, Debug, Deserialize, Serialize)]
192#[serde(deny_unknown_fields)]
193pub struct MemberVerificationChecks {
194    pub role: String,
195    pub checks: Vec<VerificationCheck>,
196}
197
198///
199/// VerificationCheck
200///
201/// Named verification check and the deployment roles it covers.
202/// Owned by backup manifest contracts and interpreted by validators.
203///
204
205#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
206#[serde(deny_unknown_fields)]
207pub struct VerificationCheck {
208    pub kind: String,
209    pub roles: Vec<String>,
210}
211
212/// Stable manifest label for the supported canister-status verification.
213pub const VERIFICATION_KIND_STATUS: &str = "status";