Skip to main content

bitwarden_api_api/apis/
organization_users_keys_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait OrganizationUsersKeysApi: Send + Sync {
29    /// GET /organizations/{orgId}/users/keys/pending-v2-upgrades
30    /// A V1 to V2 upgrade rotation cannot re-wrap the account recovery key, because that requires
31    /// the member to trust the organization's public key and the upgrade does not prompt the
32    /// member. The rotation leaves a V2 upgrade token on the membership instead. Account recovery
33    /// gives the admin the member's V1 user key, so the admin unwraps the V2 user key from the
34    /// token and re-wraps the account recovery key with it.              Only Owners and Admins of
35    /// the organization can call this endpoint. It returns only the members the caller can recover.
36    /// The client posts each page to `POST v2-upgrades`, then reads the next page with the
37    /// continuation token of the response, until the token is null. A page can be empty and still
38    /// have a token.
39    async fn get_pending_v2_upgrades<'a>(
40        &self,
41        org_id: uuid::Uuid,
42        continuation_token: Option<uuid::Uuid>,
43    ) -> Result<models::OrganizationUserPendingV2UpgradeResponseModelListResponseModel, Error>;
44
45    /// POST /organizations/{orgId}/users/keys/v2-upgrades
46    /// Only Owners and Admins of the organization can call this endpoint, and only for members they
47    /// can recover. A membership that has changed since the read is skipped rather than rejected.
48    async fn post_v2_upgrades<'a>(
49        &self,
50        org_id: uuid::Uuid,
51        organization_user_v2_upgrades_request_model: Option<
52            models::OrganizationUserV2UpgradesRequestModel,
53        >,
54    ) -> Result<(), Error>;
55}
56
57pub struct OrganizationUsersKeysApiClient {
58    configuration: Arc<configuration::Configuration>,
59}
60
61impl OrganizationUsersKeysApiClient {
62    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63        Self { configuration }
64    }
65}
66
67#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
68#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
69impl OrganizationUsersKeysApi for OrganizationUsersKeysApiClient {
70    /// A V1 to V2 upgrade rotation cannot re-wrap the account recovery key, because that requires
71    /// the member to trust the organization's public key and the upgrade does not prompt the
72    /// member. The rotation leaves a V2 upgrade token on the membership instead. Account recovery
73    /// gives the admin the member's V1 user key, so the admin unwraps the V2 user key from the
74    /// token and re-wraps the account recovery key with it.              Only Owners and Admins of
75    /// the organization can call this endpoint. It returns only the members the caller can recover.
76    /// The client posts each page to `POST v2-upgrades`, then reads the next page with the
77    /// continuation token of the response, until the token is null. A page can be empty and still
78    /// have a token.
79    async fn get_pending_v2_upgrades<'a>(
80        &self,
81        org_id: uuid::Uuid,
82        continuation_token: Option<uuid::Uuid>,
83    ) -> Result<models::OrganizationUserPendingV2UpgradeResponseModelListResponseModel, Error> {
84        let local_var_configuration = &self.configuration;
85
86        let local_var_client = &local_var_configuration.client;
87
88        let local_var_uri_str = format!(
89            "{}/organizations/{orgId}/users/keys/pending-v2-upgrades",
90            local_var_configuration.base_path,
91            orgId = org_id
92        );
93        let mut local_var_req_builder =
94            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
95
96        if let Some(ref param_value) = continuation_token {
97            local_var_req_builder =
98                local_var_req_builder.query(&[("continuationToken", &param_value.to_string())]);
99        }
100        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
101
102        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
103    }
104
105    /// Only Owners and Admins of the organization can call this endpoint, and only for members they
106    /// can recover. A membership that has changed since the read is skipped rather than rejected.
107    async fn post_v2_upgrades<'a>(
108        &self,
109        org_id: uuid::Uuid,
110        organization_user_v2_upgrades_request_model: Option<
111            models::OrganizationUserV2UpgradesRequestModel,
112        >,
113    ) -> Result<(), Error> {
114        let local_var_configuration = &self.configuration;
115
116        let local_var_client = &local_var_configuration.client;
117
118        let local_var_uri_str = format!(
119            "{}/organizations/{orgId}/users/keys/v2-upgrades",
120            local_var_configuration.base_path,
121            orgId = org_id
122        );
123        let mut local_var_req_builder =
124            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
125
126        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
127        local_var_req_builder =
128            local_var_req_builder.json(&organization_user_v2_upgrades_request_model);
129
130        bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
131    }
132}