xbp-oci 10.46.0

OCI registry primitives and traits for XBP deploy.
Documentation
use thiserror::Error;

pub type Result<T> = std::result::Result<T, OciError>;

#[derive(Debug, Error)]
pub enum OciError {
    #[error("invalid image reference: {0}")]
    InvalidRef(String),
    #[error("image not found: {0}")]
    NotFound(String),
    #[error("registry auth failed: {0}")]
    Auth(String),
    #[error("registry error: {0}")]
    Registry(String),
    #[error("promote refused: target tag exists (use force): {0}")]
    TargetExists(String),
    #[error("{0}")]
    Other(String),
}

impl OciError {
    pub fn from_registry_message(msg: impl AsRef<str>) -> Self {
        let msg = msg.as_ref().to_string();
        let lower = msg.to_ascii_lowercase();
        if lower.contains("404") || lower.contains("not found") {
            Self::NotFound(msg)
        } else if lower.contains("401")
            || lower.contains("403")
            || lower.contains("unauthorized")
            || lower.contains("denied")
        {
            Self::Auth(format!(
                "{msg}. Configure GH_TOKEN/GITHUB_TOKEN, xbp config oci, or --username/--token."
            ))
        } else {
            Self::Registry(msg)
        }
    }
}