bitwarden_api_api/apis/
secrets_manager_porting_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SmOrganizationIdExportGetError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum SmOrganizationIdImportPostError {
28 UnknownValue(serde_json::Value),
29}
30
31pub async fn sm_organization_id_export_get(
32 configuration: &configuration::Configuration,
33 organization_id: uuid::Uuid,
34) -> Result<models::SmExportResponseModel, Error<SmOrganizationIdExportGetError>> {
35 let p_organization_id = organization_id;
37
38 let uri_str = format!(
39 "{}/sm/{organizationId}/export",
40 configuration.base_path,
41 organizationId = crate::apis::urlencode(p_organization_id.to_string())
42 );
43 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45 if let Some(ref user_agent) = configuration.user_agent {
46 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
47 }
48 if let Some(ref token) = configuration.oauth_access_token {
49 req_builder = req_builder.bearer_auth(token.to_owned());
50 };
51
52 let req = req_builder.build()?;
53 let resp = configuration.client.execute(req).await?;
54
55 let status = resp.status();
56 let content_type = resp
57 .headers()
58 .get("content-type")
59 .and_then(|v| v.to_str().ok())
60 .unwrap_or("application/octet-stream");
61 let content_type = super::ContentType::from(content_type);
62
63 if !status.is_client_error() && !status.is_server_error() {
64 let content = resp.text().await?;
65 match content_type {
66 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
67 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SmExportResponseModel`"))),
68 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::SmExportResponseModel`")))),
69 }
70 } else {
71 let content = resp.text().await?;
72 let entity: Option<SmOrganizationIdExportGetError> = serde_json::from_str(&content).ok();
73 Err(Error::ResponseError(ResponseContent {
74 status,
75 content,
76 entity,
77 }))
78 }
79}
80
81pub async fn sm_organization_id_import_post(
82 configuration: &configuration::Configuration,
83 organization_id: uuid::Uuid,
84 sm_import_request_model: Option<models::SmImportRequestModel>,
85) -> Result<(), Error<SmOrganizationIdImportPostError>> {
86 let p_organization_id = organization_id;
88 let p_sm_import_request_model = sm_import_request_model;
89
90 let uri_str = format!(
91 "{}/sm/{organizationId}/import",
92 configuration.base_path,
93 organizationId = crate::apis::urlencode(p_organization_id.to_string())
94 );
95 let mut req_builder = configuration
96 .client
97 .request(reqwest::Method::POST, &uri_str);
98
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 if let Some(ref token) = configuration.oauth_access_token {
103 req_builder = req_builder.bearer_auth(token.to_owned());
104 };
105 req_builder = req_builder.json(&p_sm_import_request_model);
106
107 let req = req_builder.build()?;
108 let resp = configuration.client.execute(req).await?;
109
110 let status = resp.status();
111
112 if !status.is_client_error() && !status.is_server_error() {
113 Ok(())
114 } else {
115 let content = resp.text().await?;
116 let entity: Option<SmOrganizationIdImportPostError> = serde_json::from_str(&content).ok();
117 Err(Error::ResponseError(ResponseContent {
118 status,
119 content,
120 entity,
121 }))
122 }
123}