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 SelfHostedOrganizationLicensesApi: Send + Sync {
    /// POST /organizations/licenses/self-hosted
    async fn create_license<'a>(
        &self,
        key: &'a str,
        keys_public_key: &'a str,
        keys_encrypted_private_key: &'a str,
        license: std::path::PathBuf,
        collection_name: Option<&'a str>,
    ) -> Result<models::OrganizationResponseModel, Error>;

    /// POST /organizations/licenses/self-hosted/{id}/sync
    async fn sync_license<'a>(&self, id: &'a str) -> Result<(), Error>;

    /// POST /organizations/licenses/self-hosted/{id}
    async fn update_license<'a>(
        &self,
        id: &'a str,
        license: std::path::PathBuf,
    ) -> Result<(), Error>;
}

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

impl SelfHostedOrganizationLicensesApiClient {
    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 SelfHostedOrganizationLicensesApi for SelfHostedOrganizationLicensesApiClient {
    async fn create_license<'a>(
        &self,
        key: &'a str,
        keys_public_key: &'a str,
        keys_encrypted_private_key: &'a str,
        license: std::path::PathBuf,
        collection_name: Option<&'a str>,
    ) -> Result<models::OrganizationResponseModel, Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/licenses/self-hosted",
            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.query(&[("key", &key.to_string())]);
        if let Some(ref param_value) = collection_name {
            local_var_req_builder =
                local_var_req_builder.query(&[("collectionName", &param_value.to_string())]);
        }
        local_var_req_builder =
            local_var_req_builder.query(&[("keys.publicKey", &keys_public_key.to_string())]);
        local_var_req_builder = local_var_req_builder.query(&[(
            "keys.encryptedPrivateKey",
            &keys_encrypted_private_key.to_string(),
        )]);
        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
        let mut local_var_form = reqwest::multipart::Form::new();
        // TODO: support file upload for 'license' parameter
        local_var_req_builder = local_var_req_builder.multipart(local_var_form);

        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
    }

    async fn sync_license<'a>(&self, id: &'a str) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/licenses/self-hosted/{id}/sync",
            local_var_configuration.base_path,
            id = crate::apis::urlencode(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);

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }

    async fn update_license<'a>(
        &self,
        id: &'a str,
        license: std::path::PathBuf,
    ) -> Result<(), Error> {
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/organizations/licenses/self-hosted/{id}",
            local_var_configuration.base_path,
            id = crate::apis::urlencode(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);
        let mut local_var_form = reqwest::multipart::Form::new();
        // TODO: support file upload for 'license' parameter
        local_var_req_builder = local_var_req_builder.multipart(local_var_form);

        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
    }
}