bitwarden_api_api/apis/
self_hosted_organization_licenses_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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`organizations_licenses_self_hosted_id_post`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum OrganizationsLicensesSelfHostedIdPostError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`organizations_licenses_self_hosted_id_sync_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum OrganizationsLicensesSelfHostedIdSyncPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`organizations_licenses_self_hosted_post`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum OrganizationsLicensesSelfHostedPostError {
35    UnknownValue(serde_json::Value),
36}
37
38pub async fn organizations_licenses_self_hosted_id_post(
39    configuration: &configuration::Configuration,
40    id: &str,
41    license: std::path::PathBuf,
42) -> Result<(), Error<OrganizationsLicensesSelfHostedIdPostError>> {
43    // add a prefix to parameters to efficiently prevent name collisions
44    let p_id = id;
45    let p_license = license;
46
47    let uri_str = format!(
48        "{}/organizations/licenses/self-hosted/{id}",
49        configuration.base_path,
50        id = crate::apis::urlencode(p_id)
51    );
52    let mut req_builder = configuration
53        .client
54        .request(reqwest::Method::POST, &uri_str);
55
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref token) = configuration.oauth_access_token {
60        req_builder = req_builder.bearer_auth(token.to_owned());
61    };
62    let mut multipart_form = reqwest::multipart::Form::new();
63    // TODO: support file upload for 'license' parameter
64    req_builder = req_builder.multipart(multipart_form);
65
66    let req = req_builder.build()?;
67    let resp = configuration.client.execute(req).await?;
68
69    let status = resp.status();
70
71    if !status.is_client_error() && !status.is_server_error() {
72        Ok(())
73    } else {
74        let content = resp.text().await?;
75        let entity: Option<OrganizationsLicensesSelfHostedIdPostError> =
76            serde_json::from_str(&content).ok();
77        Err(Error::ResponseError(ResponseContent {
78            status,
79            content,
80            entity,
81        }))
82    }
83}
84
85pub async fn organizations_licenses_self_hosted_id_sync_post(
86    configuration: &configuration::Configuration,
87    id: &str,
88) -> Result<(), Error<OrganizationsLicensesSelfHostedIdSyncPostError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_id = id;
91
92    let uri_str = format!(
93        "{}/organizations/licenses/self-hosted/{id}/sync",
94        configuration.base_path,
95        id = crate::apis::urlencode(p_id)
96    );
97    let mut req_builder = configuration
98        .client
99        .request(reqwest::Method::POST, &uri_str);
100
101    if let Some(ref user_agent) = configuration.user_agent {
102        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
103    }
104    if let Some(ref token) = configuration.oauth_access_token {
105        req_builder = req_builder.bearer_auth(token.to_owned());
106    };
107
108    let req = req_builder.build()?;
109    let resp = configuration.client.execute(req).await?;
110
111    let status = resp.status();
112
113    if !status.is_client_error() && !status.is_server_error() {
114        Ok(())
115    } else {
116        let content = resp.text().await?;
117        let entity: Option<OrganizationsLicensesSelfHostedIdSyncPostError> =
118            serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent {
120            status,
121            content,
122            entity,
123        }))
124    }
125}
126
127pub async fn organizations_licenses_self_hosted_post(
128    configuration: &configuration::Configuration,
129    key: &str,
130    keys_period_public_key: &str,
131    keys_period_encrypted_private_key: &str,
132    license: std::path::PathBuf,
133    collection_name: Option<&str>,
134) -> Result<models::OrganizationResponseModel, Error<OrganizationsLicensesSelfHostedPostError>> {
135    // add a prefix to parameters to efficiently prevent name collisions
136    let p_key = key;
137    let p_keys_period_public_key = keys_period_public_key;
138    let p_keys_period_encrypted_private_key = keys_period_encrypted_private_key;
139    let p_license = license;
140    let p_collection_name = collection_name;
141
142    let uri_str = format!(
143        "{}/organizations/licenses/self-hosted",
144        configuration.base_path
145    );
146    let mut req_builder = configuration
147        .client
148        .request(reqwest::Method::POST, &uri_str);
149
150    req_builder = req_builder.query(&[("key", &p_key.to_string())]);
151    if let Some(ref param_value) = p_collection_name {
152        req_builder = req_builder.query(&[("collectionName", &param_value.to_string())]);
153    }
154    req_builder = req_builder.query(&[("keys.publicKey", &p_keys_period_public_key.to_string())]);
155    req_builder = req_builder.query(&[(
156        "keys.encryptedPrivateKey",
157        &p_keys_period_encrypted_private_key.to_string(),
158    )]);
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.oauth_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165    let mut multipart_form = reqwest::multipart::Form::new();
166    // TODO: support file upload for 'license' parameter
167    req_builder = req_builder.multipart(multipart_form);
168
169    let req = req_builder.build()?;
170    let resp = configuration.client.execute(req).await?;
171
172    let status = resp.status();
173    let content_type = resp
174        .headers()
175        .get("content-type")
176        .and_then(|v| v.to_str().ok())
177        .unwrap_or("application/octet-stream");
178    let content_type = super::ContentType::from(content_type);
179
180    if !status.is_client_error() && !status.is_server_error() {
181        let content = resp.text().await?;
182        match content_type {
183            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
184            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrganizationResponseModel`"))),
185            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OrganizationResponseModel`")))),
186        }
187    } else {
188        let content = resp.text().await?;
189        let entity: Option<OrganizationsLicensesSelfHostedPostError> =
190            serde_json::from_str(&content).ok();
191        Err(Error::ResponseError(ResponseContent {
192            status,
193            content,
194            entity,
195        }))
196    }
197}