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 CreateJsonWebKeySetError {
22 DefaultResponse(models::ErrorOAuth2),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteJsonWebKeyError {
30 DefaultResponse(models::ErrorOAuth2),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteJsonWebKeySetError {
38 DefaultResponse(models::ErrorOAuth2),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetJsonWebKeyError {
46 DefaultResponse(models::ErrorOAuth2),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetJsonWebKeySetError {
54 DefaultResponse(models::ErrorOAuth2),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum SetJsonWebKeyError {
62 DefaultResponse(models::ErrorOAuth2),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum SetJsonWebKeySetError {
70 DefaultResponse(models::ErrorOAuth2),
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn create_json_web_key_set(configuration: &configuration::Configuration, set: &str, create_json_web_key_set: models::CreateJsonWebKeySet) -> Result<models::JsonWebKeySet, Error<CreateJsonWebKeySetError>> {
77 let p_set = set;
79 let p_create_json_web_key_set = create_json_web_key_set;
80
81 let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
82 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84 if let Some(ref user_agent) = configuration.user_agent {
85 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86 }
87 if let Some(ref token) = configuration.bearer_access_token {
88 req_builder = req_builder.bearer_auth(token.to_owned());
89 };
90 req_builder = req_builder.json(&p_create_json_web_key_set);
91
92 let req = req_builder.build()?;
93 let resp = configuration.client.execute(req).await?;
94
95 let status = resp.status();
96 let content_type = resp
97 .headers()
98 .get("content-type")
99 .and_then(|v| v.to_str().ok())
100 .unwrap_or("application/octet-stream");
101 let content_type = super::ContentType::from(content_type);
102
103 if !status.is_client_error() && !status.is_server_error() {
104 let content = resp.text().await?;
105 match content_type {
106 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
108 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::JsonWebKeySet`")))),
109 }
110 } else {
111 let content = resp.text().await?;
112 let entity: Option<CreateJsonWebKeySetError> = serde_json::from_str(&content).ok();
113 Err(Error::ResponseError(ResponseContent { status, content, entity }))
114 }
115}
116
117pub async fn delete_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<(), Error<DeleteJsonWebKeyError>> {
119 let p_set = set;
121 let p_kid = kid;
122
123 let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
124 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
125
126 if let Some(ref user_agent) = configuration.user_agent {
127 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128 }
129 if let Some(ref token) = configuration.bearer_access_token {
130 req_builder = req_builder.bearer_auth(token.to_owned());
131 };
132
133 let req = req_builder.build()?;
134 let resp = configuration.client.execute(req).await?;
135
136 let status = resp.status();
137
138 if !status.is_client_error() && !status.is_server_error() {
139 Ok(())
140 } else {
141 let content = resp.text().await?;
142 let entity: Option<DeleteJsonWebKeyError> = serde_json::from_str(&content).ok();
143 Err(Error::ResponseError(ResponseContent { status, content, entity }))
144 }
145}
146
147pub async fn delete_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<(), Error<DeleteJsonWebKeySetError>> {
149 let p_set = set;
151
152 let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
153 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
154
155 if let Some(ref user_agent) = configuration.user_agent {
156 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157 }
158 if let Some(ref token) = configuration.bearer_access_token {
159 req_builder = req_builder.bearer_auth(token.to_owned());
160 };
161
162 let req = req_builder.build()?;
163 let resp = configuration.client.execute(req).await?;
164
165 let status = resp.status();
166
167 if !status.is_client_error() && !status.is_server_error() {
168 Ok(())
169 } else {
170 let content = resp.text().await?;
171 let entity: Option<DeleteJsonWebKeySetError> = serde_json::from_str(&content).ok();
172 Err(Error::ResponseError(ResponseContent { status, content, entity }))
173 }
174}
175
176pub async fn get_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeyError>> {
178 let p_set = set;
180 let p_kid = kid;
181
182 let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
183 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185 if let Some(ref user_agent) = configuration.user_agent {
186 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187 }
188 if let Some(ref token) = configuration.bearer_access_token {
189 req_builder = req_builder.bearer_auth(token.to_owned());
190 };
191
192 let req = req_builder.build()?;
193 let resp = configuration.client.execute(req).await?;
194
195 let status = resp.status();
196 let content_type = resp
197 .headers()
198 .get("content-type")
199 .and_then(|v| v.to_str().ok())
200 .unwrap_or("application/octet-stream");
201 let content_type = super::ContentType::from(content_type);
202
203 if !status.is_client_error() && !status.is_server_error() {
204 let content = resp.text().await?;
205 match content_type {
206 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
208 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::JsonWebKeySet`")))),
209 }
210 } else {
211 let content = resp.text().await?;
212 let entity: Option<GetJsonWebKeyError> = serde_json::from_str(&content).ok();
213 Err(Error::ResponseError(ResponseContent { status, content, entity }))
214 }
215}
216
217pub async fn get_json_web_key_set(configuration: &configuration::Configuration, set: &str) -> Result<models::JsonWebKeySet, Error<GetJsonWebKeySetError>> {
219 let p_set = set;
221
222 let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
223 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
224
225 if let Some(ref user_agent) = configuration.user_agent {
226 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
227 }
228 if let Some(ref token) = configuration.bearer_access_token {
229 req_builder = req_builder.bearer_auth(token.to_owned());
230 };
231
232 let req = req_builder.build()?;
233 let resp = configuration.client.execute(req).await?;
234
235 let status = resp.status();
236 let content_type = resp
237 .headers()
238 .get("content-type")
239 .and_then(|v| v.to_str().ok())
240 .unwrap_or("application/octet-stream");
241 let content_type = super::ContentType::from(content_type);
242
243 if !status.is_client_error() && !status.is_server_error() {
244 let content = resp.text().await?;
245 match content_type {
246 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
247 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
248 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::JsonWebKeySet`")))),
249 }
250 } else {
251 let content = resp.text().await?;
252 let entity: Option<GetJsonWebKeySetError> = serde_json::from_str(&content).ok();
253 Err(Error::ResponseError(ResponseContent { status, content, entity }))
254 }
255}
256
257pub async fn set_json_web_key(configuration: &configuration::Configuration, set: &str, kid: &str, json_web_key: Option<models::JsonWebKey>) -> Result<models::JsonWebKey, Error<SetJsonWebKeyError>> {
259 let p_set = set;
261 let p_kid = kid;
262 let p_json_web_key = json_web_key;
263
264 let uri_str = format!("{}/admin/keys/{set}/{kid}", configuration.base_path, set=crate::apis::urlencode(p_set), kid=crate::apis::urlencode(p_kid));
265 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
266
267 if let Some(ref user_agent) = configuration.user_agent {
268 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
269 }
270 if let Some(ref token) = configuration.bearer_access_token {
271 req_builder = req_builder.bearer_auth(token.to_owned());
272 };
273 req_builder = req_builder.json(&p_json_web_key);
274
275 let req = req_builder.build()?;
276 let resp = configuration.client.execute(req).await?;
277
278 let status = resp.status();
279 let content_type = resp
280 .headers()
281 .get("content-type")
282 .and_then(|v| v.to_str().ok())
283 .unwrap_or("application/octet-stream");
284 let content_type = super::ContentType::from(content_type);
285
286 if !status.is_client_error() && !status.is_server_error() {
287 let content = resp.text().await?;
288 match content_type {
289 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKey`"))),
291 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::JsonWebKey`")))),
292 }
293 } else {
294 let content = resp.text().await?;
295 let entity: Option<SetJsonWebKeyError> = serde_json::from_str(&content).ok();
296 Err(Error::ResponseError(ResponseContent { status, content, entity }))
297 }
298}
299
300pub async fn set_json_web_key_set(configuration: &configuration::Configuration, set: &str, json_web_key_set: Option<models::JsonWebKeySet>) -> Result<models::JsonWebKeySet, Error<SetJsonWebKeySetError>> {
302 let p_set = set;
304 let p_json_web_key_set = json_web_key_set;
305
306 let uri_str = format!("{}/admin/keys/{set}", configuration.base_path, set=crate::apis::urlencode(p_set));
307 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
308
309 if let Some(ref user_agent) = configuration.user_agent {
310 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
311 }
312 if let Some(ref token) = configuration.bearer_access_token {
313 req_builder = req_builder.bearer_auth(token.to_owned());
314 };
315 req_builder = req_builder.json(&p_json_web_key_set);
316
317 let req = req_builder.build()?;
318 let resp = configuration.client.execute(req).await?;
319
320 let status = resp.status();
321 let content_type = resp
322 .headers()
323 .get("content-type")
324 .and_then(|v| v.to_str().ok())
325 .unwrap_or("application/octet-stream");
326 let content_type = super::ContentType::from(content_type);
327
328 if !status.is_client_error() && !status.is_server_error() {
329 let content = resp.text().await?;
330 match content_type {
331 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
332 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
333 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::JsonWebKeySet`")))),
334 }
335 } else {
336 let content = resp.text().await?;
337 let entity: Option<SetJsonWebKeySetError> = serde_json::from_str(&content).ok();
338 Err(Error::ResponseError(ResponseContent { status, content, entity }))
339 }
340}
341