Skip to main content

hanzo_client/apis/
settings_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_settings_by_product`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetSettingsByProductError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`put_settings_by_product`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PutSettingsByProductError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Reads the caller org's configuration for one product, with every secret field MASKED — only the names of the set secrets come back, never their values, which live in KMS. A product the org has never configured is not a 404: it answers 200 with an empty config object, so the console's Settings tab always renders and merges its own display defaults on top.
34pub async fn get_settings_by_product(configuration: &configuration::Configuration, product: &str) -> Result<models::SettingsView, Error<GetSettingsByProductError>> {
35    // add a prefix to parameters to efficiently prevent name collisions
36    let p_product = product;
37
38    let uri_str = format!("{}/v1/settings/{product}", configuration.base_path, product=crate::apis::urlencode(p_product));
39    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
40
41    if let Some(ref user_agent) = configuration.user_agent {
42        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43    }
44    if let Some(ref token) = configuration.bearer_access_token {
45        req_builder = req_builder.bearer_auth(token.to_owned());
46    };
47
48    let req = req_builder.build()?;
49    let resp = configuration.client.execute(req).await?;
50
51    let status = resp.status();
52    let content_type = resp
53        .headers()
54        .get("content-type")
55        .and_then(|v| v.to_str().ok())
56        .unwrap_or("application/octet-stream");
57    let content_type = super::ContentType::from(content_type);
58
59    if !status.is_client_error() && !status.is_server_error() {
60        let content = resp.text().await?;
61        match content_type {
62            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
63            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsView`"))),
64            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::SettingsView`")))),
65        }
66    } else {
67        let content = resp.text().await?;
68        let entity: Option<GetSettingsByProductError> = serde_json::from_str(&content).ok();
69        Err(Error::ResponseError(ResponseContent { status, content, entity }))
70    }
71}
72
73/// Writes the caller org's configuration for one product and answers the stored result, secrets masked. Secret VALUES are sealed into KMS under orgs/{org}/settings/{product}/{key} and never touch this deployment's database; with no KMS configured a write that carries any secret is refused whole (503) rather than dropping it or persisting it in the clear. A secret the body omits keeps its stored value, so a partial write never silently clears one.
74pub async fn put_settings_by_product(configuration: &configuration::Configuration, product: &str, settings_req: models::SettingsReq) -> Result<models::SettingsView, Error<PutSettingsByProductError>> {
75    // add a prefix to parameters to efficiently prevent name collisions
76    let p_product = product;
77    let p_settings_req = settings_req;
78
79    let uri_str = format!("{}/v1/settings/{product}", configuration.base_path, product=crate::apis::urlencode(p_product));
80    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
81
82    if let Some(ref user_agent) = configuration.user_agent {
83        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
84    }
85    if let Some(ref token) = configuration.bearer_access_token {
86        req_builder = req_builder.bearer_auth(token.to_owned());
87    };
88    req_builder = req_builder.json(&p_settings_req);
89
90    let req = req_builder.build()?;
91    let resp = configuration.client.execute(req).await?;
92
93    let status = resp.status();
94    let content_type = resp
95        .headers()
96        .get("content-type")
97        .and_then(|v| v.to_str().ok())
98        .unwrap_or("application/octet-stream");
99    let content_type = super::ContentType::from(content_type);
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        match content_type {
104            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SettingsView`"))),
106            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::SettingsView`")))),
107        }
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<PutSettingsByProductError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
112    }
113}
114