canic-backup 0.69.3

Manifest and orchestration primitives for Canic deployment backup and restore
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
//! Module: plan::types
//!
//! Responsibility: define serialized backup plan and preflight contracts.
//! Does not own: registry discovery, validation, execution, or persistence.
//! Boundary: data shapes shared by backup planners, runners, and preflights.

use crate::manifest::IdentityMode;

use serde::{Deserialize, Serialize};

///
/// BackupPlan
///
/// Executable backup plan derived from a selected deployment scope.
/// Owned by backup planning and consumed by execution journals and runners.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BackupPlan {
    pub plan_id: String,
    pub run_id: String,
    pub fleet: String,
    pub network: String,
    pub root_canister_id: String,
    pub selected_subtree_root: Option<String>,
    pub selected_scope_kind: BackupScopeKind,
    pub include_descendants: bool,
    pub root_included: bool,
    pub requires_root_controller: bool,
    pub snapshot_read_authority: SnapshotReadAuthority,
    pub quiescence_policy: QuiescencePolicy,
    pub topology_hash_before_quiesce: String,
    pub targets: Vec<BackupTarget>,
    pub phases: Vec<BackupOperation>,
}

///
/// BackupScopeKind
///
/// Backup selection mode used to derive target and operation scope.
/// Owned by backup planning and serialized into plan and preflight contracts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum BackupScopeKind {
    Member,
    Subtree,
    NonRootDeployment,
    MaintenanceRoot,
}

///
/// BackupTarget
///
/// One canister selected for backup with authority and restore policy.
/// Owned by backup planning and used by preflight and execution builders.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BackupTarget {
    pub canister_id: String,
    pub role: Option<String>,
    pub parent_canister_id: Option<String>,
    pub depth: u32,
    pub control_authority: ControlAuthority,
    pub snapshot_read_authority: SnapshotReadAuthority,
    pub identity_mode: IdentityMode,
    pub expected_module_hash: Option<String>,
}

///
/// AuthorityEvidence
///
/// Confidence level for an authority decision embedded in a backup plan.
/// Owned by backup planning and refined by execution preflight receipts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum AuthorityEvidence {
    Proven,
    Declared,
    Unknown,
}

///
/// ControlAuthority
///
/// Control authority decision for one selected backup target.
/// Owned by backup planning and validated before mutation execution.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ControlAuthority {
    pub source: ControlAuthoritySource,
    pub evidence: AuthorityEvidence,
}

impl ControlAuthority {
    #[must_use]
    pub const fn unknown() -> Self {
        Self {
            source: ControlAuthoritySource::Unknown,
            evidence: AuthorityEvidence::Unknown,
        }
    }

    #[must_use]
    pub const fn root_controller(evidence: AuthorityEvidence) -> Self {
        Self {
            source: ControlAuthoritySource::RootController,
            evidence,
        }
    }

    #[must_use]
    pub const fn operator_controller(evidence: AuthorityEvidence) -> Self {
        Self {
            source: ControlAuthoritySource::OperatorController,
            evidence,
        }
    }

    #[must_use]
    pub fn alternate_controller(
        controller: impl Into<String>,
        reason: impl Into<String>,
        evidence: AuthorityEvidence,
    ) -> Self {
        Self {
            source: ControlAuthoritySource::AlternateController {
                controller: controller.into(),
                reason: reason.into(),
            },
            evidence,
        }
    }

    #[must_use]
    pub fn is_proven(&self) -> bool {
        self.evidence == AuthorityEvidence::Proven && self.source != ControlAuthoritySource::Unknown
    }

    #[must_use]
    pub fn is_proven_root_controller(&self) -> bool {
        self.evidence == AuthorityEvidence::Proven
            && self.source == ControlAuthoritySource::RootController
    }
}

///
/// ControlAuthoritySource
///
/// Source of a control authority decision for one backup target.
/// Owned by backup planning and interpreted by preflight validation.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case", tag = "kind")]
pub enum ControlAuthoritySource {
    Unknown,
    RootController,
    OperatorController,
    AlternateController { controller: String, reason: String },
}

///
/// SnapshotReadAuthority
///
/// Snapshot read authority decision for one selected backup target.
/// Owned by backup planning and validated before snapshot download.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SnapshotReadAuthority {
    pub source: SnapshotReadAuthoritySource,
    pub evidence: AuthorityEvidence,
}

impl SnapshotReadAuthority {
    #[must_use]
    pub const fn unknown() -> Self {
        Self {
            source: SnapshotReadAuthoritySource::Unknown,
            evidence: AuthorityEvidence::Unknown,
        }
    }

    #[must_use]
    pub const fn operator_controller(evidence: AuthorityEvidence) -> Self {
        Self {
            source: SnapshotReadAuthoritySource::OperatorController,
            evidence,
        }
    }

    #[must_use]
    pub const fn snapshot_visibility(evidence: AuthorityEvidence) -> Self {
        Self {
            source: SnapshotReadAuthoritySource::SnapshotVisibility,
            evidence,
        }
    }

