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::{Deserialize, Serialize};
13
14use super::{configuration, 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    let local_var_configuration = configuration;
44
45    let local_var_client = &local_var_configuration.client;
46
47    let local_var_uri_str = format!(
48        "{}/organizations/licenses/self-hosted/{id}",
49        local_var_configuration.base_path,
50        id = crate::apis::urlencode(id)
51    );
52    let mut local_var_req_builder =
53        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
54
55    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
56        local_var_req_builder =
57            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
58    }
59    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
60        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
61    };
62    let mut local_var_form = reqwest::multipart::Form::new();
63    // TODO: support file upload for 'license' parameter
64    local_var_req_builder = local_var_req_builder.multipart(local_var_form);
65
66    let local_var_req = local_var_req_builder.build()?;
67    let local_var_resp = local_var_client.execute(local_var_req).await?;
68
69    let local_var_status = local_var_resp.status();
70    let local_var_content = local_var_resp.text().await?;
71
72    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
73        Ok(())
74    } else {
75        let local_var_entity: Option<OrganizationsLicensesSelfHostedIdPostError> =
76            serde_json::from_str(&local_var_content).ok();
77        let local_var_error = ResponseContent {
78            status: local_var_status,
79            content: local_var_content,
80            entity: local_var_entity,
81        };
82        Err(Error::ResponseError(local_var_error))
83    }
84}
85
86pub async fn organizations_licenses_self_hosted_id_sync_post(
87    configuration: &configuration::Configuration,
88    id: &str,
89) -> Result<(), Error<OrganizationsLicensesSelfHostedIdSyncPostError>> {
90    let local_var_configuration = configuration;
91
92    let local_var_client = &local_var_configuration.client;
93
94    let local_var_uri_str = format!(
95        "{}/organizations/licenses/self-hosted/{id}/sync",
96        local_var_configuration.base_path,
97        id = crate::apis::urlencode(id)
98    );
99    let mut local_var_req_builder =
100        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
101
102    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103        local_var_req_builder =
104            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105    }
106    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
107        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
108    };
109
110    let local_var_req = local_var_req_builder.build()?;
111    let local_var_resp = local_var_client.execute(local_var_req).await?;
112
113    let local_var_status = local_var_resp.status();
114    let local_var_content = local_var_resp.text().await?;
115
116    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117        Ok(())
118    } else {
119        let local_var_entity: Option<OrganizationsLicensesSelfHostedIdSyncPostError> =
120            serde_json::from_str(&local_var_content).ok();
121        let local_var_error = ResponseContent {
122            status: local_var_status,
123            content: local_var_content,
124            entity: local_var_entity,
125        };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129
130pub async fn organizations_licenses_self_hosted_post(
131    configuration: &configuration::Configuration,
132    key: &str,
133    keys_period_public_key: &str,
134    keys_period_encrypted_private_key: &str,
135    license: std::path::PathBuf,
136    collection_name: Option<&str>,
137) -> Result<models::OrganizationResponseModel, Error<OrganizationsLicensesSelfHostedPostError>> {
138    let local_var_configuration = configuration;
139
140    let local_var_client = &local_var_configuration.client;
141
142    let local_var_uri_str = format!(
143        "{}/organizations/licenses/self-hosted",
144        local_var_configuration.base_path
145    );
146    let mut local_var_req_builder =
147        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
148
149    local_var_req_builder = local_var_req_builder.query(&[("key", &key.to_string())]);
150    if let Some(ref local_var_str) = collection_name {
151        local_var_req_builder =
152            local_var_req_builder.query(&[("collectionName", &local_var_str.to_string())]);
153    }
154    local_var_req_builder =
155        local_var_req_builder.query(&[("keys.publicKey", &keys_period_public_key.to_string())]);
156    local_var_req_builder = local_var_req_builder.query(&[(
157        "keys.encryptedPrivateKey",
158        &keys_period_encrypted_private_key.to_string(),
159    )]);
160    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
161        local_var_req_builder =
162            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
163    }
164    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
165        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
166    };
167    let mut local_var_form = reqwest::multipart::Form::new();
168    // TODO: support file upload for 'license' parameter
169    local_var_req_builder = local_var_req_builder.multipart(local_var_form);
170
171    let local_var_req = local_var_req_builder.build()?;
172    let local_var_resp = local_var_client.execute(local_var_req).await?;
173
174    let local_var_status = local_var_resp.status();
175    let local_var_content = local_var_resp.text().await?;
176
177    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
178        serde_json::from_str(&local_var_content).map_err(Error::from)
179    } else {
180        let local_var_entity: Option<OrganizationsLicensesSelfHostedPostError> =
181            serde_json::from_str(&local_var_content).ok();
182        let local_var_error = ResponseContent {
183            status: local_var_status,
184            content: local_var_content,
185            entity: local_var_entity,
186        };
187        Err(Error::ResponseError(local_var_error))
188    }
189}