diff --git a/.apigentools-info b/.apigentools-info index 6b37fa683..3444eb4ba 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-29 20:46:35.814473", - "spec_repo_commit": "c0b9551e" + "regenerated": "2024-10-30 18:57:59.245021", + "spec_repo_commit": "755120dd" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-10-29 20:46:35.833539", - "spec_repo_commit": "c0b9551e" + "regenerated": "2024-10-30 18:57:59.263439", + "spec_repo_commit": "755120dd" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index ab32a8143..38238fba6 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -7115,6 +7115,81 @@ components: description: The type of the resource. The value should always be device. type: string type: object + DomainAllowlist: + description: The email domain allowlist for an org. + properties: + attributes: + $ref: '#/components/schemas/DomainAllowlistAttributes' + id: + description: The unique identifier of the org. + nullable: true + type: string + type: + $ref: '#/components/schemas/DomainAllowlistType' + required: + - type + type: object + DomainAllowlistAttributes: + description: The details of the email domain allowlist. + properties: + domains: + description: The list of domains in the email domain allowlist. + items: + type: string + type: array + enabled: + description: Whether the email domain allowlist is enabled for the org. + type: boolean + type: object + DomainAllowlistRequest: + description: Request containing the desired email domain allowlist configuration. + properties: + data: + $ref: '#/components/schemas/DomainAllowlist' + required: + - data + type: object + DomainAllowlistResponse: + description: Response containing information about the email domain allowlist. + properties: + data: + $ref: '#/components/schemas/DomainAllowlistResponseData' + type: object + DomainAllowlistResponseData: + description: The email domain allowlist response for an org. + properties: + attributes: + $ref: '#/components/schemas/DomainAllowlistResponseDataAttributes' + id: + description: The unique identifier of the org. + nullable: true + type: string + type: + $ref: '#/components/schemas/DomainAllowlistType' + required: + - type + type: object + DomainAllowlistResponseDataAttributes: + description: The details of the email domain allowlist. + properties: + domains: + description: The list of domains in the email domain allowlist. + items: + type: string + type: array + enabled: + description: Whether the email domain allowlist is enabled for the org. + type: boolean + type: object + DomainAllowlistType: + default: domain_allowlist + description: Email domain allowlist allowlist type. + enum: + - domain_allowlist + example: domain_allowlist + type: string + x-enum-varnames: + - DOMAIN_ALLOWLIST DowntimeCreateRequest: description: Request for creating a downtime. properties: @@ -29433,6 +29508,61 @@ paths: tags: - Dashboard Lists x-codegen-request-body-name: body + /api/v2/domain_allowlist: + get: + description: Get the domain allowlist for an organization. + operationId: GetDomainAllowlist + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DomainAllowlistResponse' + description: OK + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - org_management + summary: Get Domain Allowlist + tags: + - Domain Allowlist + x-permission: + operator: OR + permissions: + - org_management + patch: + description: Update the domain allowlist for an organization. + operationId: PatchDomainAllowlist + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/DomainAllowlistRequest' + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DomainAllowlistResponse' + description: OK + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + appKeyAuth: [] + - AuthZ: + - org_management + summary: Sets Domain Allowlist + tags: + - Domain Allowlist + x-permission: + operator: OR + permissions: + - org_management /api/v2/dora/deployment: post: description: 'Use this API endpoint to provide data about deployments for DORA @@ -41786,6 +41916,14 @@ tags: organization.' name: Dashboard Lists +- description: 'Configure your Datadog Email Domain Allowlist directly through the + Datadog API. + + The Email Domain Allowlist controls the domains that certain datadog emails can + be sent to. + + For more information, see the [Domain Allowlist docs page](https://docs.datadoghq.com/account_management/org_settings/domain_allowlist)' + name: Domain Allowlist - description: '**Note**: Downtime V2 is currently in private beta. To request access, contact [Datadog support](https://docs.datadoghq.com/help/). diff --git a/examples/v2_domain-allowlist_GetDomainAllowlist.rs b/examples/v2_domain-allowlist_GetDomainAllowlist.rs new file mode 100644 index 000000000..312a26017 --- /dev/null +++ b/examples/v2_domain-allowlist_GetDomainAllowlist.rs @@ -0,0 +1,15 @@ +// Get Domain Allowlist returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_domain_allowlist::DomainAllowlistAPI; + +#[tokio::main] +async fn main() { + let configuration = datadog::Configuration::new(); + let api = DomainAllowlistAPI::with_config(configuration); + let resp = api.get_domain_allowlist().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_domain-allowlist_PatchDomainAllowlist.rs b/examples/v2_domain-allowlist_PatchDomainAllowlist.rs new file mode 100644 index 000000000..7f74f225f --- /dev/null +++ b/examples/v2_domain-allowlist_PatchDomainAllowlist.rs @@ -0,0 +1,26 @@ +// Sets Domain Allowlist returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_domain_allowlist::DomainAllowlistAPI; +use datadog_api_client::datadogV2::model::DomainAllowlist; +use datadog_api_client::datadogV2::model::DomainAllowlistAttributes; +use datadog_api_client::datadogV2::model::DomainAllowlistRequest; +use datadog_api_client::datadogV2::model::DomainAllowlistType; + +#[tokio::main] +async fn main() { + let body = DomainAllowlistRequest::new( + DomainAllowlist::new(DomainAllowlistType::DOMAIN_ALLOWLIST).attributes( + DomainAllowlistAttributes::new() + .domains(vec!["@static-test-domain.test".to_string()]) + .enabled(false), + ), + ); + let configuration = datadog::Configuration::new(); + let api = DomainAllowlistAPI::with_config(configuration); + let resp = api.patch_domain_allowlist(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadogV2/api/api_domain_allowlist.rs b/src/datadogV2/api/api_domain_allowlist.rs new file mode 100644 index 000000000..7f822d62f --- /dev/null +++ b/src/datadogV2/api/api_domain_allowlist.rs @@ -0,0 +1,355 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use crate::datadog; +use flate2::{ + write::{GzEncoder, ZlibEncoder}, + Compression, +}; +use reqwest::header::{HeaderMap, HeaderValue}; +use serde::{Deserialize, Serialize}; +use std::io::Write; + +/// GetDomainAllowlistError is a struct for typed errors of method [`DomainAllowlistAPI::get_domain_allowlist`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetDomainAllowlistError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// PatchDomainAllowlistError is a struct for typed errors of method [`DomainAllowlistAPI::patch_domain_allowlist`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum PatchDomainAllowlistError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// Configure your Datadog Email Domain Allowlist directly through the Datadog API. +/// The Email Domain Allowlist controls the domains that certain datadog emails can be sent to. +/// For more information, see the [Domain Allowlist docs page]() +#[derive(Debug, Clone)] +pub struct DomainAllowlistAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for DomainAllowlistAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl DomainAllowlistAPI { + pub fn new() -> Self { + Self::default() + } + pub fn with_config(config: datadog::Configuration) -> Self { + let mut reqwest_client_builder = reqwest::Client::builder(); + + if let Some(proxy_url) = &config.proxy_url { + let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL"); + reqwest_client_builder = reqwest_client_builder.proxy(proxy); + } + + let mut middleware_client_builder = + reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap()); + + if config.enable_retry { + struct RetryableStatus; + impl reqwest_retry::RetryableStrategy for RetryableStatus { + fn handle( + &self, + res: &Result, + ) -> Option { + match res { + Ok(success) => reqwest_retry::default_on_request_success(success), + Err(_) => None, + } + } + } + let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder() + .build_with_max_retries(config.max_retries); + + let retry_middleware = + reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy( + backoff_policy, + RetryableStatus, + ); + + middleware_client_builder = middleware_client_builder.with(retry_middleware); + } + + let client = middleware_client_builder.build(); + + Self { config, client } + } + + pub fn with_client_and_config( + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, + ) -> Self { + Self { config, client } + } + + /// Get the domain allowlist for an organization. + pub async fn get_domain_allowlist( + &self, + ) -> Result< + crate::datadogV2::model::DomainAllowlistResponse, + datadog::Error, + > { + match self.get_domain_allowlist_with_http_info().await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Get the domain allowlist for an organization. + pub async fn get_domain_allowlist_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_domain_allowlist"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/domain_allowlist", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::GET, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } + + /// Update the domain allowlist for an organization. + pub async fn patch_domain_allowlist( + &self, + body: crate::datadogV2::model::DomainAllowlistRequest, + ) -> Result< + crate::datadogV2::model::DomainAllowlistResponse, + datadog::Error, + > { + match self.patch_domain_allowlist_with_http_info(body).await { + Ok(response_content) => { + if let Some(e) = response_content.entity { + Ok(e) + } else { + Err(datadog::Error::Serde(serde::de::Error::custom( + "response content was None", + ))) + } + } + Err(err) => Err(err), + } + } + + /// Update the domain allowlist for an organization. + pub async fn patch_domain_allowlist_with_http_info( + &self, + body: crate::datadogV2::model::DomainAllowlistRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.patch_domain_allowlist"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/domain_allowlist", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::PATCH, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", HeaderValue::from_static("application/json")); + headers.insert("Accept", HeaderValue::from_static("application/json")); + + // build user agent + match HeaderValue::from_str(local_configuration.user_agent.as_str()) { + Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent), + Err(e) => { + log::warn!("Failed to parse user agent header: {e}, falling back to default"); + headers.insert( + reqwest::header::USER_AGENT, + HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()), + ) + } + }; + + // build auth + if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") { + headers.insert( + "DD-API-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-API-KEY header"), + ); + }; + if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") { + headers.insert( + "DD-APPLICATION-KEY", + HeaderValue::from_str(local_key.key.as_str()) + .expect("failed to parse DD-APPLICATION-KEY header"), + ); + }; + + // build body parameters + let output = Vec::new(); + let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter); + if body.serialize(&mut ser).is_ok() { + if let Some(content_encoding) = headers.get("Content-Encoding") { + match content_encoding.to_str().unwrap_or_default() { + "gzip" => { + let mut enc = GzEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "deflate" => { + let mut enc = ZlibEncoder::new(Vec::new(), Compression::default()); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + "zstd1" => { + let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap(); + let _ = enc.write_all(ser.into_inner().as_slice()); + match enc.finish() { + Ok(buf) => { + local_req_builder = local_req_builder.body(buf); + } + Err(e) => return Err(datadog::Error::Io(e)), + } + } + _ => { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + } else { + local_req_builder = local_req_builder.body(ser.into_inner()); + } + } + + local_req_builder = local_req_builder.headers(headers); + let local_req = local_req_builder.build()?; + log::debug!("request content: {:?}", local_req.body()); + let local_resp = local_client.execute(local_req).await?; + + let local_status = local_resp.status(); + let local_content = local_resp.text().await?; + log::debug!("response content: {}", local_content); + + if !local_status.is_client_error() && !local_status.is_server_error() { + match serde_json::from_str::( + &local_content, + ) { + Ok(e) => { + return Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: Some(e), + }) + } + Err(e) => return Err(datadog::Error::Serde(e)), + }; + } else { + let local_entity: Option = + serde_json::from_str(&local_content).ok(); + let local_error = datadog::ResponseContent { + status: local_status, + content: local_content, + entity: local_entity, + }; + Err(datadog::Error::ResponseError(local_error)) + } + } +} diff --git a/src/datadogV2/api/mod.rs b/src/datadogV2/api/mod.rs index a565b682c..63beebe0e 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -16,6 +16,7 @@ pub mod api_container_images; pub mod api_containers; pub mod api_csm_threats; pub mod api_dashboard_lists; +pub mod api_domain_allowlist; pub mod api_dora_metrics; pub mod api_downtimes; pub mod api_events; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index cf52d2407..737966280 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -17,6 +17,7 @@ pub use self::api::api_container_images; pub use self::api::api_containers; pub use self::api::api_csm_threats; pub use self::api::api_dashboard_lists; +pub use self::api::api_domain_allowlist; pub use self::api::api_dora_metrics; pub use self::api::api_downtimes; pub use self::api::api_events; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 918b37acb..4f0728433 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -902,6 +902,20 @@ pub mod model_dashboard_list_update_items_request; pub use self::model_dashboard_list_update_items_request::DashboardListUpdateItemsRequest; pub mod model_dashboard_list_update_items_response; pub use self::model_dashboard_list_update_items_response::DashboardListUpdateItemsResponse; +pub mod model_domain_allowlist_response; +pub use self::model_domain_allowlist_response::DomainAllowlistResponse; +pub mod model_domain_allowlist_response_data; +pub use self::model_domain_allowlist_response_data::DomainAllowlistResponseData; +pub mod model_domain_allowlist_response_data_attributes; +pub use self::model_domain_allowlist_response_data_attributes::DomainAllowlistResponseDataAttributes; +pub mod model_domain_allowlist_type; +pub use self::model_domain_allowlist_type::DomainAllowlistType; +pub mod model_domain_allowlist_request; +pub use self::model_domain_allowlist_request::DomainAllowlistRequest; +pub mod model_domain_allowlist; +pub use self::model_domain_allowlist::DomainAllowlist; +pub mod model_domain_allowlist_attributes; +pub use self::model_domain_allowlist_attributes::DomainAllowlistAttributes; pub mod model_dora_deployment_request; pub use self::model_dora_deployment_request::DORADeploymentRequest; pub mod model_dora_deployment_request_data; diff --git a/src/datadogV2/model/model_domain_allowlist.rs b/src/datadogV2/model/model_domain_allowlist.rs new file mode 100644 index 000000000..7f2b9f012 --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist.rs @@ -0,0 +1,132 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The email domain allowlist for an org. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlist { + /// The details of the email domain allowlist. + #[serde(rename = "attributes")] + pub attributes: Option, + /// The unique identifier of the org. + #[serde(rename = "id", default, with = "::serde_with::rust::double_option")] + pub id: Option>, + /// Email domain allowlist allowlist type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::DomainAllowlistType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlist { + pub fn new(type_: crate::datadogV2::model::DomainAllowlistType) -> DomainAllowlist { + DomainAllowlist { + attributes: None, + id: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes(mut self, value: crate::datadogV2::model::DomainAllowlistAttributes) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: Option) -> Self { + self.id = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DomainAllowlist { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistVisitor; + impl<'a> Visitor<'a> for DomainAllowlistVisitor { + type Value = DomainAllowlist; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option = + None; + let mut id: Option> = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::DomainAllowlistType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DomainAllowlist { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_attributes.rs b/src/datadogV2/model/model_domain_allowlist_attributes.rs new file mode 100644 index 000000000..a0235c8dc --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_attributes.rs @@ -0,0 +1,122 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The details of the email domain allowlist. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlistAttributes { + /// The list of domains in the email domain allowlist. + #[serde(rename = "domains")] + pub domains: Option>, + /// Whether the email domain allowlist is enabled for the org. + #[serde(rename = "enabled")] + pub enabled: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlistAttributes { + pub fn new() -> DomainAllowlistAttributes { + DomainAllowlistAttributes { + domains: None, + enabled: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn domains(mut self, value: Vec) -> Self { + self.domains = Some(value); + self + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DomainAllowlistAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistAttributesVisitor; + impl<'a> Visitor<'a> for DomainAllowlistAttributesVisitor { + type Value = DomainAllowlistAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut domains: Option> = None; + let mut enabled: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "domains" => { + if v.is_null() { + continue; + } + domains = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + if v.is_null() { + continue; + } + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = DomainAllowlistAttributes { + domains, + enabled, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_request.rs b/src/datadogV2/model/model_domain_allowlist_request.rs new file mode 100644 index 000000000..83ce89e13 --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_request.rs @@ -0,0 +1,92 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Request containing the desired email domain allowlist configuration. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlistRequest { + /// The email domain allowlist for an org. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::DomainAllowlist, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlistRequest { + pub fn new(data: crate::datadogV2::model::DomainAllowlist) -> DomainAllowlistRequest { + DomainAllowlistRequest { + data, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistRequestVisitor; + impl<'a> Visitor<'a> for DomainAllowlistRequestVisitor { + type Value = DomainAllowlistRequest; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let data = data.ok_or_else(|| M::Error::missing_field("data"))?; + + let content = DomainAllowlistRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_response.rs b/src/datadogV2/model/model_domain_allowlist_response.rs new file mode 100644 index 000000000..ddccc5166 --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_response.rs @@ -0,0 +1,105 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Response containing information about the email domain allowlist. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlistResponse { + /// The email domain allowlist response for an org. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlistResponse { + pub fn new() -> DomainAllowlistResponse { + DomainAllowlistResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::DomainAllowlistResponseData) -> Self { + self.data = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DomainAllowlistResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistResponseVisitor; + impl<'a> Visitor<'a> for DomainAllowlistResponseVisitor { + type Value = DomainAllowlistResponse; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut data: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "data" => { + if v.is_null() { + continue; + } + data = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = DomainAllowlistResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_response_data.rs b/src/datadogV2/model/model_domain_allowlist_response_data.rs new file mode 100644 index 000000000..ce64b73dc --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_response_data.rs @@ -0,0 +1,136 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The email domain allowlist response for an org. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlistResponseData { + /// The details of the email domain allowlist. + #[serde(rename = "attributes")] + pub attributes: Option, + /// The unique identifier of the org. + #[serde(rename = "id", default, with = "::serde_with::rust::double_option")] + pub id: Option>, + /// Email domain allowlist allowlist type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::DomainAllowlistType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlistResponseData { + pub fn new(type_: crate::datadogV2::model::DomainAllowlistType) -> DomainAllowlistResponseData { + DomainAllowlistResponseData { + attributes: None, + id: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::DomainAllowlistResponseDataAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: Option) -> Self { + self.id = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistResponseData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistResponseDataVisitor; + impl<'a> Visitor<'a> for DomainAllowlistResponseDataVisitor { + type Value = DomainAllowlistResponseData; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut attributes: Option< + crate::datadogV2::model::DomainAllowlistResponseDataAttributes, + > = None; + let mut id: Option> = None; + let mut type_: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "attributes" => { + if v.is_null() { + continue; + } + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::DomainAllowlistType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = DomainAllowlistResponseData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistResponseDataVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_response_data_attributes.rs b/src/datadogV2/model/model_domain_allowlist_response_data_attributes.rs new file mode 100644 index 000000000..f835f2864 --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_response_data_attributes.rs @@ -0,0 +1,122 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// The details of the email domain allowlist. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DomainAllowlistResponseDataAttributes { + /// The list of domains in the email domain allowlist. + #[serde(rename = "domains")] + pub domains: Option>, + /// Whether the email domain allowlist is enabled for the org. + #[serde(rename = "enabled")] + pub enabled: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DomainAllowlistResponseDataAttributes { + pub fn new() -> DomainAllowlistResponseDataAttributes { + DomainAllowlistResponseDataAttributes { + domains: None, + enabled: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn domains(mut self, value: Vec) -> Self { + self.domains = Some(value); + self + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for DomainAllowlistResponseDataAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistResponseDataAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DomainAllowlistResponseDataAttributesVisitor; + impl<'a> Visitor<'a> for DomainAllowlistResponseDataAttributesVisitor { + type Value = DomainAllowlistResponseDataAttributes; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut domains: Option> = None; + let mut enabled: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "domains" => { + if v.is_null() { + continue; + } + domains = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + if v.is_null() { + continue; + } + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = DomainAllowlistResponseDataAttributes { + domains, + enabled, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DomainAllowlistResponseDataAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_domain_allowlist_type.rs b/src/datadogV2/model/model_domain_allowlist_type.rs new file mode 100644 index 000000000..e01585b3a --- /dev/null +++ b/src/datadogV2/model/model_domain_allowlist_type.rs @@ -0,0 +1,48 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum DomainAllowlistType { + DOMAIN_ALLOWLIST, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for DomainAllowlistType { + fn to_string(&self) -> String { + match self { + Self::DOMAIN_ALLOWLIST => String::from("domain_allowlist"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for DomainAllowlistType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for DomainAllowlistType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "domain_allowlist" => Self::DOMAIN_ALLOWLIST, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.frozen new file mode 100644 index 000000000..2090a82fa --- /dev/null +++ b/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.frozen @@ -0,0 +1 @@ +2024-10-23T18:16:16.668Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.json b/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.json new file mode 100644 index 000000000..f5abb962e --- /dev/null +++ b/tests/scenarios/cassettes/v2/domain_allowlist/Get-Domain-Allowlist-returns-OK-response.json @@ -0,0 +1,33 @@ +{ + "http_interactions": [ + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/domain_allowlist" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"domain_allowlist\",\"attributes\":{\"enabled\":false,\"domains\":[\"@static-test-domain.test\"]}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 23 Oct 2024 18:16:16 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.frozen new file mode 100644 index 000000000..6315d630b --- /dev/null +++ b/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.frozen @@ -0,0 +1 @@ +2024-10-23T18:16:16.928Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.json b/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.json new file mode 100644 index 000000000..7aa2f7dbd --- /dev/null +++ b/tests/scenarios/cassettes/v2/domain_allowlist/Sets-Domain-Allowlist-returns-OK-response.json @@ -0,0 +1,39 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"domains\":[\"@static-test-domain.test\"],\"enabled\":false},\"type\":\"domain_allowlist\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "patch", + "uri": "https://api.datadoghq.com/api/v2/domain_allowlist" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"domain_allowlist\",\"attributes\":{\"enabled\":false,\"domains\":[\"@static-test-domain.test\"]}}}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 23 Oct 2024 18:16:16 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v2/domain_allowlist.feature b/tests/scenarios/features/v2/domain_allowlist.feature new file mode 100644 index 000000000..8fe10371d --- /dev/null +++ b/tests/scenarios/features/v2/domain_allowlist.feature @@ -0,0 +1,32 @@ +@endpoint(domain-allowlist) @endpoint(domain-allowlist-v2) +Feature: Domain Allowlist + Configure your Datadog Email Domain Allowlist directly through the Datadog + API. The Email Domain Allowlist controls the domains that certain datadog + emails can be sent to. For more information, see the [Domain Allowlist + docs page](https://docs.datadoghq.com/account_management/org_settings/doma + in_allowlist) + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "DomainAllowlist" API + + @team:Datadog/team-aaa-dogmail + Scenario: Get Domain Allowlist returns "OK" response + Given new "GetDomainAllowlist" request + When the request is sent + Then the response status is 200 OK + And the response "data.type" is equal to "domain_allowlist" + And the response "data.attributes.domains" array contains value "@static-test-domain.test" + And the response "data.attributes.enabled" is equal to false + + @team:Datadog/team-aaa-dogmail + Scenario: Sets Domain Allowlist returns "OK" response + Given new "PatchDomainAllowlist" request + And body with value {"data": {"attributes": {"domains": ["@static-test-domain.test"], "enabled": false}, "type": "domain_allowlist"}} + When the request is sent + Then the response status is 200 OK + And the response "data.type" is equal to "domain_allowlist" + And the response "data.attributes.domains" has length 1 + And the response "data.attributes.domains" array contains value "@static-test-domain.test" + And the response "data.attributes.enabled" is equal to false diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 68b64dfc2..5516102f8 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -547,6 +547,18 @@ "type": "safe" } }, + "GetDomainAllowlist": { + "tag": "Domain Allowlist", + "undo": { + "type": "safe" + } + }, + "PatchDomainAllowlist": { + "tag": "Domain Allowlist", + "undo": { + "type": "idempotent" + } + }, "CreateDORADeployment": { "tag": "DORA Metrics", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index fa214ded5..1b7c75ede 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -68,6 +68,7 @@ pub struct ApiInstances { Option, pub v2_api_usage_metering: Option, pub v2_api_dashboard_lists: Option, + pub v2_api_domain_allowlist: Option, pub v2_api_dora_metrics: Option, pub v2_api_downtimes: Option, pub v2_api_events: Option, @@ -524,6 +525,14 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { world.http_client.as_ref().unwrap().clone() )); } + "DomainAllowlist" => { + world.api_instances.v2_api_domain_allowlist = Some( + datadogV2::api_domain_allowlist::DomainAllowlistAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone(), + ), + ); + } "DORAMetrics" => { world.api_instances.v2_api_dora_metrics = Some( datadogV2::api_dora_metrics::DORAMetricsAPI::with_client_and_config( @@ -1926,6 +1935,13 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.UpdateDashboardListItems".into(), test_v2_update_dashboard_list_items, ); + world + .function_mappings + .insert("v2.GetDomainAllowlist".into(), test_v2_get_domain_allowlist); + world.function_mappings.insert( + "v2.PatchDomainAllowlist".into(), + test_v2_patch_domain_allowlist, + ); world.function_mappings.insert( "v2.CreateDORADeployment".into(), test_v2_create_dora_deployment, @@ -13666,6 +13682,55 @@ fn test_v2_update_dashboard_list_items( world.response.code = response.status.as_u16(); } +fn test_v2_get_domain_allowlist(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_domain_allowlist + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.get_domain_allowlist_with_http_info()) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + +fn test_v2_patch_domain_allowlist(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_domain_allowlist + .as_ref() + .expect("api instance not found"); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = match block_on(api.patch_domain_allowlist_with_http_info(body)) { + Ok(response) => response, + Err(error) => { + return match error { + Error::ResponseError(e) => { + world.response.code = e.status.as_u16(); + if let Some(entity) = e.entity { + world.response.object = serde_json::to_value(entity).unwrap(); + } + } + _ => panic!("error parsing response: {error}"), + }; + } + }; + world.response.object = serde_json::to_value(response.entity).unwrap(); + world.response.code = response.status.as_u16(); +} + fn test_v2_create_dora_deployment(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances