atlas_cli/storage/
traits.rs1use crate::error::Error;
2use crate::error::Result;
3use atlas_c2pa_lib::manifest::Manifest;
4use serde::{Deserialize, Serialize};
5use std::any::Any;
6use std::fmt;
7use std::path::PathBuf;
8
9#[derive(Clone, Serialize, Deserialize)]
27pub struct ManifestMetadata {
28 pub id: String,
29 pub name: String,
30 pub manifest_type: ManifestType,
31 pub created_at: String,
32}
33
34pub trait StorageBackend {
35 fn get_base_uri(&self) -> String;
36 fn store_manifest(&self, manifest: &Manifest) -> Result<String>;
37 fn retrieve_manifest(&self, id: &str) -> Result<Manifest>;
38 fn list_manifests(&self) -> Result<Vec<ManifestMetadata>>;
39 fn delete_manifest(&self, id: &str) -> Result<()>;
40 fn as_any(&self) -> &dyn Any;
41}
42
43#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
44pub enum ManifestType {
45 Dataset,
46 Model,
47 Software,
48 Unknown,
49}
50
51#[derive(Clone, Serialize, Deserialize)]
81pub struct ArtifactLocation {
82 pub url: String,
83 pub file_path: Option<PathBuf>,
84 pub hash: String,
85}
86
87impl fmt::Display for ManifestType {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 match self {
90 ManifestType::Dataset => write!(f, "Dataset"),
91 ManifestType::Model => write!(f, "Model"),
92 ManifestType::Software => write!(f, "Software"),
93 ManifestType::Unknown => write!(f, "Unknown"),
94 }
95 }
96}
97
98impl ArtifactLocation {
99 pub fn new(path: PathBuf) -> Result<Self> {
100 let hash = crate::hash::calculate_file_hash(&path)?;
101 let url = format!("file://{}", path.to_string_lossy());
102
103 Ok(Self {
104 url,
105 file_path: Some(path),
106 hash,
107 })
108 }
109
110 pub fn verify(&self) -> Result<bool> {
111 match &self.file_path {
112 Some(path) => {
113 let current_hash = crate::hash::calculate_file_hash(path)?;
114 Ok(current_hash == self.hash)
115 }
116 None => Err(Error::Validation(
117 "No file path available for verification".to_string(),
118 )),
119 }
120 }
121}