Skip to content

Commit

Permalink
Bring back async for get_api_configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Jun 17, 2024
1 parent 214cad3 commit 4336a0a
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 384 deletions.
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/login/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn request_access_token(
client: &Client,
input: &AccessToken,
) -> Result<IdentityTokenResponse> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
AccessTokenRequest::new(input.access_token_id, &input.client_secret)
.send(&config)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/login/api_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn request_api_identity_tokens(
client: &Client,
input: &ApiKeyLoginRequest,
) -> Result<IdentityTokenResponse> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
ApiTokenRequest::new(&input.client_id, &input.client_secret)
.send(&config)
.await
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-core/src/auth/login/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) async fn send_new_auth_request(
email: String,
device_identifier: String,
) -> Result<NewAuthRequestResponse> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let auth = new_auth_request(&email)?;

Expand Down Expand Up @@ -58,7 +58,7 @@ pub(crate) async fn complete_auth_request(
client: &Client,
auth_req: NewAuthRequestResponse,
) -> Result<()> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let res = auth_requests_id_response_get(
&config.api,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) async fn request_prelogin(
email: String,
) -> Result<PreloginResponseModel> {
let request_model = PreloginRequestModel::new(email);
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
Ok(accounts_prelogin_post(&config.identity, Some(request_model)).await?)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/login/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn request_identity_tokens(
) -> Result<IdentityTokenResponse> {
use crate::DeviceType;

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
PasswordTokenRequest::new(
&input.email,
password_hash,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/login/two_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) async fn send_two_factor_email(
HashPurpose::ServerAuthorization,
)?;

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
bitwarden_api_api::apis::two_factor_api::two_factor_send_email_login_post(
&config.api,
Some(TwoFactorEmailRequestModel {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/auth/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct RegisterRequest {

/// Half baked implementation of user registration
pub(super) async fn register(client: &Client, req: &RegisterRequest) -> Result<()> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let kdf = Kdf::default();

Expand Down
6 changes: 3 additions & 3 deletions crates/bitwarden-core/src/client/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct InternalClient {
#[cfg(feature = "internal")]
pub(super) flags: RwLock<Flags>,

/// Use Client::get_api_configurations() to access this.
/// Use Client::get_api_configurations().await to access this.
/// It should only be used directly in renew_token
#[doc(hidden)]
pub(crate) __api_configurations: RwLock<Arc<ApiConfigurations>>,
Expand Down Expand Up @@ -145,10 +145,10 @@ impl InternalClient {
}
}

pub fn get_api_configurations(&self) -> Arc<ApiConfigurations> {
pub async fn get_api_configurations(&self) -> Arc<ApiConfigurations> {
// At the moment we ignore the error result from the token renewal, if it fails,
// the token will end up expiring and the next operation is going to fail anyway.
//self.auth().renew_token().await.ok();
// self.auth().renew_token().await.ok();
self.__api_configurations
.read()
.expect("RwLock is not poisoned")
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/platform/get_user_api_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) async fn get_user_api_key(
let auth_settings = get_login_method(client)?;
let request = get_secret_verification_request(&auth_settings, input)?;

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let response = accounts_api_key_post(&config.api, Some(request)).await?;
UserApiKeyResponse::process_response(response)
Expand Down
5 changes: 2 additions & 3 deletions crates/bitwarden-send/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();
#[cfg(feature = "uniffi")]
mod uniffi_support;

mod error;
pub use error::SendParseError;
mod client_sends;
pub use client_sends::{ClientSends, ClientSendsExt};
mod send;
pub use send::{Send, SendListView, SendView};

#[cfg(feature = "uniffi")]
mod uniffi_support;
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/projects/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) async fn create_project(
name: input.name.clone().encrypt_with_key(key)?.to_string(),
});

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::projects_api::organizations_organization_id_projects_post(
&config.api,
input.organization_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/projects/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) async fn delete_projects(
client: &Client,
input: ProjectsDeleteRequest,
) -> Result<ProjectsDeleteResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res =
bitwarden_api_api::apis::projects_api::projects_delete_post(&config.api, Some(input.ids))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/projects/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) async fn get_project(
client: &Client,
input: &ProjectGetRequest,
) -> Result<ProjectResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let res = bitwarden_api_api::apis::projects_api::projects_id_get(&config.api, input.id).await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/projects/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) async fn list_projects(
client: &Client,
input: &ProjectsListRequest,
) -> Result<ProjectsResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::projects_api::organizations_organization_id_projects_get(
&config.api,
input.organization_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/projects/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) async fn update_project(
name: input.name.clone().encrypt_with_key(key)?.to_string(),
});

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res =
bitwarden_api_api::apis::projects_api::projects_id_put(&config.api, input.id, project)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) async fn create_secret(
project_ids: input.project_ids.clone(),
});

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::secrets_api::organizations_organization_id_secrets_post(
&config.api,
input.organization_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) async fn delete_secrets(
client: &Client,
input: SecretsDeleteRequest,
) -> Result<SecretsDeleteResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res =
bitwarden_api_api::apis::secrets_api::secrets_delete_post(&config.api, Some(input.ids))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) async fn get_secret(
client: &Client,
input: &SecretGetRequest,
) -> Result<SecretResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::secrets_api::secrets_id_get(&config.api, input.id).await?;

let enc = client.internal.get_encryption_settings()?;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/get_by_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) async fn get_secrets_by_ids(
) -> Result<SecretsResponse, Error> {
let request = Some(GetSecretsRequestModel { ids: input.ids });

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;

let res =
bitwarden_api_api::apis::secrets_api::secrets_get_by_ids_post(&config.api, request).await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-sm/src/secrets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) async fn list_secrets(
client: &Client,
input: &SecretIdentifiersRequest,
) -> Result<SecretIdentifiersResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::secrets_api::organizations_organization_id_secrets_get(
&config.api,
input.organization_id,
Expand All @@ -44,7 +44,7 @@ pub(crate) async fn list_secrets_by_project(
client: &Client,
input: &SecretIdentifiersByProjectRequest,
) -> Result<SecretIdentifiersResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res = bitwarden_api_api::apis::secrets_api::projects_project_id_secrets_get(
&config.api,
input.project_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) async fn sync_secrets(
client: &Client,
input: &SecretsSyncRequest,
) -> Result<SecretsSyncResponse, Error> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let last_synced_date = input.last_synced_date.map(|date| date.to_rfc3339());

let res = bitwarden_api_api::apis::secrets_api::organizations_organization_id_secrets_sync_get(
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-sm/src/secrets/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) async fn update_secret(
project_ids: input.project_ids.clone(),
});

let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let res =
bitwarden_api_api::apis::secrets_api::secrets_id_put(&config.api, input.id, secret).await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-vault/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct SyncRequest {
}

pub(crate) async fn sync(client: &Client, input: &SyncRequest) -> Result<SyncResponse, SyncError> {
let config = client.internal.get_api_configurations();
let config = client.internal.get_api_configurations().await;
let sync = bitwarden_api_api::apis::sync_api::sync_get(&config.api, input.exclude_subdomains)
.await
.map_err(|e| SyncError::Core(e.into()))?;
Expand Down
Loading

0 comments on commit 4336a0a

Please sign in to comment.