hanzo-client 8.5.156

Generated client for the Hanzo API — every service, one crate.
Documentation
/*
 * Hanzo Cloud API
 *
 * 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/.
 *
 * The version of the OpenAPI document: v1
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`delete_kv_by_bucket`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteKvByBucketError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_kv_by_bucket_by_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteKvByBucketByKeyError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_kv_by_bucket_by_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetKvByBucketByKeyError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_kv_by_bucket_by_key_history`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetKvByBucketByKeyHistoryError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`post_kv_by_bucket`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostKvByBucketError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`put_kv_by_bucket_by_key`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PutKvByBucketByKeyError {
    UnknownValue(serde_json::Value),
}


/// Removes one bucket of the caller's org — every key and every revision with it — and answers 204 with no body. 404 when the org has no bucket of that name.
pub async fn delete_kv_by_bucket(configuration: &configuration::Configuration, bucket: &str) -> Result<(), Error<DeleteKvByBucketError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;

    let uri_str = format!("{}/v1/kv/{bucket}", configuration.base_path, bucket=crate::apis::urlencode(p_bucket));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteKvByBucketError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Delete removes one key — a delete marker in the key's history, so watchers see it and Get answers 404 — and answers 204 with no body. 404 when the bucket does not exist.
pub async fn delete_kv_by_bucket_by_key(configuration: &configuration::Configuration, bucket: &str, key: &str) -> Result<(), Error<DeleteKvByBucketByKeyError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;
    let p_key = key;

    let uri_str = format!("{}/v1/kv/{bucket}/{key}", configuration.base_path, bucket=crate::apis::urlencode(p_bucket), key=crate::apis::urlencode(p_key));
    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteKvByBucketByKeyError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get returns one key's current value and revision. 404 when the bucket does not exist, the key was never written, or its latest revision is a delete.
pub async fn get_kv_by_bucket_by_key(configuration: &configuration::Configuration, bucket: &str, key: &str) -> Result<models::KvEntry, Error<GetKvByBucketByKeyError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;
    let p_key = key;

    let uri_str = format!("{}/v1/kv/{bucket}/{key}", configuration.base_path, bucket=crate::apis::urlencode(p_bucket), key=crate::apis::urlencode(p_key));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KvEntry`"))),
            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::KvEntry`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetKvByBucketByKeyError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// History returns one key's retained revisions, oldest first — every put and every delete marker up to the bucket's History depth. 404 when the bucket does not exist or the key was never written.
pub async fn get_kv_by_bucket_by_key_history(configuration: &configuration::Configuration, bucket: &str, key: &str) -> Result<models::KvPage, Error<GetKvByBucketByKeyHistoryError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;
    let p_key = key;

    let uri_str = format!("{}/v1/kv/{bucket}/{key}/history", configuration.base_path, bucket=crate::apis::urlencode(p_bucket), key=crate::apis::urlencode(p_key));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KvPage`"))),
            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::KvPage`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetKvByBucketByKeyHistoryError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Creates a KV bucket and returns it. A bucket is keyed state on the same durable plane as the streams: each key holds up to History revisions, entries can expire by TTL, and watchers on the NATS port see every write. 409 when the org already has a bucket of that name.
pub async fn post_kv_by_bucket(configuration: &configuration::Configuration, bucket: &str, bucket_write: models::BucketWrite) -> Result<models::BucketRecord, Error<PostKvByBucketError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;
    let p_bucket_write = bucket_write;

    let uri_str = format!("{}/v1/kv/{bucket}", configuration.base_path, bucket=crate::apis::urlencode(p_bucket));
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    req_builder = req_builder.json(&p_bucket_write);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BucketRecord`"))),
            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::BucketRecord`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PostKvByBucketError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Put sets one key to one value and returns the revision the write created. Writes are versioned: each put is a new revision and the bucket retains up to its History of them per key.
pub async fn put_kv_by_bucket_by_key(configuration: &configuration::Configuration, bucket: &str, key: &str, kv_write: models::KvWrite) -> Result<models::KvAck, Error<PutKvByBucketByKeyError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_bucket = bucket;
    let p_key = key;
    let p_kv_write = kv_write;

    let uri_str = format!("{}/v1/kv/{bucket}/{key}", configuration.base_path, bucket=crate::apis::urlencode(p_bucket), key=crate::apis::urlencode(p_key));
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    req_builder = req_builder.json(&p_kv_write);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::KvAck`"))),
            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::KvAck`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PutKvByBucketByKeyError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}