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 SecretVersionsApi: Send + Sync {
async fn bulk_delete<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<(), Error>;
async fn get_by_id<'a>(
&self,
id: uuid::Uuid,
) -> Result<models::SecretVersionResponseModel, Error>;
async fn get_many_by_ids<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<models::SecretVersionResponseModelListResponseModel, Error>;
async fn get_versions_by_secret_id<'a>(
&self,
secret_id: uuid::Uuid,
) -> Result<models::SecretVersionResponseModelListResponseModel, Error>;
async fn restore_version<'a>(
&self,
secret_id: uuid::Uuid,
restore_secret_version_request_model: Option<models::RestoreSecretVersionRequestModel>,
) -> Result<models::SecretResponseModel, Error>;
}
pub struct SecretVersionsApiClient {
configuration: Arc<configuration::Configuration>,
}
impl SecretVersionsApiClient {
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 SecretVersionsApi for SecretVersionsApiClient {
async fn bulk_delete<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<(), Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/secret-versions/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_empty_response(local_var_req_builder).await
}
async fn get_by_id<'a>(
&self,
id: uuid::Uuid,
) -> Result<models::SecretVersionResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/secret-versions/{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_many_by_ids<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<models::SecretVersionResponseModelListResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/secret-versions/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(&uuid_colon_colon_uuid);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
async fn get_versions_by_secret_id<'a>(
&self,
secret_id: uuid::Uuid,
) -> Result<models::SecretVersionResponseModelListResponseModel, Error> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/secrets/{secretId}/versions",
local_var_configuration.base_path,
secretId = secret_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 restore_version<'a>(
&self,
secret_id: uuid::Uuid,
restore_secret_version_request_model: Option<models::RestoreSecretVersionRequestModel>,
) -> 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/{secretId}/versions/restore",
local_var_configuration.base_path,
secretId = secret_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(&restore_secret_version_request_model);
bitwarden_api_base::process_with_json_response(local_var_req_builder).await
}
}