Skip to main content

canic_host/deployment_truth/model/lifecycle/proposal/
mod.rs

1use super::super::CanisterControlClassV1;
2use super::authority::{
3    ConsentRequirementV1, ExternalUpgradeAuthorizationModeV1, LifecycleModeV1,
4    LifecycleVerificationRequirementV1,
5};
6use serde::{Deserialize, Serialize};
7
8///
9/// ExternalUpgradeProposalV1
10///
11#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
12pub struct ExternalUpgradeProposalV1 {
13    pub proposal_id: String,
14    pub proposal_digest: String,
15    pub deployment_plan_id: String,
16    pub deployment_plan_digest: String,
17    pub lifecycle_plan_id: String,
18    pub lifecycle_plan_digest: String,
19    pub promotion_plan_id: Option<String>,
20    pub promotion_plan_digest: Option<String>,
21    pub promotion_provenance_id: Option<String>,
22    pub promotion_provenance_digest: Option<String>,
23    pub subject: String,
24    pub canister_id: Option<String>,
25    pub role: Option<String>,
26    pub control_class: CanisterControlClassV1,
27    pub lifecycle_mode: LifecycleModeV1,
28    pub observed_before_digest: String,
29    pub current_module_hash: Option<String>,
30    pub current_canonical_embedded_config_sha256: Option<String>,
31    pub target_wasm_sha256: Option<String>,
32    pub target_wasm_gz_sha256: Option<String>,
33    pub target_installed_module_hash: Option<String>,
34    pub target_role_artifact_identity: Option<String>,
35    pub target_canonical_embedded_config_sha256: Option<String>,
36    pub root_trust_anchor: Option<String>,
37    pub authority_profile_hash: Option<String>,
38    pub required_external_action: String,
39    pub consent_requirements: Vec<ConsentRequirementV1>,
40    pub allowed_authorization_modes: Vec<ExternalUpgradeAuthorizationModeV1>,
41    pub verification_requirements: Vec<LifecycleVerificationRequirementV1>,
42    pub expires_at: Option<String>,
43    pub supersedes_proposal_id: Option<String>,
44}
45
46///
47/// ExternalUpgradeReceiptV1
48///
49#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
50pub struct ExternalUpgradeReceiptV1 {
51    pub schema_version: u32,
52    pub receipt_id: String,
53    pub proposal_id: String,
54    pub proposal_digest: String,
55    pub subject: String,
56    pub canister_id: Option<String>,
57    pub role: Option<String>,
58    pub consent_state: ExternalUpgradeConsentStateV1,
59    pub reported_by: Option<String>,
60    pub observed_before_module_hash: Option<String>,
61    pub observed_after_module_hash: Option<String>,
62    pub observed_after_canonical_embedded_config_sha256: Option<String>,
63    pub verification_result: ExternalUpgradeVerificationResultV1,
64    pub verification_notes: Vec<String>,
65    pub receipt_digest: String,
66}
67
68///
69/// ExternalUpgradeConsentEvidenceV1
70///
71#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
72pub struct ExternalUpgradeConsentEvidenceV1 {
73    pub schema_version: u32,
74    pub evidence_id: String,
75    pub evidence_digest: String,
76    pub proposal_id: String,
77    pub proposal_digest: String,
78    pub receipt_id: String,
79    pub receipt_digest: String,
80    pub subject: String,
81    pub canister_id: Option<String>,
82    pub role: Option<String>,
83    pub consent_state: ExternalUpgradeConsentStateV1,
84    pub reported_by: Option<String>,
85    pub consent_requirements: Vec<ConsentRequirementV1>,
86    pub allowed_authorization_modes: Vec<ExternalUpgradeAuthorizationModeV1>,
87    pub status_summary: String,
88}
89
90///
91/// ExternalUpgradeConsentEvidenceRequest
92///
93#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
94pub struct ExternalUpgradeConsentEvidenceRequest {
95    pub evidence_id: String,
96    pub proposal: ExternalUpgradeProposalV1,
97    pub receipt: ExternalUpgradeReceiptV1,
98}
99
100///
101/// ExternalUpgradeConsentStateV1
102///
103#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
104pub enum ExternalUpgradeConsentStateV1 {
105    Pending,
106    Refused,
107    Delegated,
108    ExecutedExternally,
109}
110
111impl ExternalUpgradeConsentStateV1 {
112    #[must_use]
113    pub const fn label(self) -> &'static str {
114        match self {
115            Self::Pending => "pending",
116            Self::Refused => "refused",
117            Self::Delegated => "delegated",
118            Self::ExecutedExternally => "executed_externally",
119        }
120    }
121}
122
123///
124/// ExternalUpgradeVerificationResultV1
125///
126#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
127pub enum ExternalUpgradeVerificationResultV1 {
128    Pending,
129    Refused,
130    Verified,
131    Mismatch,
132}
133
134impl ExternalUpgradeVerificationResultV1 {
135    #[must_use]
136    pub const fn label(self) -> &'static str {
137        match self {
138            Self::Pending => "pending",
139            Self::Refused => "refused",
140            Self::Verified => "verified",
141            Self::Mismatch => "mismatch",
142        }
143    }
144}
145
146#[cfg(test)]
147mod tests {
148    use super::*;
149
150    #[test]
151    fn external_upgrade_consent_state_owns_text_labels() {
152        assert_eq!(ExternalUpgradeConsentStateV1::Pending.label(), "pending");
153        assert_eq!(ExternalUpgradeConsentStateV1::Refused.label(), "refused");
154        assert_eq!(
155            ExternalUpgradeConsentStateV1::Delegated.label(),
156            "delegated"
157        );
158        assert_eq!(
159            ExternalUpgradeConsentStateV1::ExecutedExternally.label(),
160            "executed_externally"
161        );
162    }
163
164    #[test]
165    fn external_upgrade_verification_result_owns_text_labels() {
166        assert_eq!(
167            ExternalUpgradeVerificationResultV1::Pending.label(),
168            "pending"
169        );
170        assert_eq!(
171            ExternalUpgradeVerificationResultV1::Refused.label(),
172            "refused"
173        );
174        assert_eq!(
175            ExternalUpgradeVerificationResultV1::Verified.label(),
176            "verified"
177        );
178        assert_eq!(
179            ExternalUpgradeVerificationResultV1::Mismatch.label(),
180            "mismatch"
181        );
182    }
183}