    #[must_use]
    pub const fn root_configured_read(evidence: AuthorityEvidence) -> Self {
        Self {
            source: SnapshotReadAuthoritySource::RootConfiguredRead,
            evidence,
        }
    }

    #[must_use]
    pub const fn root_mediated_transfer(evidence: AuthorityEvidence) -> Self {
        Self {
            source: SnapshotReadAuthoritySource::RootMediatedTransfer,
            evidence,
        }
    }

    #[must_use]
    pub fn is_proven(&self) -> bool {
        self.evidence == AuthorityEvidence::Proven
            && self.source != SnapshotReadAuthoritySource::Unknown
    }
}

///
/// SnapshotReadAuthoritySource
///
/// Source of a snapshot-read authority decision for one backup target.
/// Owned by backup planning and interpreted by preflight validation.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum SnapshotReadAuthoritySource {
    Unknown,
    OperatorController,
    SnapshotVisibility,
    RootConfiguredRead,
    RootMediatedTransfer,
}

///
/// QuiescencePolicy
///
/// Consistency policy requested before backup mutation begins.
/// Owned by backup planning and checked by execution preflight receipts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum QuiescencePolicy {
    CrashConsistent,
    RootCoordinated,
    AppQuiesced,
}

///
/// BackupOperation
///
/// Ordered operation generated for one backup plan.
/// Owned by backup planning and converted into execution journal operations.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BackupOperation {
    pub operation_id: String,
    pub order: u32,
    pub kind: BackupOperationKind,
    pub target_canister_id: Option<String>,
}

///
/// BackupOperationKind
///
/// Operation class used by backup execution and preflight validation.
/// Owned by backup planning and interpreted by execution journals.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum BackupOperationKind {
    ValidateTopology,
    ValidateControlAuthority,
    ValidateSnapshotReadAuthority,
    ValidateQuiescencePolicy,
    Stop,
    CreateSnapshot,
    Start,
    DownloadSnapshot,
    VerifyArtifact,
    FinalizeManifest,
}

///
/// BackupReceipt
///
/// Legacy per-operation backup receipt retained for plan-facing contracts.
/// Owned by backup planning and superseded by execution operation receipts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BackupReceipt {
    pub plan_id: String,
    pub operation_id: String,
    pub status: BackupReceiptStatus,
    pub target_canister_id: Option<String>,
    pub snapshot_id: Option<String>,
    pub message: Option<String>,
}

///
/// BackupReceiptStatus
///
/// Terminal status for a plan-facing backup receipt.
/// Owned by backup planning and serialized with legacy receipt contracts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum BackupReceiptStatus {
    Completed,
    Failed,
    Skipped,
}

///
/// BackupExecutionPreflightReceipts
///
/// Complete preflight receipt bundle required before backup mutation.
/// Owned by backup planning and consumed by execution journals.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BackupExecutionPreflightReceipts {
    pub plan_id: String,
    pub preflight_id: String,
    pub validated_at: String,
    pub expires_at: String,
    pub topology: TopologyPreflightReceipt,
    pub control_authority: Vec<ControlAuthorityReceipt>,
    pub snapshot_read_authority: Vec<SnapshotReadAuthorityReceipt>,
    pub quiescence: QuiescencePreflightReceipt,
}

///
/// ControlAuthorityReceipt
///
/// Control authority preflight result for one selected backup target.
/// Owned by backup planning and applied before execution can mutate targets.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ControlAuthorityReceipt {
    pub plan_id: String,
    pub preflight_id: String,
    pub target_canister_id: String,
    pub authority: ControlAuthority,
    pub proof_source: AuthorityProofSource,
    pub validated_at: String,
    pub expires_at: String,
    pub message: Option<String>,
}

///
/// SnapshotReadAuthorityReceipt
///
/// Snapshot-read authority preflight result for one selected backup target.
/// Owned by backup planning and applied before snapshot download can run.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SnapshotReadAuthorityReceipt {
    pub plan_id: String,
    pub preflight_id: String,
    pub target_canister_id: String,
    pub authority: SnapshotReadAuthority,
    pub proof_source: AuthorityProofSource,
    pub validated_at: String,
    pub expires_at: String,
    pub message: Option<String>,
}

///
/// AuthorityProofSource
///
/// Evidence source used by an authority preflight receipt.
/// Owned by backup planning and serialized with authority receipt contracts.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum AuthorityProofSource {
    RootCoordination,
    ManagementStatus,
    SnapshotReadCheck,
    Declaration,
    Unknown,
}

///
/// ControlAuthorityPreflightRequest
///
/// Request shape for proving control authority over selected targets.
/// Owned by backup planning and sent to execution preflight providers.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ControlAuthorityPreflightRequest {
    pub plan_id: String,
    pub run_id: String,
    pub fleet: String,
    pub network: String,
    pub root_canister_id: String,
    pub requires_root_controller: bool,
    pub targets: Vec<ControlAuthorityPreflightTarget>,
}

