use alloc::string::String;
use alloc::vec::Vec;
#[cfg(feature = "schemars")]
use schemars::JsonSchema;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{SecretRequirement, TenantCtx};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct DistributorEnvironmentId(pub String);
impl DistributorEnvironmentId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<String> for DistributorEnvironmentId {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<&str> for DistributorEnvironmentId {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ComponentDigest(pub String);
impl ComponentDigest {
pub fn as_str(&self) -> &str {
&self.0
}
pub fn is_sha256_like(&self) -> bool {
const PREFIX: &str = "sha256:";
let s = self.0.as_str();
if !s.starts_with(PREFIX) {
return false;
}
let rest = &s[PREFIX.len()..];
if rest.len() != 64 {
return false;
}
rest.chars()
.all(|c| c.is_ascii_hexdigit() && c.is_ascii_lowercase() || c.is_ascii_digit())
}
}
impl From<String> for ComponentDigest {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<&str> for ComponentDigest {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum ComponentStatus {
Pending,
Ready,
Failed {
reason: String,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[cfg_attr(feature = "serde", serde(tag = "kind", rename_all = "snake_case"))]
pub enum ArtifactLocation {
FilePath {
path: String,
},
OciReference {
reference: String,
},
DistributorInternal {
handle: String,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct SignatureSummary {
pub verified: bool,
pub signer: String,
pub extra: Value,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct CacheInfo {
pub size_bytes: u64,
pub last_used_utc: String,
pub last_refreshed_utc: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ResolveComponentRequest {
pub tenant: TenantCtx,
pub environment_id: DistributorEnvironmentId,
pub pack_id: String,
pub component_id: String,
pub version: String,
pub extra: Value,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ResolveComponentResponse {
pub status: ComponentStatus,
pub digest: ComponentDigest,
pub artifact: ArtifactLocation,
pub signature: SignatureSummary,
pub cache: CacheInfo,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub secret_requirements: Option<Vec<SecretRequirement>>,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct PackStatusResponseV2 {
pub status: Value,
#[cfg_attr(
feature = "serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub secret_requirements: Option<Vec<SecretRequirement>>,
}