bitwarden_api_api/apis/
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 [`licenses_organization_id_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum LicensesOrganizationIdGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`licenses_user_id_get`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum LicensesUserIdGetError {
28    UnknownValue(serde_json::Value),
29}
30
31pub async fn licenses_organization_id_get(
32    configuration: &configuration::Configuration,
33    id: &str,
34    self_hosted_organization_license_request_model: Option<
35        models::SelfHostedOrganizationLicenseRequestModel,
36    >,
37) -> Result<models::OrganizationLicense, Error<LicensesOrganizationIdGetError>> {
38    // add a prefix to parameters to efficiently prevent name collisions
39    let p_id = id;
40    let p_self_hosted_organization_license_request_model =
41        self_hosted_organization_license_request_model;
42
43    let uri_str = format!(
44        "{}/licenses/organization/{id}",
45        configuration.base_path,
46        id = crate::apis::urlencode(p_id)
47    );
48    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
49
50    if let Some(ref user_agent) = configuration.user_agent {
51        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52    }
53    if let Some(ref token) = configuration.oauth_access_token {
54        req_builder = req_builder.bearer_auth(token.to_owned());
55    };
56    req_builder = req_builder.json(&p_self_hosted_organization_license_request_model);
57
58    let req = req_builder.build()?;
59    let resp = configuration.client.execute(req).await?;
60
61    let status = resp.status();
62    let content_type = resp
63        .headers()
64        .get("content-type")
65        .and_then(|v| v.to_str().ok())
66        .unwrap_or("application/octet-stream");
67    let content_type = super::ContentType::from(content_type);
68
69    if !status.is_client_error() && !status.is_server_error() {
70        let content = resp.text().await?;
71        match content_type {
72            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
73            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OrganizationLicense`"))),
74            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::OrganizationLicense`")))),
75        }
76    } else {
77        let content = resp.text().await?;
78        let entity: Option<LicensesOrganizationIdGetError> = serde_json::from_str(&content).ok();
79        Err(Error::ResponseError(ResponseContent {
80            status,
81            content,
82            entity,
83        }))
84    }
85}
86
87pub async fn licenses_user_id_get(
88    configuration: &configuration::Configuration,
89    id: &str,
90    key: Option<&str>,
91) -> Result<models::UserLicense, Error<LicensesUserIdGetError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_id = id;
94    let p_key = key;
95
96    let uri_str = format!(
97        "{}/licenses/user/{id}",
98        configuration.base_path,
99        id = crate::apis::urlencode(p_id)
100    );
101    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
102
103    if let Some(ref param_value) = p_key {
104        req_builder = req_builder.query(&[("key", &param_value.to_string())]);
105    }
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109    if let Some(ref token) = configuration.oauth_access_token {
110        req_builder = req_builder.bearer_auth(token.to_owned());
111    };
112
113    let req = req_builder.build()?;
114    let resp = configuration.client.execute(req).await?;
115
116    let status = resp.status();
117    let content_type = resp
118        .headers()
119        .get("content-type")
120        .and_then(|v| v.to_str().ok())
121        .unwrap_or("application/octet-stream");
122    let content_type = super::ContentType::from(content_type);
123
124    if !status.is_client_error() && !status.is_server_error() {
125        let content = resp.text().await?;
126        match content_type {
127            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
128            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserLicense`"))),
129            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::UserLicense`")))),
130        }
131    } else {
132        let content = resp.text().await?;
133        let entity: Option<LicensesUserIdGetError> = serde_json::from_str(&content).ok();
134        Err(Error::ResponseError(ResponseContent {
135            status,
136            content,
137            entity,
138        }))
139    }
140}