Skip to main content

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 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 LicensesApi: Send + Sync {
29    /// GET /licenses/user/{id}
30    async fn get_user<'a>(
31        &self,
32        id: &'a str,
33        key: Option<&'a str>,
34    ) -> Result<models::UserLicense, Error<GetUserError>>;
35
36    /// GET /licenses/organization/{id}
37    async fn organization_sync<'a>(
38        &self,
39        id: &'a str,
40        self_hosted_organization_license_request_model: Option<
41            models::SelfHostedOrganizationLicenseRequestModel,
42        >,
43    ) -> Result<models::OrganizationLicense, Error<OrganizationSyncError>>;
44}
45
46pub struct LicensesApiClient {
47    configuration: Arc<configuration::Configuration>,
48}
49
50impl LicensesApiClient {
51    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
52        Self { configuration }
53    }
54}
55
56#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
57#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
58impl LicensesApi for LicensesApiClient {
59    async fn get_user<'a>(
60        &self,
61        id: &'a str,
62        key: Option<&'a str>,
63    ) -> Result<models::UserLicense, Error<GetUserError>> {
64        let local_var_configuration = &self.configuration;
65
66        let local_var_client = &local_var_configuration.client;
67
68        let local_var_uri_str = format!(
69            "{}/licenses/user/{id}",
70            local_var_configuration.base_path,
71            id = crate::apis::urlencode(id)
72        );
73        let mut local_var_req_builder =
74            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
75
76        if let Some(ref param_value) = key {
77            local_var_req_builder =
78                local_var_req_builder.query(&[("key", &param_value.to_string())]);
79        }
80        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
81
82        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
83    }
84
85    async fn organization_sync<'a>(
86        &self,
87        id: &'a str,
88        self_hosted_organization_license_request_model: Option<
89            models::SelfHostedOrganizationLicenseRequestModel,
90        >,
91    ) -> Result<models::OrganizationLicense, Error<OrganizationSyncError>> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!(
97            "{}/licenses/organization/{id}",
98            local_var_configuration.base_path,
99            id = crate::apis::urlencode(id)
100        );
101        let mut local_var_req_builder =
102            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
103
104        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
105        local_var_req_builder =
106            local_var_req_builder.json(&self_hosted_organization_license_request_model);
107
108        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
109    }
110}
111
112/// struct for typed errors of method [`LicensesApi::get_user`]
113#[derive(Debug, Clone, Serialize, Deserialize)]
114#[serde(untagged)]
115pub enum GetUserError {
116    UnknownValue(serde_json::Value),
117}
118/// struct for typed errors of method [`LicensesApi::organization_sync`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum OrganizationSyncError {
122    UnknownValue(serde_json::Value),
123}