Skip to main content

hanzo_client/apis/
sbom_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_sbom_health`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetSbomHealthError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`post_sbom`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostSbomError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Health is a pure liveness probe: the service is up; datastore reflects whether the datastore store is connected. Not JWT-gated, always 200 (a disconnected datastore is degraded-but-alive; the data endpoints report that as 503).
34pub async fn get_sbom_health(configuration: &configuration::Configuration, ) -> Result<models::SbomHealth, Error<GetSbomHealthError>> {
35
36    let uri_str = format!("{}/v1/sbom/health", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(ref token) = configuration.bearer_access_token {
43        req_builder = req_builder.bearer_auth(token.to_owned());
44    };
45
46    let req = req_builder.build()?;
47    let resp = configuration.client.execute(req).await?;
48
49    let status = resp.status();
50    let content_type = resp
51        .headers()
52        .get("content-type")
53        .and_then(|v| v.to_str().ok())
54        .unwrap_or("application/octet-stream");
55    let content_type = super::ContentType::from(content_type);
56
57    if !status.is_client_error() && !status.is_server_error() {
58        let content = resp.text().await?;
59        match content_type {
60            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
61            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SbomHealth`"))),
62            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SbomHealth`")))),
63        }
64    } else {
65        let content = resp.text().await?;
66        let entity: Option<GetSbomHealthError> = serde_json::from_str(&content).ok();
67        Err(Error::ResponseError(ResponseContent { status, content, entity }))
68    }
69}
70
71/// Ingest persists a CycloneDX SBOM's components keyed by image digest. Gated to a validated SuperAdmin (owner == AdminOrg) — the canonical cloud super-admin check, which the build fleet / CI carries. Re-ingest is idempotent: rows share the (digest, name, version, purl) ORDER BY, so ReplacingMergeTree keeps the latest by ingested_at (and resolve reads FINAL).
72pub async fn post_sbom(configuration: &configuration::Configuration, sbom_ingest: models::SbomIngest) -> Result<models::SbomIngested, Error<PostSbomError>> {
73    // add a prefix to parameters to efficiently prevent name collisions
74    let p_sbom_ingest = sbom_ingest;
75
76    let uri_str = format!("{}/v1/sbom", configuration.base_path);
77    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
78
79    if let Some(ref user_agent) = configuration.user_agent {
80        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
81    }
82    if let Some(ref token) = configuration.bearer_access_token {
83        req_builder = req_builder.bearer_auth(token.to_owned());
84    };
85    req_builder = req_builder.json(&p_sbom_ingest);
86
87    let req = req_builder.build()?;
88    let resp = configuration.client.execute(req).await?;
89
90    let status = resp.status();
91    let content_type = resp
92        .headers()
93        .get("content-type")
94        .and_then(|v| v.to_str().ok())
95        .unwrap_or("application/octet-stream");
96    let content_type = super::ContentType::from(content_type);
97
98    if !status.is_client_error() && !status.is_server_error() {
99        let content = resp.text().await?;
100        match content_type {
101            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SbomIngested`"))),
103            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SbomIngested`")))),
104        }
105    } else {
106        let content = resp.text().await?;
107        let entity: Option<PostSbomError> = serde_json::from_str(&content).ok();
108        Err(Error::ResponseError(ResponseContent { status, content, entity }))
109    }
110}
111