Skip to main content

hanzo_client/apis/
catalog_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_catalog`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetCatalogError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// Browse searches AND browses the cross-org catalog: every project, app and site the fleet has built, whichever org built it.  It reads TWO corpora and returns them as one page — the published, world-readable catalog that every caller sees, plus the caller's OWN org's private entries when the request carries a validated principal. Each row says which it came from in `scope`, so a client can warn before sharing a link. An anonymous caller simply gets the published one; no filter can ever widen a caller into another tenant's corpus, because the query that would return it is never run for them.  A request with no q is a browse rather than a search, and both answer the same shape: the page, the total before paging, and the facet counts over the whole matching set.
27pub async fn get_catalog(configuration: &configuration::Configuration, q: Option<&str>, org: Option<&str>, kind: Option<&str>, origin: Option<&str>, archetype: Option<&str>, language: Option<&str>, template: Option<&str>, forkable: Option<&str>, limit: Option<&str>, offset: Option<&str>) -> Result<models::CatalogPage, Error<GetCatalogError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    let p_q = q;
30    let p_org = org;
31    let p_kind = kind;
32    let p_origin = origin;
33    let p_archetype = archetype;
34    let p_language = language;
35    let p_template = template;
36    let p_forkable = forkable;
37    let p_limit = limit;
38    let p_offset = offset;
39
40    let uri_str = format!("{}/v1/catalog", configuration.base_path);
41    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
42
43    if let Some(ref param_value) = p_q {
44        req_builder = req_builder.query(&[("q", &param_value.to_string())]);
45    }
46    if let Some(ref param_value) = p_org {
47        req_builder = req_builder.query(&[("org", &param_value.to_string())]);
48    }
49    if let Some(ref param_value) = p_kind {
50        req_builder = req_builder.query(&[("kind", &param_value.to_string())]);
51    }
52    if let Some(ref param_value) = p_origin {
53        req_builder = req_builder.query(&[("origin", &param_value.to_string())]);
54    }
55    if let Some(ref param_value) = p_archetype {
56        req_builder = req_builder.query(&[("archetype", &param_value.to_string())]);
57    }
58    if let Some(ref param_value) = p_language {
59        req_builder = req_builder.query(&[("language", &param_value.to_string())]);
60    }
61    if let Some(ref param_value) = p_template {
62        req_builder = req_builder.query(&[("template", &param_value.to_string())]);
63    }
64    if let Some(ref param_value) = p_forkable {
65        req_builder = req_builder.query(&[("forkable", &param_value.to_string())]);
66    }
67    if let Some(ref param_value) = p_limit {
68        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
69    }
70    if let Some(ref param_value) = p_offset {
71        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
72    }
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76    if let Some(ref token) = configuration.bearer_access_token {
77        req_builder = req_builder.bearer_auth(token.to_owned());
78    };
79
80    let req = req_builder.build()?;
81    let resp = configuration.client.execute(req).await?;
82
83    let status = resp.status();
84    let content_type = resp
85        .headers()
86        .get("content-type")
87        .and_then(|v| v.to_str().ok())
88        .unwrap_or("application/octet-stream");
89    let content_type = super::ContentType::from(content_type);
90
91    if !status.is_client_error() && !status.is_server_error() {
92        let content = resp.text().await?;
93        match content_type {
94            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
95            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CatalogPage`"))),
96            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::CatalogPage`")))),
97        }
98    } else {
99        let content = resp.text().await?;
100        let entity: Option<GetCatalogError> = serde_json::from_str(&content).ok();
101        Err(Error::ResponseError(ResponseContent { status, content, entity }))
102    }
103}
104