bitwarden_api_api/apis/
cipher_lease_api.rs1use 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 CipherLeaseApi: Send + Sync {
29 async fn post<'a>(
31 &self,
32 id: uuid::Uuid,
33 access_request_create_request_model: models::AccessRequestCreateRequestModel,
34 ) -> Result<models::AccessRequestResultResponseModel, Error>;
35
36 async fn pre_check<'a>(
38 &self,
39 id: uuid::Uuid,
40 ) -> Result<models::AccessPreCheckResponseModel, Error>;
41
42 async fn state<'a>(
44 &self,
45 id: uuid::Uuid,
46 ) -> Result<models::CipherAccessStateResponseModel, Error>;
47}
48
49pub struct CipherLeaseApiClient {
50 configuration: Arc<configuration::Configuration>,
51}
52
53impl CipherLeaseApiClient {
54 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
55 Self { configuration }
56 }
57}
58
59#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
60#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
61impl CipherLeaseApi for CipherLeaseApiClient {
62 async fn post<'a>(
63 &self,
64 id: uuid::Uuid,
65 access_request_create_request_model: models::AccessRequestCreateRequestModel,
66 ) -> Result<models::AccessRequestResultResponseModel, Error> {
67 let local_var_configuration = &self.configuration;
68
69 let local_var_client = &local_var_configuration.client;
70
71 let local_var_uri_str = format!(
72 "{}/leases/ciphers/{id}",
73 local_var_configuration.base_path,
74 id = id
75 );
76 let mut local_var_req_builder =
77 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
78
79 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
80 local_var_req_builder = local_var_req_builder.json(&access_request_create_request_model);
81
82 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
83 }
84
85 async fn pre_check<'a>(
86 &self,
87 id: uuid::Uuid,
88 ) -> Result<models::AccessPreCheckResponseModel, Error> {
89 let local_var_configuration = &self.configuration;
90
91 let local_var_client = &local_var_configuration.client;
92
93 let local_var_uri_str = format!(
94 "{}/leases/ciphers/{id}/pre-check",
95 local_var_configuration.base_path,
96 id = id
97 );
98 let mut local_var_req_builder =
99 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
100
101 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
102
103 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
104 }
105
106 async fn state<'a>(
107 &self,
108 id: uuid::Uuid,
109 ) -> Result<models::CipherAccessStateResponseModel, Error> {
110 let local_var_configuration = &self.configuration;
111
112 let local_var_client = &local_var_configuration.client;
113
114 let local_var_uri_str = format!(
115 "{}/leases/ciphers/{id}/state",
116 local_var_configuration.base_path,
117 id = id
118 );
119 let mut local_var_req_builder =
120 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
121
122 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
123
124 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
125 }
126}