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 {
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>;
async fn sync_license<'a>(&self, id: &'a str) -> Result<(), Error>;
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", ¶m_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();
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();
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
}
}