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 PolicyEditorV2BetaApi: Send + Sync {
23 async fn get_active_v2_policy(
29 &self,
30 params: GetActiveV2PolicyParams,
31 ) -> Result<models::PolicyAndValidationResponseV2, Error<GetActiveV2PolicyError>>;
32
33 async fn get_v2_draft(
39 &self,
40 params: GetV2DraftParams,
41 ) -> Result<models::DraftReviewAndValidationResponseV2, Error<GetV2DraftError>>;
42
43 async fn publish_v2_draft(
51 &self,
52 params: PublishV2DraftParams,
53 ) -> Result<models::PublishResultV2, Error<PublishV2DraftError>>;
54
55 async fn update_v2_draft(
61 &self,
62 params: UpdateV2DraftParams,
63 ) -> Result<models::DraftReviewAndValidationResponseV2, Error<UpdateV2DraftError>>;
64}
65
66pub struct PolicyEditorV2BetaApiClient {
67 configuration: Arc<configuration::Configuration>,
68}
69
70impl PolicyEditorV2BetaApiClient {
71 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
72 Self { configuration }
73 }
74}
75
76#[derive(Clone, Debug)]
79#[cfg_attr(feature = "bon", derive(::bon::Builder))]
80pub struct GetActiveV2PolicyParams {
81 pub policy_type: models::PolicyTypeV2,
84}
85
86#[derive(Clone, Debug)]
89#[cfg_attr(feature = "bon", derive(::bon::Builder))]
90pub struct GetV2DraftParams {
91 pub policy_type: models::PolicyTypeV2,
94}
95
96#[derive(Clone, Debug)]
99#[cfg_attr(feature = "bon", derive(::bon::Builder))]
100pub struct PublishV2DraftParams {
101 pub publish_draft_request_v2: models::PublishDraftRequestV2,
102 pub idempotency_key: Option<String>,
107}
108
109#[derive(Clone, Debug)]
112#[cfg_attr(feature = "bon", derive(::bon::Builder))]
113pub struct UpdateV2DraftParams {
114 pub update_draft_request_v2: models::UpdateDraftRequestV2,
115 pub idempotency_key: Option<String>,
120}
121
122#[async_trait]
123impl PolicyEditorV2BetaApi for PolicyEditorV2BetaApiClient {
124 async fn get_active_v2_policy(
128 &self,
129 params: GetActiveV2PolicyParams,
130 ) -> Result<models::PolicyAndValidationResponseV2, Error<GetActiveV2PolicyError>> {
131 let GetActiveV2PolicyParams { policy_type } = params;
132
133 let local_var_configuration = &self.configuration;
134
135 let local_var_client = &local_var_configuration.client;
136
137 let local_var_uri_str =
138 format!("{}/policy/active_policy", local_var_configuration.base_path);
139 let mut local_var_req_builder =
140 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
141
142 local_var_req_builder =
143 local_var_req_builder.query(&[("policyType", &policy_type.to_string())]);
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 => {
164 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
165 }
166 ContentType::Text => {
167 return Err(Error::from(serde_json::Error::custom(
168 "Received `text/plain` content type response that cannot be converted to \
169 `models::PolicyAndValidationResponseV2`",
170 )));
171 }
172 ContentType::Unsupported(local_var_unknown_type) => {
173 return Err(Error::from(serde_json::Error::custom(format!(
174 "Received `{local_var_unknown_type}` content type response that cannot be \
175 converted to `models::PolicyAndValidationResponseV2`"
176 ))));
177 }
178 }
179 } else {
180 let local_var_entity: Option<GetActiveV2PolicyError> =
181 serde_json::from_str(&local_var_content).ok();
182 let local_var_error = ResponseContent {
183 status: local_var_status,
184 content: local_var_content,
185 entity: local_var_entity,
186 };
187 Err(Error::ResponseError(local_var_error))
188 }
189 }
190
191 async fn get_v2_draft(
195 &self,
196 params: GetV2DraftParams,
197 ) -> Result<models::DraftReviewAndValidationResponseV2, Error<GetV2DraftError>> {
198 let GetV2DraftParams { policy_type } = params;
199
200 let local_var_configuration = &self.configuration;
201
202 let local_var_client = &local_var_configuration.client;
203
204 let local_var_uri_str = format!("{}/policy/draft", local_var_configuration.base_path);
205 let mut local_var_req_builder =
206 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
207
208 local_var_req_builder =
209 local_var_req_builder.query(&[("policyType", &policy_type.to_string())]);
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::DraftReviewAndValidationResponseV2`",
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::DraftReviewAndValidationResponseV2`"
242 ))));
243 }
244 }
245 } else {
246 let local_var_entity: Option<GetV2DraftError> =
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_v2_draft(
263 &self,
264 params: PublishV2DraftParams,
265 ) -> Result<models::PublishResultV2, Error<PublishV2DraftError>> {
266 let PublishV2DraftParams {
267 publish_draft_request_v2,
268 idempotency_key,
269 } = params;
270
271 let local_var_configuration = &self.configuration;
272
273 let local_var_client = &local_var_configuration.client;
274
275 let local_var_uri_str = format!("{}/policy/draft", local_var_configuration.base_path);
276 let mut local_var_req_builder =
277 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
278
279 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
280 local_var_req_builder = local_var_req_builder
281 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
282 }
283 if let Some(local_var_param_value) = idempotency_key {
284 local_var_req_builder =
285 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
286 }
287 local_var_req_builder = local_var_req_builder.json(&publish_draft_request_v2);
288
289 let local_var_req = local_var_req_builder.build()?;
290 let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292 let local_var_status = local_var_resp.status();
293 let local_var_content_type = local_var_resp
294 .headers()
295 .get("content-type")
296 .and_then(|v| v.to_str().ok())
297 .unwrap_or("application/octet-stream");
298 let local_var_content_type = super::ContentType::from(local_var_content_type);
299 let local_var_content = local_var_resp.text().await?;
300
301 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
302 match local_var_content_type {
303 ContentType::Json => {
304 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
305 }
306 ContentType::Text => {
307 return Err(Error::from(serde_json::Error::custom(
308 "Received `text/plain` content type response that cannot be converted to \
309 `models::PublishResultV2`",
310 )));
311 }
312 ContentType::Unsupported(local_var_unknown_type) => {
313 return Err(Error::from(serde_json::Error::custom(format!(
314 "Received `{local_var_unknown_type}` content type response that cannot be \
315 converted to `models::PublishResultV2`"
316 ))));
317 }
318 }
319 } else {
320 let local_var_entity: Option<PublishV2DraftError> =
321 serde_json::from_str(&local_var_content).ok();
322 let local_var_error = ResponseContent {
323 status: local_var_status,
324 content: local_var_content,
325 entity: local_var_entity,
326 };
327 Err(Error::ResponseError(local_var_error))
328 }
329 }
330
331 async fn update_v2_draft(
335 &self,
336 params: UpdateV2DraftParams,
337 ) -> Result<models::DraftReviewAndValidationResponseV2, Error<UpdateV2DraftError>> {
338 let UpdateV2DraftParams {
339 update_draft_request_v2,
340 idempotency_key,
341 } = params;
342
343 let local_var_configuration = &self.configuration;
344
345 let local_var_client = &local_var_configuration.client;
346
347 let local_var_uri_str = format!("{}/policy/draft", local_var_configuration.base_path);
348 let mut local_var_req_builder =
349 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
350
351 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
352 local_var_req_builder = local_var_req_builder
353 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
354 }
355 if let Some(local_var_param_value) = idempotency_key {
356 local_var_req_builder =
357 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
358 }
359 local_var_req_builder = local_var_req_builder.json(&update_draft_request_v2);
360
361 let local_var_req = local_var_req_builder.build()?;
362 let local_var_resp = local_var_client.execute(local_var_req).await?;
363
364 let local_var_status = local_var_resp.status();
365 let local_var_content_type = local_var_resp
366 .headers()
367 .get("content-type")
368 .and_then(|v| v.to_str().ok())
369 .unwrap_or("application/octet-stream");
370 let local_var_content_type = super::ContentType::from(local_var_content_type);
371 let local_var_content = local_var_resp.text().await?;
372
373 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
374 match local_var_content_type {
375 ContentType::Json => {
376 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
377 }
378 ContentType::Text => {
379 return Err(Error::from(serde_json::Error::custom(
380 "Received `text/plain` content type response that cannot be converted to \
381 `models::DraftReviewAndValidationResponseV2`",
382 )));
383 }
384 ContentType::Unsupported(local_var_unknown_type) => {
385 return Err(Error::from(serde_json::Error::custom(format!(
386 "Received `{local_var_unknown_type}` content type response that cannot be \
387 converted to `models::DraftReviewAndValidationResponseV2`"
388 ))));
389 }
390 }
391 } else {
392 let local_var_entity: Option<UpdateV2DraftError> =
393 serde_json::from_str(&local_var_content).ok();
394 let local_var_error = ResponseContent {
395 status: local_var_status,
396 content: local_var_content,
397 entity: local_var_entity,
398 };
399 Err(Error::ResponseError(local_var_error))
400 }
401 }
402}
403
404#[derive(Debug, Clone, Serialize, Deserialize)]
407#[serde(untagged)]
408pub enum GetActiveV2PolicyError {
409 DefaultResponse(models::ErrorSchema),
410 UnknownValue(serde_json::Value),
411}
412
413#[derive(Debug, Clone, Serialize, Deserialize)]
415#[serde(untagged)]
416pub enum GetV2DraftError {
417 DefaultResponse(models::ErrorSchema),
418 UnknownValue(serde_json::Value),
419}
420
421#[derive(Debug, Clone, Serialize, Deserialize)]
424#[serde(untagged)]
425pub enum PublishV2DraftError {
426 DefaultResponse(models::ErrorSchema),
427 UnknownValue(serde_json::Value),
428}
429
430#[derive(Debug, Clone, Serialize, Deserialize)]
432#[serde(untagged)]
433pub enum UpdateV2DraftError {
434 DefaultResponse(models::ErrorSchema),
435 UnknownValue(serde_json::Value),
436}