1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessChangePasswordError {
22 Status400(models::PveError),
23 Status401(models::PveError),
24 Status403(models::PveError),
25 Status404(models::PveError),
26 Status500(models::PveError),
27 Status501(models::PveError),
28 Status503(models::PveError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessGetAccessError {
36 Status400(models::PveError),
37 Status401(models::PveError),
38 Status403(models::PveError),
39 Status404(models::PveError),
40 Status500(models::PveError),
41 Status501(models::PveError),
42 Status503(models::PveError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AccessPermissionsError {
50 Status400(models::PveError),
51 Status401(models::PveError),
52 Status403(models::PveError),
53 Status404(models::PveError),
54 Status500(models::PveError),
55 Status501(models::PveError),
56 Status503(models::PveError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum AccessVerifyVncTicketError {
64 Status400(models::PveError),
65 Status401(models::PveError),
66 Status403(models::PveError),
67 Status404(models::PveError),
68 Status500(models::PveError),
69 Status501(models::PveError),
70 Status503(models::PveError),
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn access_change_password(configuration: &configuration::Configuration, access_change_password_request: models::AccessChangePasswordRequest) -> Result<models::AccessChangePasswordResponse, Error<AccessChangePasswordError>> {
77 let p_body_access_change_password_request = access_change_password_request;
79
80 let uri_str = format!("{}/access/password", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref apikey) = configuration.api_key {
87 let key = apikey.key.clone();
88 let value = match apikey.prefix {
89 Some(ref prefix) => format!("{} {}", prefix, key),
90 None => key,
91 };
92 req_builder = req_builder.header("CSRFPreventionToken", value);
93 };
94 req_builder = req_builder.json(&p_body_access_change_password_request);
95
96 let req = req_builder.build()?;
97 let resp = configuration.client.execute(req).await?;
98
99 let status = resp.status();
100 let content_type = resp
101 .headers()
102 .get("content-type")
103 .and_then(|v| v.to_str().ok())
104 .unwrap_or("application/octet-stream");
105 let content_type = super::ContentType::from(content_type);
106
107 if !status.is_client_error() && !status.is_server_error() {
108 let content = resp.text().await?;
109 match content_type {
110 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
111 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessChangePasswordResponse`"))),
112 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::AccessChangePasswordResponse`")))),
113 }
114 } else {
115 let content = resp.text().await?;
116 let entity: Option<AccessChangePasswordError> = serde_json::from_str(&content).ok();
117 Err(Error::ResponseError(ResponseContent { status, content, entity }))
118 }
119}
120
121pub async fn access_get_access(configuration: &configuration::Configuration, ) -> Result<models::AccessGetAccessResponse, Error<AccessGetAccessError>> {
123
124 let uri_str = format!("{}/access", configuration.base_path);
125 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
126
127 if let Some(ref user_agent) = configuration.user_agent {
128 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129 }
130 if let Some(ref apikey) = configuration.api_key {
131 let key = apikey.key.clone();
132 let value = match apikey.prefix {
133 Some(ref prefix) => format!("{} {}", prefix, key),
134 None => key,
135 };
136 req_builder = req_builder.header("Authorization", value);
137 };
138 if let Some(ref apikey) = configuration.api_key {
139 let key = apikey.key.clone();
140 let value = match apikey.prefix {
141 Some(ref prefix) => format!("{} {}", prefix, key),
142 None => key,
143 };
144 req_builder = req_builder.header("CSRFPreventionToken", value);
145 };
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessGetAccessResponse`"))),
163 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::AccessGetAccessResponse`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<AccessGetAccessError> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent { status, content, entity }))
169 }
170}
171
172pub async fn access_permissions(configuration: &configuration::Configuration, path: Option<&str>, userid: Option<&str>) -> Result<models::AccessPermissionsResponse, Error<AccessPermissionsError>> {
174 let p_query_path = path;
176 let p_query_userid = userid;
177
178 let uri_str = format!("{}/access/permissions", configuration.base_path);
179 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
180
181 if let Some(ref param_value) = p_query_path {
182 req_builder = req_builder.query(&[("path", ¶m_value.to_string())]);
183 }
184 if let Some(ref param_value) = p_query_userid {
185 req_builder = req_builder.query(&[("userid", ¶m_value.to_string())]);
186 }
187 if let Some(ref user_agent) = configuration.user_agent {
188 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189 }
190 if let Some(ref apikey) = configuration.api_key {
191 let key = apikey.key.clone();
192 let value = match apikey.prefix {
193 Some(ref prefix) => format!("{} {}", prefix, key),
194 None => key,
195 };
196 req_builder = req_builder.header("Authorization", value);
197 };
198 if let Some(ref apikey) = configuration.api_key {
199 let key = apikey.key.clone();
200 let value = match apikey.prefix {
201 Some(ref prefix) => format!("{} {}", prefix, key),
202 None => key,
203 };
204 req_builder = req_builder.header("CSRFPreventionToken", value);
205 };
206
207 let req = req_builder.build()?;
208 let resp = configuration.client.execute(req).await?;
209
210 let status = resp.status();
211 let content_type = resp
212 .headers()
213 .get("content-type")
214 .and_then(|v| v.to_str().ok())
215 .unwrap_or("application/octet-stream");
216 let content_type = super::ContentType::from(content_type);
217
218 if !status.is_client_error() && !status.is_server_error() {
219 let content = resp.text().await?;
220 match content_type {
221 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
222 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessPermissionsResponse`"))),
223 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::AccessPermissionsResponse`")))),
224 }
225 } else {
226 let content = resp.text().await?;
227 let entity: Option<AccessPermissionsError> = serde_json::from_str(&content).ok();
228 Err(Error::ResponseError(ResponseContent { status, content, entity }))
229 }
230}
231
232pub async fn access_verify_vnc_ticket(configuration: &configuration::Configuration, access_verify_vnc_ticket_request: models::AccessVerifyVncTicketRequest) -> Result<models::AccessVerifyVncTicketResponse, Error<AccessVerifyVncTicketError>> {
234 let p_body_access_verify_vnc_ticket_request = access_verify_vnc_ticket_request;
236
237 let uri_str = format!("{}/access/vncticket", configuration.base_path);
238 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
239
240 if let Some(ref user_agent) = configuration.user_agent {
241 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
242 }
243 req_builder = req_builder.json(&p_body_access_verify_vnc_ticket_request);
244
245 let req = req_builder.build()?;
246 let resp = configuration.client.execute(req).await?;
247
248 let status = resp.status();
249 let content_type = resp
250 .headers()
251 .get("content-type")
252 .and_then(|v| v.to_str().ok())
253 .unwrap_or("application/octet-stream");
254 let content_type = super::ContentType::from(content_type);
255
256 if !status.is_client_error() && !status.is_server_error() {
257 let content = resp.text().await?;
258 match content_type {
259 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
260 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessVerifyVncTicketResponse`"))),
261 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::AccessVerifyVncTicketResponse`")))),
262 }
263 } else {
264 let content = resp.text().await?;
265 let entity: Option<AccessVerifyVncTicketError> = serde_json::from_str(&content).ok();
266 Err(Error::ResponseError(ResponseContent { status, content, entity }))
267 }
268}
269