bitwarden_api_api/apis/
self_hosted_organization_licenses_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 SelfHostedOrganizationLicensesApi: Send + Sync {
29 async fn create_license<'a>(
31 &self,
32 key: &'a str,
33 keys_public_key: &'a str,
34 keys_encrypted_private_key: &'a str,
35 license: std::path::PathBuf,
36 collection_name: Option<&'a str>,
37 ) -> Result<models::OrganizationResponseModel, Error<CreateLicenseError>>;
38
39 async fn sync_license<'a>(&self, id: &'a str) -> Result<(), Error<SyncLicenseError>>;
41
42 async fn update_license<'a>(
44 &self,
45 id: &'a str,
46 license: std::path::PathBuf,
47 ) -> Result<(), Error<UpdateLicenseError>>;
48}
49
50pub struct SelfHostedOrganizationLicensesApiClient {
51 configuration: Arc<configuration::Configuration>,
52}
53
54impl SelfHostedOrganizationLicensesApiClient {
55 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
56 Self { configuration }
57 }
58}
59
60#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
61#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
62impl SelfHostedOrganizationLicensesApi for SelfHostedOrganizationLicensesApiClient {
63 async fn create_license<'a>(
64 &self,
65 key: &'a str,
66 keys_public_key: &'a str,
67 keys_encrypted_private_key: &'a str,
68 license: std::path::PathBuf,
69 collection_name: Option<&'a str>,
70 ) -> Result<models::OrganizationResponseModel, Error<CreateLicenseError>> {
71 let local_var_configuration = &self.configuration;
72
73 let local_var_client = &local_var_configuration.client;
74
75 let local_var_uri_str = format!(
76 "{}/organizations/licenses/self-hosted",
77 local_var_configuration.base_path
78 );
79 let mut local_var_req_builder =
80 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
81
82 local_var_req_builder = local_var_req_builder.query(&[("key", &key.to_string())]);
83 if let Some(ref param_value) = collection_name {
84 local_var_req_builder =
85 local_var_req_builder.query(&[("collectionName", ¶m_value.to_string())]);
86 }
87 local_var_req_builder =
88 local_var_req_builder.query(&[("keys.publicKey", &keys_public_key.to_string())]);
89 local_var_req_builder = local_var_req_builder.query(&[(
90 "keys.encryptedPrivateKey",
91 &keys_encrypted_private_key.to_string(),
92 )]);
93 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
94 let mut local_var_form = reqwest::multipart::Form::new();
95 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
97
98 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
99 }
100
101 async fn sync_license<'a>(&self, id: &'a str) -> Result<(), Error<SyncLicenseError>> {
102 let local_var_configuration = &self.configuration;
103
104 let local_var_client = &local_var_configuration.client;
105
106 let local_var_uri_str = format!(
107 "{}/organizations/licenses/self-hosted/{id}/sync",
108 local_var_configuration.base_path,
109 id = crate::apis::urlencode(id)
110 );
111 let mut local_var_req_builder =
112 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
113
114 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
115
116 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
117 }
118
119 async fn update_license<'a>(
120 &self,
121 id: &'a str,
122 license: std::path::PathBuf,
123 ) -> Result<(), Error<UpdateLicenseError>> {
124 let local_var_configuration = &self.configuration;
125
126 let local_var_client = &local_var_configuration.client;
127
128 let local_var_uri_str = format!(
129 "{}/organizations/licenses/self-hosted/{id}",
130 local_var_configuration.base_path,
131 id = crate::apis::urlencode(id)
132 );
133 let mut local_var_req_builder =
134 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
135
136 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
137 let mut local_var_form = reqwest::multipart::Form::new();
138 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
140
141 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
142 }
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize)]
147#[serde(untagged)]
148pub enum CreateLicenseError {
149 UnknownValue(serde_json::Value),
150}
151#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum SyncLicenseError {
155 UnknownValue(serde_json::Value),
156}
157#[derive(Debug, Clone, Serialize, Deserialize)]
159#[serde(untagged)]
160pub enum UpdateLicenseError {
161 UnknownValue(serde_json::Value),
162}