bitwarden-api-api 3.0.0

Api bindings for the Bitwarden API.
Documentation
/*
 * Bitwarden Internal API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: latest
 *
 * Generated by: https://openapi-generator.tech
 */

use std::sync::Arc;

use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};

use super::{Error, configuration};
use crate::{
    apis::{AuthRequired, ContentType, ResponseContent},
    models,
};

#[cfg_attr(feature = "mockall", automock)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait SecretsApi: Send + Sync {
    /// POST /secrets/delete
    async fn bulk_delete<'a>(
        &self,
        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error>;

    /// POST /organizations/{organizationId}/secrets
    async fn create<'a>(
        &self,
        organization_id: uuid::Uuid,
        secret_create_request_model: Option<models::SecretCreateRequestModel>,
    ) -> Result<models::SecretResponseModel, Error>;

    /// GET /secrets/{id}
    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::SecretResponseModel, Error>;

    /// POST /secrets/get-by-ids
    async fn get_secrets_by_ids<'a>(
        &self,
        get_secrets_request_model: Option<models::GetSecretsRequestModel>,
    ) -> Result<models::BaseSecretResponseModelListResponseModel, Error>;

    /// GET /projects/{projectId}/secrets
    async fn get_secrets_by_project<'a>(
        &self,
        project_id: uuid::Uuid,
    ) -> Result<models::SecretWithProjectsListResponseModel, Error>;

    /// GET /organizations/{organizationId}/secrets/sync
    async fn get_secrets_sync<'a>(
        &self,
        organization_id: uuid::Uuid,
        last_synced_date: Option<String>,
    ) -> Result<models::SecretsSyncResponseModel, Error>;

    /// GET /organizations/{organizationId}/secrets
    async fn list_by_organization<'a>(
        &self,
        organization_id: uuid::Uuid,
    ) -> Result<models::SecretWithProjectsListResponseModel, Error>;

    /// PUT /secrets/{id}
    async fn update_secret<'a>(
        &self,
        id: uuid::Uuid,
        secret_update_request_model: Option<models::SecretUpdateRequestModel>,
    ) -> Result<models::SecretResponseModel, Error>;
}

pub struct SecretsApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl SecretsApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl SecretsApi for SecretsApiClient {
    async fn bulk_delete<'a>(
        &self,
        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/secrets/delete", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn create<'a>(
        &self,
        organization_id: uuid::Uuid,
        secret_create_request_model: Option<models::SecretCreateRequestModel>,
    ) -> Result<models::SecretResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/{organizationId}/secrets",
            local_var_configuration.base_path,
            organizationId = organization_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        local_var_req_builder = local_var_req_builder.json(&secret_create_request_model);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::SecretResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/secrets/{id}",
            local_var_configuration.base_path,
            id = id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn get_secrets_by_ids<'a>(
        &self,
        get_secrets_request_model: Option<models::GetSecretsRequestModel>,
    ) -> Result<models::BaseSecretResponseModelListResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/secrets/get-by-ids", local_var_configuration.base_path);
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        local_var_req_builder = local_var_req_builder.json(&get_secrets_request_model);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn get_secrets_by_project<'a>(
        &self,
        project_id: uuid::Uuid,
    ) -> Result<models::SecretWithProjectsListResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/projects/{projectId}/secrets",
            local_var_configuration.base_path,
            projectId = project_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn get_secrets_sync<'a>(
        &self,
        organization_id: uuid::Uuid,
        last_synced_date: Option<String>,
    ) -> Result<models::SecretsSyncResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/{organizationId}/secrets/sync",
            local_var_configuration.base_path,
            organizationId = organization_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        if let Some(ref param_value) = last_synced_date {
            local_var_req_builder =
                local_var_req_builder.query(&[("lastSyncedDate", &param_value.to_string())]);
        }
        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn list_by_organization<'a>(
        &self,
        organization_id: uuid::Uuid,
    ) -> Result<models::SecretWithProjectsListResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/{organizationId}/secrets",
            local_var_configuration.base_path,
            organizationId = organization_id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn update_secret<'a>(
        &self,
        id: uuid::Uuid,
        secret_update_request_model: Option<models::SecretUpdateRequestModel>,
    ) -> Result<models::SecretResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/secrets/{id}",
            local_var_configuration.base_path,
            id = id
        );
        let mut local_var_req_builder =
            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        local_var_req_builder = local_var_req_builder.json(&secret_update_request_model);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }
}