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 {
async fn bulk_delete<'a>(
&self,
uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
) -> Result<models::BulkDeleteResponseModelListResponseModel, Error>;
async fn create<'a>(
&self,
organization_id: uuid::Uuid,
secret_create_request_model: Option<models::SecretCreateRequestModel>,
) -> Result<models::SecretResponseModel, Error>;
async fn get<'a>(&self, id: uuid::Uuid) -> Result<models::SecretResponseModel, Error>;
async fn get_secrets_by_ids<'a>(
&self,
get_secrets_request_model: Option<models::GetSecretsRequestModel>,
) -> Result<models::BaseSecretResponseModelListResponseModel, Error>;
async fn get_secrets_by_project<'a>(
&self,
project_id: uuid::Uuid,
) -> Result<models::SecretWithProjectsListResponseModel, Error>;
async fn get_secrets_sync<'a>(
&self,
organization_id: uuid::Uuid,
last_synced_date: Option<String>,
) -> Result<models::SecretsSyncResponseModel, Error>;
async fn list_by_organization<'a>(
&self,
organization_id: uuid::Uuid,
) -> Result<models::SecretWithProjectsListResponseModel, Error>;
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", ¶m_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
}
}