Skip to main content

auths_sdk/ports/
artifact.rs

1//! Artifact source port for computing digests and metadata.
2//!
3//! Abstracts artifact access so implementations can read from files,
4//! S3, network sockets, or in-memory buffers.
5
6use serde::{Deserialize, Serialize};
7
8/// Content-addressed digest of an artifact.
9///
10/// Usage:
11/// ```ignore
12/// let digest = ArtifactDigest {
13///     algorithm: DigestAlgorithm::Sha256,
14///     hex: "b94d27b9...".to_string(),
15/// };
16/// ```
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
18pub struct ArtifactDigest {
19    /// The hash algorithm used (e.g. `"sha256"`).
20    pub algorithm: String,
21    /// The hex-encoded digest value.
22    pub hex: String,
23}
24
25/// Metadata describing an artifact.
26///
27/// Usage:
28/// ```ignore
29/// let meta = ArtifactMetadata {
30///     artifact_type: "file".to_string(),
31///     digest: digest.clone(),
32///     name: Some("release.tar.gz".to_string()),
33///     size: Some(1024),
34/// };
35/// ```
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct ArtifactMetadata {
38    /// The artifact type name (e.g. `"file"`, `"container"`).
39    pub artifact_type: String,
40    /// Content-addressed digest of the artifact.
41    pub digest: ArtifactDigest,
42    /// Optional human-readable name of the artifact.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub name: Option<String>,
45    /// Optional size in bytes.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub size: Option<u64>,
48}
49
50/// Errors from artifact operations.
51#[derive(Debug, thiserror::Error)]
52pub enum ArtifactError {
53    /// An I/O error occurred reading the artifact.
54    #[error("IO error reading artifact: {0}")]
55    Io(String),
56    /// Artifact metadata could not be retrieved.
57    #[error("metadata unavailable: {0}")]
58    Metadata(String),
59}
60
61/// Port for computing artifact digests and metadata.
62///
63/// Usage:
64/// ```ignore
65/// let digest = source.digest()?;
66/// let meta = source.metadata()?;
67/// ```
68pub trait ArtifactSource: Send + Sync {
69    /// Compute the content-addressed digest of the artifact.
70    fn digest(&self) -> Result<ArtifactDigest, ArtifactError>;
71
72    /// Retrieve metadata about the artifact.
73    fn metadata(&self) -> Result<ArtifactMetadata, ArtifactError>;
74}