1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::{Deserialize, Serialize};
11use std::io::Write;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateChildOrgError {
17 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
18 UnknownValue(serde_json::Value),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum DowngradeOrgError {
25 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetOrgError {
33 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ListOrgsError {
41 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UpdateOrgError {
49 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UploadIdPForOrgError {
57 APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone)]
63pub struct OrganizationsAPI {
64 config: datadog::Configuration,
65 client: reqwest_middleware::ClientWithMiddleware,
66}
67
68impl Default for OrganizationsAPI {
69 fn default() -> Self {
70 Self::with_config(datadog::Configuration::default())
71 }
72}
73
74impl OrganizationsAPI {
75 pub fn new() -> Self {
76 Self::default()
77 }
78 pub fn with_config(config: datadog::Configuration) -> Self {
79 let mut reqwest_client_builder = reqwest::Client::builder();
80
81 if let Some(proxy_url) = &config.proxy_url {
82 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
83 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
84 }
85
86 let mut middleware_client_builder =
87 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
88
89 if config.enable_retry {
90 struct RetryableStatus;
91 impl reqwest_retry::RetryableStrategy for RetryableStatus {
92 fn handle(
93 &self,
94 res: &Result<reqwest::Response, reqwest_middleware::Error>,
95 ) -> Option<reqwest_retry::Retryable> {
96 match res {
97 Ok(success) => reqwest_retry::default_on_request_success(success),
98 Err(_) => None,
99 }
100 }
101 }
102 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
103 .build_with_max_retries(config.max_retries);
104
105 let retry_middleware =
106 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
107 backoff_policy,
108 RetryableStatus,
109 );
110
111 middleware_client_builder = middleware_client_builder.with(retry_middleware);
112 }
113
114 let client = middleware_client_builder.build();
115
116 Self { config, client }
117 }
118
119 pub fn with_client_and_config(
120 config: datadog::Configuration,
121 client: reqwest_middleware::ClientWithMiddleware,
122 ) -> Self {
123 Self { config, client }
124 }
125
126 pub async fn create_child_org(
137 &self,
138 body: crate::datadogV1::model::OrganizationCreateBody,
139 ) -> Result<
140 crate::datadogV1::model::OrganizationCreateResponse,
141 datadog::Error<CreateChildOrgError>,
142 > {
143 match self.create_child_org_with_http_info(body).await {
144 Ok(response_content) => {
145 if let Some(e) = response_content.entity {
146 Ok(e)
147 } else {
148 Err(datadog::Error::Serde(serde::de::Error::custom(
149 "response content was None",
150 )))
151 }
152 }
153 Err(err) => Err(err),
154 }
155 }
156
157 pub async fn create_child_org_with_http_info(
168 &self,
169 body: crate::datadogV1::model::OrganizationCreateBody,
170 ) -> Result<
171 datadog::ResponseContent<crate::datadogV1::model::OrganizationCreateResponse>,
172 datadog::Error<CreateChildOrgError>,
173 > {
174 let local_configuration = &self.config;
175 let operation_id = "v1.create_child_org";
176
177 let local_client = &self.client;
178
179 let local_uri_str = format!(
180 "{}/api/v1/org",
181 local_configuration.get_operation_host(operation_id)
182 );
183 let mut local_req_builder =
184 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
185
186 let mut headers = HeaderMap::new();
188 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
189 headers.insert("Accept", HeaderValue::from_static("application/json"));
190
191 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
193 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
194 Err(e) => {
195 log::warn!("Failed to parse user agent header: {e}, falling back to default");
196 headers.insert(
197 reqwest::header::USER_AGENT,
198 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
199 )
200 }
201 };
202
203 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
205 headers.insert(
206 "DD-API-KEY",
207 HeaderValue::from_str(local_key.key.as_str())
208 .expect("failed to parse DD-API-KEY header"),
209 );
210 };
211 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
212 headers.insert(
213 "DD-APPLICATION-KEY",
214 HeaderValue::from_str(local_key.key.as_str())
215 .expect("failed to parse DD-APPLICATION-KEY header"),
216 );
217 };
218
219 let output = Vec::new();
221 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
222 if body.serialize(&mut ser).is_ok() {
223 if let Some(content_encoding) = headers.get("Content-Encoding") {
224 match content_encoding.to_str().unwrap_or_default() {
225 "gzip" => {
226 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
227 let _ = enc.write_all(ser.into_inner().as_slice());
228 match enc.finish() {
229 Ok(buf) => {
230 local_req_builder = local_req_builder.body(buf);
231 }
232 Err(e) => return Err(datadog::Error::Io(e)),
233 }
234 }
235 "deflate" => {
236 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
237 let _ = enc.write_all(ser.into_inner().as_slice());
238 match enc.finish() {
239 Ok(buf) => {
240 local_req_builder = local_req_builder.body(buf);
241 }
242 Err(e) => return Err(datadog::Error::Io(e)),
243 }
244 }
245 "zstd1" => {
246 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
247 let _ = enc.write_all(ser.into_inner().as_slice());
248 match enc.finish() {
249 Ok(buf) => {
250 local_req_builder = local_req_builder.body(buf);
251 }
252 Err(e) => return Err(datadog::Error::Io(e)),
253 }
254 }
255 _ => {
256 local_req_builder = local_req_builder.body(ser.into_inner());
257 }
258 }
259 } else {
260 local_req_builder = local_req_builder.body(ser.into_inner());
261 }
262 }
263
264 local_req_builder = local_req_builder.headers(headers);
265 let local_req = local_req_builder.build()?;
266 log::debug!("request content: {:?}", local_req.body());
267 let local_resp = local_client.execute(local_req).await?;
268
269 let local_status = local_resp.status();
270 let local_content = local_resp.text().await?;
271 log::debug!("response content: {}", local_content);
272
273 if !local_status.is_client_error() && !local_status.is_server_error() {
274 match serde_json::from_str::<crate::datadogV1::model::OrganizationCreateResponse>(
275 &local_content,
276 ) {
277 Ok(e) => {
278 return Ok(datadog::ResponseContent {
279 status: local_status,
280 content: local_content,
281 entity: Some(e),
282 })
283 }
284 Err(e) => return Err(datadog::Error::Serde(e)),
285 };
286 } else {
287 let local_entity: Option<CreateChildOrgError> =
288 serde_json::from_str(&local_content).ok();
289 let local_error = datadog::ResponseContent {
290 status: local_status,
291 content: local_content,
292 entity: local_entity,
293 };
294 Err(datadog::Error::ResponseError(local_error))
295 }
296 }
297
298 pub async fn downgrade_org(
300 &self,
301 public_id: String,
302 ) -> Result<crate::datadogV1::model::OrgDowngradedResponse, datadog::Error<DowngradeOrgError>>
303 {
304 match self.downgrade_org_with_http_info(public_id).await {
305 Ok(response_content) => {
306 if let Some(e) = response_content.entity {
307 Ok(e)
308 } else {
309 Err(datadog::Error::Serde(serde::de::Error::custom(
310 "response content was None",
311 )))
312 }
313 }
314 Err(err) => Err(err),
315 }
316 }
317
318 pub async fn downgrade_org_with_http_info(
320 &self,
321 public_id: String,
322 ) -> Result<
323 datadog::ResponseContent<crate::datadogV1::model::OrgDowngradedResponse>,
324 datadog::Error<DowngradeOrgError>,
325 > {
326 let local_configuration = &self.config;
327 let operation_id = "v1.downgrade_org";
328
329 let local_client = &self.client;
330
331 let local_uri_str = format!(
332 "{}/api/v1/org/{public_id}/downgrade",
333 local_configuration.get_operation_host(operation_id),
334 public_id = datadog::urlencode(public_id)
335 );
336 let mut local_req_builder =
337 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
338
339 let mut headers = HeaderMap::new();
341 headers.insert("Accept", HeaderValue::from_static("application/json"));
342
343 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
345 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
346 Err(e) => {
347 log::warn!("Failed to parse user agent header: {e}, falling back to default");
348 headers.insert(
349 reqwest::header::USER_AGENT,
350 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
351 )
352 }
353 };
354
355 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
357 headers.insert(
358 "DD-API-KEY",
359 HeaderValue::from_str(local_key.key.as_str())
360 .expect("failed to parse DD-API-KEY header"),
361 );
362 };
363 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
364 headers.insert(
365 "DD-APPLICATION-KEY",
366 HeaderValue::from_str(local_key.key.as_str())
367 .expect("failed to parse DD-APPLICATION-KEY header"),
368 );
369 };
370
371 local_req_builder = local_req_builder.headers(headers);
372 let local_req = local_req_builder.build()?;
373 log::debug!("request content: {:?}", local_req.body());
374 let local_resp = local_client.execute(local_req).await?;
375
376 let local_status = local_resp.status();
377 let local_content = local_resp.text().await?;
378 log::debug!("response content: {}", local_content);
379
380 if !local_status.is_client_error() && !local_status.is_server_error() {
381 match serde_json::from_str::<crate::datadogV1::model::OrgDowngradedResponse>(
382 &local_content,
383 ) {
384 Ok(e) => {
385 return Ok(datadog::ResponseContent {
386 status: local_status,
387 content: local_content,
388 entity: Some(e),
389 })
390 }
391 Err(e) => return Err(datadog::Error::Serde(e)),
392 };
393 } else {
394 let local_entity: Option<DowngradeOrgError> = serde_json::from_str(&local_content).ok();
395 let local_error = datadog::ResponseContent {
396 status: local_status,
397 content: local_content,
398 entity: local_entity,
399 };
400 Err(datadog::Error::ResponseError(local_error))
401 }
402 }
403
404 pub async fn get_org(
406 &self,
407 public_id: String,
408 ) -> Result<crate::datadogV1::model::OrganizationResponse, datadog::Error<GetOrgError>> {
409 match self.get_org_with_http_info(public_id).await {
410 Ok(response_content) => {
411 if let Some(e) = response_content.entity {
412 Ok(e)
413 } else {
414 Err(datadog::Error::Serde(serde::de::Error::custom(
415 "response content was None",
416 )))
417 }
418 }
419 Err(err) => Err(err),
420 }
421 }
422
423 pub async fn get_org_with_http_info(
425 &self,
426 public_id: String,
427 ) -> Result<
428 datadog::ResponseContent<crate::datadogV1::model::OrganizationResponse>,
429 datadog::Error<GetOrgError>,
430 > {
431 let local_configuration = &self.config;
432 let operation_id = "v1.get_org";
433
434 let local_client = &self.client;
435
436 let local_uri_str = format!(
437 "{}/api/v1/org/{public_id}",
438 local_configuration.get_operation_host(operation_id),
439 public_id = datadog::urlencode(public_id)
440 );
441 let mut local_req_builder =
442 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
443
444 let mut headers = HeaderMap::new();
446 headers.insert("Accept", HeaderValue::from_static("application/json"));
447
448 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
450 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
451 Err(e) => {
452 log::warn!("Failed to parse user agent header: {e}, falling back to default");
453 headers.insert(
454 reqwest::header::USER_AGENT,
455 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
456 )
457 }
458 };
459
460 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
462 headers.insert(
463 "DD-API-KEY",
464 HeaderValue::from_str(local_key.key.as_str())
465 .expect("failed to parse DD-API-KEY header"),
466 );
467 };
468 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
469 headers.insert(
470 "DD-APPLICATION-KEY",
471 HeaderValue::from_str(local_key.key.as_str())
472 .expect("failed to parse DD-APPLICATION-KEY header"),
473 );
474 };
475
476 local_req_builder = local_req_builder.headers(headers);
477 let local_req = local_req_builder.build()?;
478 log::debug!("request content: {:?}", local_req.body());
479 let local_resp = local_client.execute(local_req).await?;
480
481 let local_status = local_resp.status();
482 let local_content = local_resp.text().await?;
483 log::debug!("response content: {}", local_content);
484
485 if !local_status.is_client_error() && !local_status.is_server_error() {
486 match serde_json::from_str::<crate::datadogV1::model::OrganizationResponse>(
487 &local_content,
488 ) {
489 Ok(e) => {
490 return Ok(datadog::ResponseContent {
491 status: local_status,
492 content: local_content,
493 entity: Some(e),
494 })
495 }
496 Err(e) => return Err(datadog::Error::Serde(e)),
497 };
498 } else {
499 let local_entity: Option<GetOrgError> = serde_json::from_str(&local_content).ok();
500 let local_error = datadog::ResponseContent {
501 status: local_status,
502 content: local_content,
503 entity: local_entity,
504 };
505 Err(datadog::Error::ResponseError(local_error))
506 }
507 }
508
509 pub async fn list_orgs(
511 &self,
512 ) -> Result<crate::datadogV1::model::OrganizationListResponse, datadog::Error<ListOrgsError>>
513 {
514 match self.list_orgs_with_http_info().await {
515 Ok(response_content) => {
516 if let Some(e) = response_content.entity {
517 Ok(e)
518 } else {
519 Err(datadog::Error::Serde(serde::de::Error::custom(
520 "response content was None",
521 )))
522 }
523 }
524 Err(err) => Err(err),
525 }
526 }
527
528 pub async fn list_orgs_with_http_info(
530 &self,
531 ) -> Result<
532 datadog::ResponseContent<crate::datadogV1::model::OrganizationListResponse>,
533 datadog::Error<ListOrgsError>,
534 > {
535 let local_configuration = &self.config;
536 let operation_id = "v1.list_orgs";
537
538 let local_client = &self.client;
539
540 let local_uri_str = format!(
541 "{}/api/v1/org",
542 local_configuration.get_operation_host(operation_id)
543 );
544 let mut local_req_builder =
545 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
546
547 let mut headers = HeaderMap::new();
549 headers.insert("Accept", HeaderValue::from_static("application/json"));
550
551 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
553 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
554 Err(e) => {
555 log::warn!("Failed to parse user agent header: {e}, falling back to default");
556 headers.insert(
557 reqwest::header::USER_AGENT,
558 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
559 )
560 }
561 };
562
563 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
565 headers.insert(
566 "DD-API-KEY",
567 HeaderValue::from_str(local_key.key.as_str())
568 .expect("failed to parse DD-API-KEY header"),
569 );
570 };
571 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
572 headers.insert(
573 "DD-APPLICATION-KEY",
574 HeaderValue::from_str(local_key.key.as_str())
575 .expect("failed to parse DD-APPLICATION-KEY header"),
576 );
577 };
578
579 local_req_builder = local_req_builder.headers(headers);
580 let local_req = local_req_builder.build()?;
581 log::debug!("request content: {:?}", local_req.body());
582 let local_resp = local_client.execute(local_req).await?;
583
584 let local_status = local_resp.status();
585 let local_content = local_resp.text().await?;
586 log::debug!("response content: {}", local_content);
587
588 if !local_status.is_client_error() && !local_status.is_server_error() {
589 match serde_json::from_str::<crate::datadogV1::model::OrganizationListResponse>(
590 &local_content,
591 ) {
592 Ok(e) => {
593 return Ok(datadog::ResponseContent {
594 status: local_status,
595 content: local_content,
596 entity: Some(e),
597 })
598 }
599 Err(e) => return Err(datadog::Error::Serde(e)),
600 };
601 } else {
602 let local_entity: Option<ListOrgsError> = serde_json::from_str(&local_content).ok();
603 let local_error = datadog::ResponseContent {
604 status: local_status,
605 content: local_content,
606 entity: local_entity,
607 };
608 Err(datadog::Error::ResponseError(local_error))
609 }
610 }
611
612 pub async fn update_org(
614 &self,
615 public_id: String,
616 body: crate::datadogV1::model::Organization,
617 ) -> Result<crate::datadogV1::model::OrganizationResponse, datadog::Error<UpdateOrgError>> {
618 match self.update_org_with_http_info(public_id, body).await {
619 Ok(response_content) => {
620 if let Some(e) = response_content.entity {
621 Ok(e)
622 } else {
623 Err(datadog::Error::Serde(serde::de::Error::custom(
624 "response content was None",
625 )))
626 }
627 }
628 Err(err) => Err(err),
629 }
630 }
631
632 pub async fn update_org_with_http_info(
634 &self,
635 public_id: String,
636 body: crate::datadogV1::model::Organization,
637 ) -> Result<
638 datadog::ResponseContent<crate::datadogV1::model::OrganizationResponse>,
639 datadog::Error<UpdateOrgError>,
640 > {
641 let local_configuration = &self.config;
642 let operation_id = "v1.update_org";
643
644 let local_client = &self.client;
645
646 let local_uri_str = format!(
647 "{}/api/v1/org/{public_id}",
648 local_configuration.get_operation_host(operation_id),
649 public_id = datadog::urlencode(public_id)
650 );
651 let mut local_req_builder =
652 local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
653
654 let mut headers = HeaderMap::new();
656 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
657 headers.insert("Accept", HeaderValue::from_static("application/json"));
658
659 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
661 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
662 Err(e) => {
663 log::warn!("Failed to parse user agent header: {e}, falling back to default");
664 headers.insert(
665 reqwest::header::USER_AGENT,
666 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
667 )
668 }
669 };
670
671 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
673 headers.insert(
674 "DD-API-KEY",
675 HeaderValue::from_str(local_key.key.as_str())
676 .expect("failed to parse DD-API-KEY header"),
677 );
678 };
679 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
680 headers.insert(
681 "DD-APPLICATION-KEY",
682 HeaderValue::from_str(local_key.key.as_str())
683 .expect("failed to parse DD-APPLICATION-KEY header"),
684 );
685 };
686
687 let output = Vec::new();
689 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
690 if body.serialize(&mut ser).is_ok() {
691 if let Some(content_encoding) = headers.get("Content-Encoding") {
692 match content_encoding.to_str().unwrap_or_default() {
693 "gzip" => {
694 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
695 let _ = enc.write_all(ser.into_inner().as_slice());
696 match enc.finish() {
697 Ok(buf) => {
698 local_req_builder = local_req_builder.body(buf);
699 }
700 Err(e) => return Err(datadog::Error::Io(e)),
701 }
702 }
703 "deflate" => {
704 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
705 let _ = enc.write_all(ser.into_inner().as_slice());
706 match enc.finish() {
707 Ok(buf) => {
708 local_req_builder = local_req_builder.body(buf);
709 }
710 Err(e) => return Err(datadog::Error::Io(e)),
711 }
712 }
713 "zstd1" => {
714 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
715 let _ = enc.write_all(ser.into_inner().as_slice());
716 match enc.finish() {
717 Ok(buf) => {
718 local_req_builder = local_req_builder.body(buf);
719 }
720 Err(e) => return Err(datadog::Error::Io(e)),
721 }
722 }
723 _ => {
724 local_req_builder = local_req_builder.body(ser.into_inner());
725 }
726 }
727 } else {
728 local_req_builder = local_req_builder.body(ser.into_inner());
729 }
730 }
731
732 local_req_builder = local_req_builder.headers(headers);
733 let local_req = local_req_builder.build()?;
734 log::debug!("request content: {:?}", local_req.body());
735 let local_resp = local_client.execute(local_req).await?;
736
737 let local_status = local_resp.status();
738 let local_content = local_resp.text().await?;
739 log::debug!("response content: {}", local_content);
740
741 if !local_status.is_client_error() && !local_status.is_server_error() {
742 match serde_json::from_str::<crate::datadogV1::model::OrganizationResponse>(
743 &local_content,
744 ) {
745 Ok(e) => {
746 return Ok(datadog::ResponseContent {
747 status: local_status,
748 content: local_content,
749 entity: Some(e),
750 })
751 }
752 Err(e) => return Err(datadog::Error::Serde(e)),
753 };
754 } else {
755 let local_entity: Option<UpdateOrgError> = serde_json::from_str(&local_content).ok();
756 let local_error = datadog::ResponseContent {
757 status: local_status,
758 content: local_content,
759 entity: local_entity,
760 };
761 Err(datadog::Error::ResponseError(local_error))
762 }
763 }
764
765 pub async fn upload_idp_for_org(
772 &self,
773 public_id: String,
774 idp_file: Vec<u8>,
775 ) -> Result<crate::datadogV1::model::IdpResponse, datadog::Error<UploadIdPForOrgError>> {
776 match self
777 .upload_idp_for_org_with_http_info(public_id, idp_file)
778 .await
779 {
780 Ok(response_content) => {
781 if let Some(e) = response_content.entity {
782 Ok(e)
783 } else {
784 Err(datadog::Error::Serde(serde::de::Error::custom(
785 "response content was None",
786 )))
787 }
788 }
789 Err(err) => Err(err),
790 }
791 }
792
793 pub async fn upload_idp_for_org_with_http_info(
800 &self,
801 public_id: String,
802 idp_file: Vec<u8>,
803 ) -> Result<
804 datadog::ResponseContent<crate::datadogV1::model::IdpResponse>,
805 datadog::Error<UploadIdPForOrgError>,
806 > {
807 let local_configuration = &self.config;
808 let operation_id = "v1.upload_idp_for_org";
809
810 let local_client = &self.client;
811
812 let local_uri_str = format!(
813 "{}/api/v1/org/{public_id}/idp_metadata",
814 local_configuration.get_operation_host(operation_id),
815 public_id = datadog::urlencode(public_id)
816 );
817 let mut local_req_builder =
818 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
819
820 let mut headers = HeaderMap::new();
822 headers.insert(
823 "Content-Type",
824 HeaderValue::from_static("multipart/form-data"),
825 );
826 headers.insert("Accept", HeaderValue::from_static("application/json"));
827
828 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
830 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
831 Err(e) => {
832 log::warn!("Failed to parse user agent header: {e}, falling back to default");
833 headers.insert(
834 reqwest::header::USER_AGENT,
835 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
836 )
837 }
838 };
839
840 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
842 headers.insert(
843 "DD-API-KEY",
844 HeaderValue::from_str(local_key.key.as_str())
845 .expect("failed to parse DD-API-KEY header"),
846 );
847 };
848 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
849 headers.insert(
850 "DD-APPLICATION-KEY",
851 HeaderValue::from_str(local_key.key.as_str())
852 .expect("failed to parse DD-APPLICATION-KEY header"),
853 );
854 };
855
856 let mut local_form = form_data_builder::FormData::new(Vec::new());
858 let cursor = std::io::Cursor::new(idp_file);
859 if let Err(e) = local_form.write_file(
860 "idp_file",
861 cursor,
862 Some("idp_file".as_ref()),
863 "application/octet-stream",
864 ) {
865 return Err(crate::datadog::Error::Io(e));
866 };
867 headers.insert(
868 "Content-Type",
869 local_form.content_type_header().parse().unwrap(),
870 );
871 let form_result = local_form.finish();
872 match form_result {
873 Ok(form) => local_req_builder = local_req_builder.body(form),
874 Err(e) => return Err(crate::datadog::Error::Io(e)),
875 };
876
877 local_req_builder = local_req_builder.headers(headers);
878 let local_req = local_req_builder.build()?;
879 log::debug!("request content: {:?}", local_req.body());
880 let local_resp = local_client.execute(local_req).await?;
881
882 let local_status = local_resp.status();
883 let local_content = local_resp.text().await?;
884 log::debug!("response content: {}", local_content);
885
886 if !local_status.is_client_error() && !local_status.is_server_error() {
887 match serde_json::from_str::<crate::datadogV1::model::IdpResponse>(&local_content) {
888 Ok(e) => {
889 return Ok(datadog::ResponseContent {
890 status: local_status,
891 content: local_content,
892 entity: Some(e),
893 })
894 }
895 Err(e) => return Err(datadog::Error::Serde(e)),
896 };
897 } else {
898 let local_entity: Option<UploadIdPForOrgError> =
899 serde_json::from_str(&local_content).ok();
900 let local_error = datadog::ResponseContent {
901 status: local_status,
902 content: local_content,
903 entity: local_entity,
904 };
905 Err(datadog::Error::ResponseError(local_error))
906 }
907 }
908}