Skip to main content

canic_host/deployment_truth/model/artifact/
mod.rs

1use super::inventory::DeploymentObservationGapV1;
2use serde::{Deserialize, Serialize};
3
4///
5/// RoleArtifactManifestV1
6///
7#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
8pub struct RoleArtifactManifestV1 {
9    pub schema_version: u32,
10    pub manifest_id: String,
11    pub network: String,
12    pub artifact_root: Option<String>,
13    pub role_artifacts: Vec<RoleArtifactV1>,
14    pub unresolved_artifacts: Vec<DeploymentObservationGapV1>,
15}
16
17///
18/// RoleArtifactV1
19///
20#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
21pub struct RoleArtifactV1 {
22    pub role: String,
23    pub source: ArtifactSourceV1,
24    pub build_profile: String,
25    pub wasm_path: Option<String>,
26    pub wasm_gz_path: Option<String>,
27    pub wasm_gz_size_bytes: Option<u64>,
28    pub wasm_sha256: Option<String>,
29    pub wasm_gz_sha256: Option<String>,
30    pub wasm_gz_sha256_source: Option<ArtifactDigestSourceV1>,
31    pub observed_wasm_gz_file_sha256: Option<String>,
32    pub observed_wasm_gz_file_sha256_source: Option<ArtifactDigestSourceV1>,
33    pub installed_module_hash: Option<String>,
34    pub candid_path: Option<String>,
35    pub candid_sha256: Option<String>,
36    pub raw_config_sha256: Option<String>,
37    pub canonical_embedded_config_sha256: Option<String>,
38    pub embedded_topology_sha256: Option<String>,
39    pub builder_version: Option<String>,
40    pub rust_toolchain: Option<String>,
41    pub package_version: Option<String>,
42}
43
44///
45/// ArtifactDigestSourceV1
46///
47#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
48pub enum ArtifactDigestSourceV1 {
49    ReleaseSetManifest,
50    ObservedFileDigest,
51    InstalledModuleHash,
52}
53
54///
55/// ArtifactSourceV1
56///
57#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
58pub enum ArtifactSourceV1 {
59    LocalBuild,
60    ReleaseSet,
61    WasmStore,
62    External,
63    Unknown,
64}
65
66impl ArtifactSourceV1 {
67    #[must_use]
68    pub const fn label(self) -> &'static str {
69        match self {
70            Self::LocalBuild => "LocalBuild",
71            Self::ReleaseSet => "ReleaseSet",
72            Self::WasmStore => "WasmStore",
73            Self::External => "External",
74            Self::Unknown => "Unknown",
75        }
76    }
77}
78
79///
80/// ObservedArtifactV1
81///
82#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
83pub struct ObservedArtifactV1 {
84    pub role: String,
85    pub artifact_path: String,
86    pub file_sha256: Option<String>,
87    pub file_sha256_source: Option<ArtifactDigestSourceV1>,
88    pub payload_sha256: Option<String>,
89    pub payload_size_bytes: Option<u64>,
90    pub source: ArtifactSourceV1,
91}
92
93#[cfg(test)]
94mod tests {
95    use super::*;
96
97    #[test]
98    fn artifact_source_owns_text_labels() {
99        assert_eq!(ArtifactSourceV1::LocalBuild.label(), "LocalBuild");
100        assert_eq!(ArtifactSourceV1::ReleaseSet.label(), "ReleaseSet");
101        assert_eq!(ArtifactSourceV1::WasmStore.label(), "WasmStore");
102        assert_eq!(ArtifactSourceV1::External.label(), "External");
103        assert_eq!(ArtifactSourceV1::Unknown.label(), "Unknown");
104    }
105}