1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait PolicyEditorBetaApi: Send + Sync {
23 async fn get_active_policy(
31 &self,
32 ) -> Result<models::PolicyAndValidationResponse, Error<GetActivePolicyError>>;
33
34 async fn get_draft(
42 &self,
43 ) -> Result<models::DraftReviewAndValidationResponse, Error<GetDraftError>>;
44
45 async fn publish_draft(
54 &self,
55 params: PublishDraftParams,
56 ) -> Result<models::PublishResult, Error<PublishDraftError>>;
57
58 async fn publish_policy_rules(
67 &self,
68 params: PublishPolicyRulesParams,
69 ) -> Result<models::PublishResult, Error<PublishPolicyRulesError>>;
70
71 async fn update_draft(
75 &self,
76 params: UpdateDraftParams,
77 ) -> Result<models::DraftReviewAndValidationResponse, Error<UpdateDraftError>>;
78}
79
80pub struct PolicyEditorBetaApiClient {
81 configuration: Arc<configuration::Configuration>,
82}
83
84impl PolicyEditorBetaApiClient {
85 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
86 Self { configuration }
87 }
88}
89
90#[derive(Clone, Debug)]
93#[cfg_attr(feature = "bon", derive(::bon::Builder))]
94pub struct PublishDraftParams {
95 pub publish_draft_request_v2: models::PublishDraftRequestV2,
96 pub idempotency_key: Option<String>,
101}
102
103#[derive(Clone, Debug)]
106#[cfg_attr(feature = "bon", derive(::bon::Builder))]
107pub struct PublishPolicyRulesParams {
108 pub policy_rules: models::PolicyRules,
109 pub idempotency_key: Option<String>,
114}
115
116#[derive(Clone, Debug)]
119#[cfg_attr(feature = "bon", derive(::bon::Builder))]
120pub struct UpdateDraftParams {
121 pub policy_rules: models::PolicyRules,
122 pub idempotency_key: Option<String>,
127}
128
129#[async_trait]
130impl PolicyEditorBetaApi for PolicyEditorBetaApiClient {
131 async fn get_active_policy(
137 &self,
138 ) -> Result<models::PolicyAndValidationResponse, Error<GetActivePolicyError>> {
139 let local_var_configuration = &self.configuration;
140
141 let local_var_client = &local_var_configuration.client;
142
143 let local_var_uri_str = format!("{}/tap/active_policy", local_var_configuration.base_path);
144 let mut local_var_req_builder =
145 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
146
147 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148 local_var_req_builder = local_var_req_builder
149 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
150 }
151
152 let local_var_req = local_var_req_builder.build()?;
153 let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155 let local_var_status = local_var_resp.status();
156 let local_var_content_type = local_var_resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let local_var_content_type = super::ContentType::from(local_var_content_type);
162 let local_var_content = local_var_resp.text().await?;
163
164 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165 match local_var_content_type {
166 ContentType::Json => {
167 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
168 }
169 ContentType::Text => {
170 return Err(Error::from(serde_json::Error::custom(
171 "Received `text/plain` content type response that cannot be converted to \
172 `models::PolicyAndValidationResponse`",
173 )));
174 }
175 ContentType::Unsupported(local_var_unknown_type) => {
176 return Err(Error::from(serde_json::Error::custom(format!(
177 "Received `{local_var_unknown_type}` content type response that cannot be \
178 converted to `models::PolicyAndValidationResponse`"
179 ))));
180 }
181 }
182 } else {
183 let local_var_entity: Option<GetActivePolicyError> =
184 serde_json::from_str(&local_var_content).ok();
185 let local_var_error = ResponseContent {
186 status: local_var_status,
187 content: local_var_content,
188 entity: local_var_entity,
189 };
190 Err(Error::ResponseError(local_var_error))
191 }
192 }
193
194 async fn get_draft(
200 &self,
201 ) -> Result<models::DraftReviewAndValidationResponse, Error<GetDraftError>> {
202 let local_var_configuration = &self.configuration;
203
204 let local_var_client = &local_var_configuration.client;
205
206 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
207 let mut local_var_req_builder =
208 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
209
210 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
211 local_var_req_builder = local_var_req_builder
212 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
213 }
214
215 let local_var_req = local_var_req_builder.build()?;
216 let local_var_resp = local_var_client.execute(local_var_req).await?;
217
218 let local_var_status = local_var_resp.status();
219 let local_var_content_type = local_var_resp
220 .headers()
221 .get("content-type")
222 .and_then(|v| v.to_str().ok())
223 .unwrap_or("application/octet-stream");
224 let local_var_content_type = super::ContentType::from(local_var_content_type);
225 let local_var_content = local_var_resp.text().await?;
226
227 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228 match local_var_content_type {
229 ContentType::Json => {
230 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
231 }
232 ContentType::Text => {
233 return Err(Error::from(serde_json::Error::custom(
234 "Received `text/plain` content type response that cannot be converted to \
235 `models::DraftReviewAndValidationResponse`",
236 )));
237 }
238 ContentType::Unsupported(local_var_unknown_type) => {
239 return Err(Error::from(serde_json::Error::custom(format!(
240 "Received `{local_var_unknown_type}` content type response that cannot be \
241 converted to `models::DraftReviewAndValidationResponse`"
242 ))));
243 }
244 }
245 } else {
246 let local_var_entity: Option<GetDraftError> =
247 serde_json::from_str(&local_var_content).ok();
248 let local_var_error = ResponseContent {
249 status: local_var_status,
250 content: local_var_content,
251 entity: local_var_entity,
252 };
253 Err(Error::ResponseError(local_var_error))
254 }
255 }
256
257 async fn publish_draft(
264 &self,
265 params: PublishDraftParams,
266 ) -> Result<models::PublishResult, Error<PublishDraftError>> {
267 let PublishDraftParams {
268 publish_draft_request_v2,
269 idempotency_key,
270 } = params;
271
272 let local_var_configuration = &self.configuration;
273
274 let local_var_client = &local_var_configuration.client;
275
276 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
277 let mut local_var_req_builder =
278 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
279
280 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
281 local_var_req_builder = local_var_req_builder
282 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283 }
284 if let Some(local_var_param_value) = idempotency_key {
285 local_var_req_builder =
286 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
287 }
288 local_var_req_builder = local_var_req_builder.json(&publish_draft_request_v2);
289
290 let local_var_req = local_var_req_builder.build()?;
291 let local_var_resp = local_var_client.execute(local_var_req).await?;
292
293 let local_var_status = local_var_resp.status();
294 let local_var_content_type = local_var_resp
295 .headers()
296 .get("content-type")
297 .and_then(|v| v.to_str().ok())
298 .unwrap_or("application/octet-stream");
299 let local_var_content_type = super::ContentType::from(local_var_content_type);
300 let local_var_content = local_var_resp.text().await?;
301
302 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303 match local_var_content_type {
304 ContentType::Json => {
305 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
306 }
307 ContentType::Text => {
308 return Err(Error::from(serde_json::Error::custom(
309 "Received `text/plain` content type response that cannot be converted to \
310 `models::PublishResult`",
311 )));
312 }
313 ContentType::Unsupported(local_var_unknown_type) => {
314 return Err(Error::from(serde_json::Error::custom(format!(
315 "Received `{local_var_unknown_type}` content type response that cannot be \
316 converted to `models::PublishResult`"
317 ))));
318 }
319 }
320 } else {
321 let local_var_entity: Option<PublishDraftError> =
322 serde_json::from_str(&local_var_content).ok();
323 let local_var_error = ResponseContent {
324 status: local_var_status,
325 content: local_var_content,
326 entity: local_var_entity,
327 };
328 Err(Error::ResponseError(local_var_error))
329 }
330 }
331
332 async fn publish_policy_rules(
339 &self,
340 params: PublishPolicyRulesParams,
341 ) -> Result<models::PublishResult, Error<PublishPolicyRulesError>> {
342 let PublishPolicyRulesParams {
343 policy_rules,
344 idempotency_key,
345 } = params;
346
347 let local_var_configuration = &self.configuration;
348
349 let local_var_client = &local_var_configuration.client;
350
351 let local_var_uri_str = format!("{}/tap/publish", local_var_configuration.base_path);
352 let mut local_var_req_builder =
353 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
354
355 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
356 local_var_req_builder = local_var_req_builder
357 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
358 }
359 if let Some(local_var_param_value) = idempotency_key {
360 local_var_req_builder =
361 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
362 }
363 local_var_req_builder = local_var_req_builder.json(&policy_rules);
364
365 let local_var_req = local_var_req_builder.build()?;
366 let local_var_resp = local_var_client.execute(local_var_req).await?;
367
368 let local_var_status = local_var_resp.status();
369 let local_var_content_type = local_var_resp
370 .headers()
371 .get("content-type")
372 .and_then(|v| v.to_str().ok())
373 .unwrap_or("application/octet-stream");
374 let local_var_content_type = super::ContentType::from(local_var_content_type);
375 let local_var_content = local_var_resp.text().await?;
376
377 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
378 match local_var_content_type {
379 ContentType::Json => {
380 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
381 }
382 ContentType::Text => {
383 return Err(Error::from(serde_json::Error::custom(
384 "Received `text/plain` content type response that cannot be converted to \
385 `models::PublishResult`",
386 )));
387 }
388 ContentType::Unsupported(local_var_unknown_type) => {
389 return Err(Error::from(serde_json::Error::custom(format!(
390 "Received `{local_var_unknown_type}` content type response that cannot be \
391 converted to `models::PublishResult`"
392 ))));
393 }
394 }
395 } else {
396 let local_var_entity: Option<PublishPolicyRulesError> =
397 serde_json::from_str(&local_var_content).ok();
398 let local_var_error = ResponseContent {
399 status: local_var_status,
400 content: local_var_content,
401 entity: local_var_entity,
402 };
403 Err(Error::ResponseError(local_var_error))
404 }
405 }
406
407 async fn update_draft(
409 &self,
410 params: UpdateDraftParams,
411 ) -> Result<models::DraftReviewAndValidationResponse, Error<UpdateDraftError>> {
412 let UpdateDraftParams {
413 policy_rules,
414 idempotency_key,
415 } = params;
416
417 let local_var_configuration = &self.configuration;
418
419 let local_var_client = &local_var_configuration.client;
420
421 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
422 let mut local_var_req_builder =
423 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
424
425 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
426 local_var_req_builder = local_var_req_builder
427 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
428 }
429 if let Some(local_var_param_value) = idempotency_key {
430 local_var_req_builder =
431 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
432 }
433 local_var_req_builder = local_var_req_builder.json(&policy_rules);
434
435 let local_var_req = local_var_req_builder.build()?;
436 let local_var_resp = local_var_client.execute(local_var_req).await?;
437
438 let local_var_status = local_var_resp.status();
439 let local_var_content_type = local_var_resp
440 .headers()
441 .get("content-type")
442 .and_then(|v| v.to_str().ok())
443 .unwrap_or("application/octet-stream");
444 let local_var_content_type = super::ContentType::from(local_var_content_type);
445 let local_var_content = local_var_resp.text().await?;
446
447 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
448 match local_var_content_type {
449 ContentType::Json => {
450 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
451 }
452 ContentType::Text => {
453 return Err(Error::from(serde_json::Error::custom(
454 "Received `text/plain` content type response that cannot be converted to \
455 `models::DraftReviewAndValidationResponse`",
456 )));
457 }
458 ContentType::Unsupported(local_var_unknown_type) => {
459 return Err(Error::from(serde_json::Error::custom(format!(
460 "Received `{local_var_unknown_type}` content type response that cannot be \
461 converted to `models::DraftReviewAndValidationResponse`"
462 ))));
463 }
464 }
465 } else {
466 let local_var_entity: Option<UpdateDraftError> =
467 serde_json::from_str(&local_var_content).ok();
468 let local_var_error = ResponseContent {
469 status: local_var_status,
470 content: local_var_content,
471 entity: local_var_entity,
472 };
473 Err(Error::ResponseError(local_var_error))
474 }
475 }
476}
477
478#[derive(Debug, Clone, Serialize, Deserialize)]
480#[serde(untagged)]
481pub enum GetActivePolicyError {
482 DefaultResponse(models::ErrorSchema),
483 UnknownValue(serde_json::Value),
484}
485
486#[derive(Debug, Clone, Serialize, Deserialize)]
488#[serde(untagged)]
489pub enum GetDraftError {
490 DefaultResponse(models::ErrorSchema),
491 UnknownValue(serde_json::Value),
492}
493
494#[derive(Debug, Clone, Serialize, Deserialize)]
496#[serde(untagged)]
497pub enum PublishDraftError {
498 DefaultResponse(models::ErrorSchema),
499 UnknownValue(serde_json::Value),
500}
501
502#[derive(Debug, Clone, Serialize, Deserialize)]
505#[serde(untagged)]
506pub enum PublishPolicyRulesError {
507 DefaultResponse(models::ErrorSchema),
508 UnknownValue(serde_json::Value),
509}
510
511#[derive(Debug, Clone, Serialize, Deserialize)]
513#[serde(untagged)]
514pub enum UpdateDraftError {
515 DefaultResponse(models::ErrorSchema),
516 UnknownValue(serde_json::Value),
517}