sindri-openapi 0.3.1

An autogenerated, configurable Sindri API client used by the main Sindri package
Documentation
/*
 * Sindri Labs API
 *
 *  ## About [Sindri Labs](https://www.sindri.app/)' API simplifies the developer experience to enable fast and scalable zero-knowledge proof generation. Front-End Dashboard: [https://sindri.app/login](https://sindri.app/login) ## Documentation The [Sindri Documentation](https://sindri.app/docs) contains everything you need to get started! ## Sindri Resources The [sindri-resources GitHub repo](https://github.com/Sindri-Labs/sindri-resources) contains contains resources and sample data for the Sindri API. ## Using this Page This is a standard [OpenAPI (Swagger)](https://swagger.io/specification/) API documentation page. It provides detailed documentation for each endpoint. This page enables easy prototyping via the \"Try it out\" feature! Since all Sindri endpoints require a valid API Key, in order to use the \"Try it out\" feature for any endpoint in this documentation you must first obtain an API key. Do this in one of two ways: 1. Enter your username and password in the `/api/apikey/generate` endpoint of the **Authorization** section below. Use the API key returned in the `access` field of the response. 2. Obtain an API key from the Sindri Dashboard team \"Account Settings\". After obtaining your API key, authorize your page session by entering your API Key in the `SindriAPIKeyBearerAuth` section, reached by clicking \"Authorize\" below. Proving Backend Version: v1.2.17
 *
 * The version of the OpenAPI document: v1.17.28
 *
 * Generated by: https://openapi-generator.tech
 */

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

/// struct for typed errors of method [`apikey_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ApikeyDeleteError {
    Status404(models::ApiKeyDoesNotExistResponse),
    Status500(models::SindriInternalErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`apikey_generate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ApikeyGenerateError {
    Status400(models::SindriValueErrorResponse),
    Status403(models::ApiKeyErrorResponse),
    Status401(models::ApiKeyErrorResponse),
    UnknownValue(serde_json::Value),
}

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

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

/// Delete a specific API key.
pub async fn apikey_delete(
    configuration: &configuration::Configuration,
    apikey_id: Option<&str>,
) -> Result<models::ActionResponse, Error<ApikeyDeleteError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_apikey_id = apikey_id;

    let uri_str = format!(
        "{}/api/v1/apikey/{apikey_id}/delete",
        configuration.base_path,
        apikey_id = crate::apis::urlencode(p_apikey_id.unwrap())
    );
    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());
    };
    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() {
        let content = resp.text().await?;
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let content = resp.text().await?;
        let entity: Option<ApikeyDeleteError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Generates a long-term API Key from your account's username and password.
pub async fn apikey_generate(
    configuration: &configuration::Configuration,
    obtain_apikey_input: models::ObtainApikeyInput,
    sindri_team_id: Option<&str>,
) -> Result<models::ApiKeyResponse, Error<ApikeyGenerateError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_obtain_apikey_input = obtain_apikey_input;
    let p_sindri_team_id = sindri_team_id;

    let uri_str = format!("{}/api/apikey/generate", configuration.base_path);
    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(param_value) = p_sindri_team_id {
        req_builder = req_builder.header("Sindri-Team-Id", param_value.to_string());
    }
    req_builder = req_builder.json(&p_obtain_apikey_input);

    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() {
        let content = resp.text().await?;
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let content = resp.text().await?;
        let entity: Option<ApikeyGenerateError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Generate an API key for the requesting team.
pub async fn apikey_generate_with_auth(
    configuration: &configuration::Configuration,
    name: Option<&str>,
) -> Result<models::ApiKeyResponse, Error<ApikeyGenerateWithAuthError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_name = name;

    let uri_str = format!("{}/api/v1/apikey/generate", configuration.base_path);
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref param_value) = p_name {
        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
    }
    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());
    };
    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() {
        let content = resp.text().await?;
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let content = resp.text().await?;
        let entity: Option<ApikeyGenerateWithAuthError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// List API keys for the requesting team.
pub async fn apikey_list(
    configuration: &configuration::Configuration,
) -> Result<Vec<models::ApiKeyResponse>, Error<ApikeyListError>> {
    let uri_str = format!("{}/api/v1/apikey/list", configuration.base_path);
    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());
    };
    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() {
        let content = resp.text().await?;
        serde_json::from_str(&content).map_err(Error::from)
    } else {
        let content = resp.text().await?;
        let entity: Option<ApikeyListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}