Skip to main content

canic_host/deployment_truth/model/promotion/policy/
mod.rs

1use super::super::SafetyFindingV1;
2use super::source::{PromotionArtifactLevelV1, PromotionReadinessStatusV1};
3use serde::{Deserialize, Serialize};
4
5///
6/// RolePromotionPolicyV1
7///
8#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
9pub struct RolePromotionPolicyV1 {
10    pub role: String,
11    pub allowed_promotion_levels: Vec<PromotionArtifactLevelV1>,
12    pub requirements: Vec<PromotionPolicyRequirementV1>,
13}
14
15///
16/// PromotionPolicyRequirementV1
17///
18#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
19pub enum PromotionPolicyRequirementV1 {
20    SameSourceRevision,
21    SameCargoFeatures,
22    TargetConfigDigest,
23    ByteIdenticalWasm,
24    SealedBytes,
25}
26
27impl PromotionPolicyRequirementV1 {
28    #[must_use]
29    pub const fn label(self) -> &'static str {
30        match self {
31            Self::SameSourceRevision => "SameSourceRevision",
32            Self::SameCargoFeatures => "SameCargoFeatures",
33            Self::TargetConfigDigest => "TargetConfigDigest",
34            Self::ByteIdenticalWasm => "ByteIdenticalWasm",
35            Self::SealedBytes => "SealedBytes",
36        }
37    }
38}
39
40///
41/// PromotionPolicyClaimV1
42///
43#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
44pub enum PromotionPolicyClaimV1 {
45    ByteIdenticalWasm,
46    TargetConfigDigest,
47}
48
49impl PromotionPolicyClaimV1 {
50    #[must_use]
51    pub const fn label(self) -> &'static str {
52        match self {
53            Self::ByteIdenticalWasm => "ByteIdenticalWasm",
54            Self::TargetConfigDigest => "TargetConfigDigest",
55        }
56    }
57}
58
59///
60/// PromotionPolicyCheckV1
61///
62#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
63pub struct PromotionPolicyCheckV1 {
64    pub schema_version: u32,
65    pub check_id: String,
66    pub promotion_policy_check_digest: String,
67    pub status: PromotionReadinessStatusV1,
68    pub roles: Vec<RolePromotionPolicyDecisionV1>,
69    pub blockers: Vec<SafetyFindingV1>,
70}
71
72///
73/// RolePromotionPolicyDecisionV1
74///
75#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
76pub struct RolePromotionPolicyDecisionV1 {
77    pub role: String,
78    pub requested_promotion_level: PromotionArtifactLevelV1,
79    pub allowed_promotion_levels: Vec<PromotionArtifactLevelV1>,
80    pub requirements: Vec<PromotionPolicyRequirementV1>,
81    pub claims: Vec<PromotionPolicyClaimV1>,
82    pub level_allowed: bool,
83    pub policy_satisfied: bool,
84}
85
86#[cfg(test)]
87mod tests {
88    use super::*;
89
90    #[test]
91    fn promotion_policy_requirement_owns_text_labels() {
92        assert_eq!(
93            PromotionPolicyRequirementV1::SameSourceRevision.label(),
94            "SameSourceRevision"
95        );
96        assert_eq!(
97            PromotionPolicyRequirementV1::SameCargoFeatures.label(),
98            "SameCargoFeatures"
99        );
100        assert_eq!(
101            PromotionPolicyRequirementV1::TargetConfigDigest.label(),
102            "TargetConfigDigest"
103        );
104        assert_eq!(
105            PromotionPolicyRequirementV1::ByteIdenticalWasm.label(),
106            "ByteIdenticalWasm"
107        );
108        assert_eq!(
109            PromotionPolicyRequirementV1::SealedBytes.label(),
110            "SealedBytes"
111        );
112    }
113
114    #[test]
115    fn promotion_policy_claim_owns_text_labels() {
116        assert_eq!(
117            PromotionPolicyClaimV1::ByteIdenticalWasm.label(),
118            "ByteIdenticalWasm"
119        );
120        assert_eq!(
121            PromotionPolicyClaimV1::TargetConfigDigest.label(),
122            "TargetConfigDigest"
123        );
124    }
125}