ic_backup/model/operation_plan/context/
mod.rs1use super::{OperationPlanError, canonical_hash};
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug)]
8pub struct PlanContextRequest {
9 pub network: String,
11 pub caller: String,
13 pub release: String,
15}
16#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
18#[serde(try_from = "ContextFields")]
19pub struct PlanContextRecord {
20 network: String,
21 caller: String,
22 release: String,
23}
24#[derive(Deserialize)]
25#[serde(deny_unknown_fields)]
26struct ContextFields {
27 network: String,
28 caller: String,
29 release: String,
30}
31impl TryFrom<ContextFields> for PlanContextRecord {
32 type Error = OperationPlanError;
33 fn try_from(fields: ContextFields) -> Result<Self, Self::Error> {
34 Self::new(&PlanContextRequest {
35 network: fields.network,
36 caller: fields.caller,
37 release: fields.release,
38 })
39 }
40}
41impl PlanContextRecord {
42 pub fn new(request: &PlanContextRequest) -> Result<Self, OperationPlanError> {
47 Ok(Self {
48 network: canonical_hash(&request.network)?,
49 caller: crate::model::principal::canonical_text(&request.caller)
50 .ok_or(OperationPlanError::InvalidPrincipal("caller"))?,
51 release: canonical_hash(&request.release)?,
52 })
53 }
54 #[must_use]
56 pub fn network(&self) -> &str {
57 &self.network
58 }
59 #[must_use]
61 pub fn caller(&self) -> &str {
62 &self.caller
63 }
64 #[must_use]
66 pub fn release(&self) -> &str {
67 &self.release
68 }
69}