///
/// ControlAuthorityPreflightTarget
///
/// Target row included in a control-authority preflight request.
/// Owned by backup planning and projected from selected backup targets.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ControlAuthorityPreflightTarget {
    pub canister_id: String,
    pub role: Option<String>,
    pub parent_canister_id: Option<String>,
    pub declared_authority: ControlAuthority,
}

impl From<&BackupTarget> for ControlAuthorityPreflightTarget {
    fn from(target: &BackupTarget) -> Self {
        Self {
            canister_id: target.canister_id.clone(),
            role: target.role.clone(),
            parent_canister_id: target.parent_canister_id.clone(),
            declared_authority: target.control_authority.clone(),
        }
    }
}

///
/// SnapshotReadAuthorityPreflightRequest
///
/// Request shape for proving snapshot read authority over selected targets.
/// Owned by backup planning and sent to execution preflight providers.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SnapshotReadAuthorityPreflightRequest {
    pub plan_id: String,
    pub run_id: String,
    pub fleet: String,
    pub network: String,
    pub root_canister_id: String,
    pub targets: Vec<SnapshotReadAuthorityPreflightTarget>,
}

///
/// SnapshotReadAuthorityPreflightTarget
///
/// Target row included in a snapshot-read preflight request.
/// Owned by backup planning and projected from selected backup targets.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SnapshotReadAuthorityPreflightTarget {
    pub canister_id: String,
    pub role: Option<String>,
    pub parent_canister_id: Option<String>,
    pub declared_authority: SnapshotReadAuthority,
}

impl From<&BackupTarget> for SnapshotReadAuthorityPreflightTarget {
    fn from(target: &BackupTarget) -> Self {
        Self {
            canister_id: target.canister_id.clone(),
            role: target.role.clone(),
            parent_canister_id: target.parent_canister_id.clone(),
            declared_authority: target.snapshot_read_authority.clone(),
        }
    }
}

///
/// TopologyPreflightRequest
///
/// Request shape for confirming selected topology before mutation.
/// Owned by backup planning and sent to execution preflight providers.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TopologyPreflightRequest {
    pub plan_id: String,
    pub run_id: String,
    pub fleet: String,
    pub network: String,
    pub root_canister_id: String,
    pub selected_subtree_root: Option<String>,
    pub selected_scope_kind: BackupScopeKind,
    pub topology_hash_before_quiesce: String,
    pub targets: Vec<TopologyPreflightTarget>,
}

///
/// TopologyPreflightTarget
///
/// Target row included in a topology preflight request and receipt.
/// Owned by backup planning and projected from selected backup targets.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TopologyPreflightTarget {
    pub canister_id: String,
    pub parent_canister_id: Option<String>,
    pub depth: u32,
}

impl From<&BackupTarget> for TopologyPreflightTarget {
    fn from(target: &BackupTarget) -> Self {
        Self {
            canister_id: target.canister_id.clone(),
            parent_canister_id: target.parent_canister_id.clone(),
            depth: target.depth,
        }
    }
}

///
/// TopologyPreflightReceipt
///
/// Topology preflight result accepted before backup mutation begins.
/// Owned by backup planning and checked against the selected plan.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TopologyPreflightReceipt {
    pub plan_id: String,
    pub preflight_id: String,
    pub topology_hash_before_quiesce: String,
    pub topology_hash_at_preflight: String,
    pub targets: Vec<TopologyPreflightTarget>,
    pub validated_at: String,
    pub expires_at: String,
    pub message: Option<String>,
}

///
/// QuiescencePreflightRequest
///
/// Request shape for confirming the selected quiescence policy.
/// Owned by backup planning and sent to execution preflight providers.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct QuiescencePreflightRequest {
    pub plan_id: String,
    pub run_id: String,
    pub fleet: String,
    pub network: String,
    pub root_canister_id: String,
    pub selected_subtree_root: Option<String>,
    pub quiescence_policy: QuiescencePolicy,
    pub targets: Vec<QuiescencePreflightTarget>,
}

///
/// QuiescencePreflightTarget
///
/// Target row included in a quiescence preflight request and receipt.
/// Owned by backup planning and projected from selected backup targets.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct QuiescencePreflightTarget {
    pub canister_id: String,
    pub role: Option<String>,
    pub parent_canister_id: Option<String>,
}

impl From<&BackupTarget> for QuiescencePreflightTarget {
    fn from(target: &BackupTarget) -> Self {
        Self {
            canister_id: target.canister_id.clone(),
            role: target.role.clone(),
            parent_canister_id: target.parent_canister_id.clone(),
        }
    }
}

///
/// QuiescencePreflightReceipt
///
/// Quiescence preflight result accepted before backup mutation begins.
/// Owned by backup planning and checked against the selected plan.
///

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct QuiescencePreflightReceipt {
    pub plan_id: String,
    pub preflight_id: String,
    pub quiescence_policy: QuiescencePolicy,
    pub accepted: bool,
    pub targets: Vec<QuiescencePreflightTarget>,
    pub validated_at: String,
    pub expires_at: String,
    pub message: Option<String>,
}