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)]
92#[cfg_attr(feature = "bon", derive(::bon::Builder))]
93pub struct PublishDraftParams {
94 pub publish_draft_request: models::PublishDraftRequest,
95 pub idempotency_key: Option<String>,
100}
101
102#[derive(Clone, Debug)]
104#[cfg_attr(feature = "bon", derive(::bon::Builder))]
105pub struct PublishPolicyRulesParams {
106 pub policy_rules: models::PolicyRules,
107 pub idempotency_key: Option<String>,
112}
113
114#[derive(Clone, Debug)]
116#[cfg_attr(feature = "bon", derive(::bon::Builder))]
117pub struct UpdateDraftParams {
118 pub policy_rules: models::PolicyRules,
119 pub idempotency_key: Option<String>,
124}
125
126#[async_trait]
127impl PolicyEditorBetaApi for PolicyEditorBetaApiClient {
128 async fn get_active_policy(
134 &self,
135 ) -> Result<models::PolicyAndValidationResponse, Error<GetActivePolicyError>> {
136 let local_var_configuration = &self.configuration;
137
138 let local_var_client = &local_var_configuration.client;
139
140 let local_var_uri_str = format!("{}/tap/active_policy", local_var_configuration.base_path);
141 let mut local_var_req_builder =
142 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
143
144 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145 local_var_req_builder = local_var_req_builder
146 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148
149 let local_var_req = local_var_req_builder.build()?;
150 let local_var_resp = local_var_client.execute(local_var_req).await?;
151
152 let local_var_status = local_var_resp.status();
153 let local_var_content_type = local_var_resp
154 .headers()
155 .get("content-type")
156 .and_then(|v| v.to_str().ok())
157 .unwrap_or("application/octet-stream");
158 let local_var_content_type = super::ContentType::from(local_var_content_type);
159 let local_var_content = local_var_resp.text().await?;
160
161 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162 match local_var_content_type {
163 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
164 ContentType::Text => {
165 return Err(Error::from(serde_json::Error::custom(
166 "Received `text/plain` content type response that cannot be converted to \
167 `models::PolicyAndValidationResponse`",
168 )));
169 }
170 ContentType::Unsupported(local_var_unknown_type) => {
171 return Err(Error::from(serde_json::Error::custom(format!(
172 "Received `{local_var_unknown_type}` content type response that cannot be \
173 converted to `models::PolicyAndValidationResponse`"
174 ))));
175 }
176 }
177 } else {
178 let local_var_entity: Option<GetActivePolicyError> =
179 serde_json::from_str(&local_var_content).ok();
180 let local_var_error = ResponseContent {
181 status: local_var_status,
182 content: local_var_content,
183 entity: local_var_entity,
184 };
185 Err(Error::ResponseError(local_var_error))
186 }
187 }
188
189 async fn get_draft(
195 &self,
196 ) -> Result<models::DraftReviewAndValidationResponse, Error<GetDraftError>> {
197 let local_var_configuration = &self.configuration;
198
199 let local_var_client = &local_var_configuration.client;
200
201 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
202 let mut local_var_req_builder =
203 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
204
205 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
206 local_var_req_builder = local_var_req_builder
207 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
208 }
209
210 let local_var_req = local_var_req_builder.build()?;
211 let local_var_resp = local_var_client.execute(local_var_req).await?;
212
213 let local_var_status = local_var_resp.status();
214 let local_var_content_type = local_var_resp
215 .headers()
216 .get("content-type")
217 .and_then(|v| v.to_str().ok())
218 .unwrap_or("application/octet-stream");
219 let local_var_content_type = super::ContentType::from(local_var_content_type);
220 let local_var_content = local_var_resp.text().await?;
221
222 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
223 match local_var_content_type {
224 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
225 ContentType::Text => {
226 return Err(Error::from(serde_json::Error::custom(
227 "Received `text/plain` content type response that cannot be converted to \
228 `models::DraftReviewAndValidationResponse`",
229 )));
230 }
231 ContentType::Unsupported(local_var_unknown_type) => {
232 return Err(Error::from(serde_json::Error::custom(format!(
233 "Received `{local_var_unknown_type}` content type response that cannot be \
234 converted to `models::DraftReviewAndValidationResponse`"
235 ))));
236 }
237 }
238 } else {
239 let local_var_entity: Option<GetDraftError> =
240 serde_json::from_str(&local_var_content).ok();
241 let local_var_error = ResponseContent {
242 status: local_var_status,
243 content: local_var_content,
244 entity: local_var_entity,
245 };
246 Err(Error::ResponseError(local_var_error))
247 }
248 }
249
250 async fn publish_draft(
257 &self,
258 params: PublishDraftParams,
259 ) -> Result<models::PublishResult, Error<PublishDraftError>> {
260 let PublishDraftParams {
261 publish_draft_request,
262 idempotency_key,
263 } = params;
264
265 let local_var_configuration = &self.configuration;
266
267 let local_var_client = &local_var_configuration.client;
268
269 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
270 let mut local_var_req_builder =
271 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
272
273 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
274 local_var_req_builder = local_var_req_builder
275 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
276 }
277 if let Some(local_var_param_value) = idempotency_key {
278 local_var_req_builder =
279 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
280 }
281 local_var_req_builder = local_var_req_builder.json(&publish_draft_request);
282
283 let local_var_req = local_var_req_builder.build()?;
284 let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286 let local_var_status = local_var_resp.status();
287 let local_var_content_type = local_var_resp
288 .headers()
289 .get("content-type")
290 .and_then(|v| v.to_str().ok())
291 .unwrap_or("application/octet-stream");
292 let local_var_content_type = super::ContentType::from(local_var_content_type);
293 let local_var_content = local_var_resp.text().await?;
294
295 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296 match local_var_content_type {
297 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
298 ContentType::Text => {
299 return Err(Error::from(serde_json::Error::custom(
300 "Received `text/plain` content type response that cannot be converted to \
301 `models::PublishResult`",
302 )));
303 }
304 ContentType::Unsupported(local_var_unknown_type) => {
305 return Err(Error::from(serde_json::Error::custom(format!(
306 "Received `{local_var_unknown_type}` content type response that cannot be \
307 converted to `models::PublishResult`"
308 ))));
309 }
310 }
311 } else {
312 let local_var_entity: Option<PublishDraftError> =
313 serde_json::from_str(&local_var_content).ok();
314 let local_var_error = ResponseContent {
315 status: local_var_status,
316 content: local_var_content,
317 entity: local_var_entity,
318 };
319 Err(Error::ResponseError(local_var_error))
320 }
321 }
322
323 async fn publish_policy_rules(
330 &self,
331 params: PublishPolicyRulesParams,
332 ) -> Result<models::PublishResult, Error<PublishPolicyRulesError>> {
333 let PublishPolicyRulesParams {
334 policy_rules,
335 idempotency_key,
336 } = params;
337
338 let local_var_configuration = &self.configuration;
339
340 let local_var_client = &local_var_configuration.client;
341
342 let local_var_uri_str = format!("{}/tap/publish", local_var_configuration.base_path);
343 let mut local_var_req_builder =
344 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
345
346 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
347 local_var_req_builder = local_var_req_builder
348 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
349 }
350 if let Some(local_var_param_value) = idempotency_key {
351 local_var_req_builder =
352 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
353 }
354 local_var_req_builder = local_var_req_builder.json(&policy_rules);
355
356 let local_var_req = local_var_req_builder.build()?;
357 let local_var_resp = local_var_client.execute(local_var_req).await?;
358
359 let local_var_status = local_var_resp.status();
360 let local_var_content_type = local_var_resp
361 .headers()
362 .get("content-type")
363 .and_then(|v| v.to_str().ok())
364 .unwrap_or("application/octet-stream");
365 let local_var_content_type = super::ContentType::from(local_var_content_type);
366 let local_var_content = local_var_resp.text().await?;
367
368 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
369 match local_var_content_type {
370 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
371 ContentType::Text => {
372 return Err(Error::from(serde_json::Error::custom(
373 "Received `text/plain` content type response that cannot be converted to \
374 `models::PublishResult`",
375 )));
376 }
377 ContentType::Unsupported(local_var_unknown_type) => {
378 return Err(Error::from(serde_json::Error::custom(format!(
379 "Received `{local_var_unknown_type}` content type response that cannot be \
380 converted to `models::PublishResult`"
381 ))));
382 }
383 }
384 } else {
385 let local_var_entity: Option<PublishPolicyRulesError> =
386 serde_json::from_str(&local_var_content).ok();
387 let local_var_error = ResponseContent {
388 status: local_var_status,
389 content: local_var_content,
390 entity: local_var_entity,
391 };
392 Err(Error::ResponseError(local_var_error))
393 }
394 }
395
396 async fn update_draft(
398 &self,
399 params: UpdateDraftParams,
400 ) -> Result<models::DraftReviewAndValidationResponse, Error<UpdateDraftError>> {
401 let UpdateDraftParams {
402 policy_rules,
403 idempotency_key,
404 } = params;
405
406 let local_var_configuration = &self.configuration;
407
408 let local_var_client = &local_var_configuration.client;
409
410 let local_var_uri_str = format!("{}/tap/draft", local_var_configuration.base_path);
411 let mut local_var_req_builder =
412 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
413
414 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
415 local_var_req_builder = local_var_req_builder
416 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
417 }
418 if let Some(local_var_param_value) = idempotency_key {
419 local_var_req_builder =
420 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
421 }
422 local_var_req_builder = local_var_req_builder.json(&policy_rules);
423
424 let local_var_req = local_var_req_builder.build()?;
425 let local_var_resp = local_var_client.execute(local_var_req).await?;
426
427 let local_var_status = local_var_resp.status();
428 let local_var_content_type = local_var_resp
429 .headers()
430 .get("content-type")
431 .and_then(|v| v.to_str().ok())
432 .unwrap_or("application/octet-stream");
433 let local_var_content_type = super::ContentType::from(local_var_content_type);
434 let local_var_content = local_var_resp.text().await?;
435
436 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
437 match local_var_content_type {
438 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
439 ContentType::Text => {
440 return Err(Error::from(serde_json::Error::custom(
441 "Received `text/plain` content type response that cannot be converted to \
442 `models::DraftReviewAndValidationResponse`",
443 )));
444 }
445 ContentType::Unsupported(local_var_unknown_type) => {
446 return Err(Error::from(serde_json::Error::custom(format!(
447 "Received `{local_var_unknown_type}` content type response that cannot be \
448 converted to `models::DraftReviewAndValidationResponse`"
449 ))));
450 }
451 }
452 } else {
453 let local_var_entity: Option<UpdateDraftError> =
454 serde_json::from_str(&local_var_content).ok();
455 let local_var_error = ResponseContent {
456 status: local_var_status,
457 content: local_var_content,
458 entity: local_var_entity,
459 };
460 Err(Error::ResponseError(local_var_error))
461 }
462 }
463}
464
465#[derive(Debug, Clone, Serialize, Deserialize)]
467#[serde(untagged)]
468pub enum GetActivePolicyError {
469 DefaultResponse(models::ErrorSchema),
470 UnknownValue(serde_json::Value),
471}
472
473#[derive(Debug, Clone, Serialize, Deserialize)]
475#[serde(untagged)]
476pub enum GetDraftError {
477 DefaultResponse(models::ErrorSchema),
478 UnknownValue(serde_json::Value),
479}
480
481#[derive(Debug, Clone, Serialize, Deserialize)]
483#[serde(untagged)]
484pub enum PublishDraftError {
485 DefaultResponse(models::ErrorSchema),
486 UnknownValue(serde_json::Value),
487}
488
489#[derive(Debug, Clone, Serialize, Deserialize)]
491#[serde(untagged)]
492pub enum PublishPolicyRulesError {
493 DefaultResponse(models::ErrorSchema),
494 UnknownValue(serde_json::Value),
495}
496
497#[derive(Debug, Clone, Serialize, Deserialize)]
499#[serde(untagged)]
500pub enum UpdateDraftError {
501 DefaultResponse(models::ErrorSchema),
502 UnknownValue(serde_json::Value),
503}