diff --git a/.apigentools-info b/.apigentools-info index a0ee89b61..b8b1f0332 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-12 09:36:34.033025", - "spec_repo_commit": "7c86a87a" + "regenerated": "2024-09-12 13:53:27.242345", + "spec_repo_commit": "567a9707" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-12 09:36:34.051405", - "spec_repo_commit": "7c86a87a" + "regenerated": "2024-09-12 13:53:27.260291", + "spec_repo_commit": "567a9707" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index b97ac37f8..b9e676c2a 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -84,6 +84,14 @@ components: required: false schema: $ref: '#/components/schemas/APIKeysSort' + ASMExclusionFilterID: + description: The ID of the exclusion filter. + example: 3b5-v82-ns6 + in: path + name: exclusion_filter_id + required: true + schema: + type: string ApplicationKeyFilterCreatedAtEndParameter: description: Only include application keys created on or before the specified date. @@ -907,6 +915,304 @@ components: type: string x-enum-varnames: - API_KEYS + ASMExclusionFilterAttributes: + description: The attributes of the ASM WAF exclusion filter. + properties: + description: + description: A description for the exclusion filter. + example: Test exclude path + type: string + enabled: + description: Indicates whether the exclusion filter is enabled. + example: false + type: boolean + ip_list: + description: The IPs list for the exclusion filter. + items: + example: 127.0.0.1 + type: string + type: array + metadata: + $ref: '#/components/schemas/ASMExclusionFilterMetadata' + path_glob: + description: The path glob for the exclusion filter. + example: /lfi_include/* + type: string + rules_target: + description: A list of rules targeted by the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterRulesTarget' + type: array + scope: + description: The scope of the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterScope' + type: array + type: object + ASMExclusionFilterCreateAttributes: + description: Create a new ASM WAF exclusion filter. + properties: + description: + description: A description for the exclusion filter. + example: Test exclude path + type: string + enabled: + description: Indicates whether the exclusion filter is enabled. + example: false + type: boolean + ip_list: + description: The IPs list for the exclusion filter. + items: + example: 127.0.0.1 + type: string + type: array + path_glob: + description: The path glob for the exclusion filter. + example: /lfi_include/* + type: string + rules_target: + description: A list of rules targeted by the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterRulesTarget' + type: array + scope: + description: The scope of the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterScope' + type: array + required: + - description + - enabled + ASMExclusionFilterCreateData: + description: Object for a single exclusion filter. + properties: + attributes: + $ref: '#/components/schemas/ASMExclusionFilterCreateAttributes' + type: + $ref: '#/components/schemas/ASMExclusionFilterType' + required: + - attributes + - type + type: object + ASMExclusionFilterCreateRequest: + description: Request object that includes the exclusion filter to create. + properties: + data: + $ref: '#/components/schemas/ASMExclusionFilterCreateData' + required: + - data + type: object + ASMExclusionFilterData: + description: Object for a single Exclusion filter. + properties: + attributes: + $ref: '#/components/schemas/ASMExclusionFilterAttributes' + id: + description: The ID of the Exclusion filter. + example: 3dd-0uc-h1s + type: string + type: + $ref: '#/components/schemas/ASMExclusionFilterType' + type: object + ASMExclusionFilterID: + description: The ID of the exclusion filter. + example: 3dd-0uc-h1s + type: string + ASMExclusionFilterListAttributes: + description: The attributes of the ASM WAF exclusion filter. + properties: + description: + description: A description for the exclusion filter. + example: Test exclude path + type: string + enabled: + description: Indicates whether the exclusion filter is enabled. + example: false + type: boolean + ip_list: + description: The IPs list for the exclusion filter. + items: + example: 127.0.0.1 + type: string + type: array + metadata: + $ref: '#/components/schemas/ASMExclusionFilterMetadata' + path_glob: + description: The path glob for the exclusion filter. + example: /lfi_include/* + type: string + rules_target: + description: A list of rules targeted by the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterListRulesTarget' + type: array + scope: + description: The scope of the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterScope' + type: array + type: object + ASMExclusionFilterListResponse: + description: Response object that includes a list of exclusion filters. + properties: + data: + description: The ASMExclusionFilterResponse data. + items: + $ref: '#/components/schemas/ASMExclusionListFilterData' + type: array + type: object + ASMExclusionFilterListRulesTarget: + description: A rule targeted by the exclusion filter. + properties: + tags: + $ref: '#/components/schemas/ASMExclusionFilterListRulesTargetTags' + type: object + ASMExclusionFilterListRulesTargetTags: + description: Tags identifying the category and type of the targeted rule. + properties: + category: + description: The category of the rule. + example: attack_attempt + type: string + type: + description: The type of the rule. + example: lfi + type: string + type: object + ASMExclusionFilterMetadata: + description: Metadata about the exclusion filter. + properties: + added_at: + description: The timestamp when the exclusion filter was added. + example: '2023-05-04T15:26:41Z' + format: date-time + type: string + added_by: + description: The email address of the user who added the exclusion filter. + example: xxxx@xxxx.com + type: string + modified_at: + description: The timestamp when the exclusion filter was last modified. + example: '2023-05-30T15:45:51Z' + format: date-time + type: string + modified_by: + description: The email address of the user who last modified the exclusion + filter. + example: xxx@xxx.com + type: string + type: object + ASMExclusionFilterResponse: + description: Response object that includes a list of exclusion filters. + properties: + data: + description: The ASMExclusionFilterResponse data. + items: + $ref: '#/components/schemas/ASMExclusionFilterData' + type: array + type: object + ASMExclusionFilterRulesTarget: + description: A rule targeted by the exclusion filter. + properties: + rule_id: + description: The ID of the targeted rule. + example: dog-913-009 + type: string + rule_name: + description: The name of the targeted rule. + example: WhiteHat Security OOB domain + type: string + type: object + ASMExclusionFilterScope: + description: The scope of the exclusion filter. + properties: + env: + description: The environment scope for the exclusion filter. + example: dd-appsec-php-support + type: string + service: + description: The service scope for the exclusion filter. + example: anil-php-weblog + type: string + type: object + ASMExclusionFilterType: + default: exclusion_filter + description: The type of the resource. The value should always be `exclusion_filter`. + enum: + - exclusion_filter + example: exclusion_filter + type: string + x-enum-varnames: + - EXCLUSION_FILTER + ASMExclusionFilterUpdateAttributes: + description: Update an existing ASM Exclusion filter. + properties: + description: + description: The description of the Exclusion filter. + example: My Exclusion filter + type: string + enabled: + description: Whether the Exclusion filter is enabled. + example: true + type: boolean + ip_list: + description: The IPs list for the exclusion filter. + items: + example: 127.0.0.1 + type: string + type: array + path_glob: + description: The path glob for the exclusion filter. + example: /lfi_include/* + type: string + rules_target: + description: A list of rules targeted by the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterRulesTarget' + type: array + scope: + description: The scope of the exclusion filter. + items: + $ref: '#/components/schemas/ASMExclusionFilterScope' + type: array + required: + - description + - enabled + type: object + ASMExclusionFilterUpdateData: + description: Object for a single Exclusion filter. + properties: + attributes: + $ref: '#/components/schemas/ASMExclusionFilterUpdateAttributes' + id: + $ref: '#/components/schemas/ASMExclusionFilterID' + type: + $ref: '#/components/schemas/ASMExclusionFilterType' + required: + - attributes + - type + type: object + ASMExclusionFilterUpdateRequest: + description: Request object that includes the Exclusion filter with the attributes + to update. + properties: + data: + $ref: '#/components/schemas/ASMExclusionFilterUpdateData' + required: + - data + type: object + ASMExclusionListFilterData: + description: Object for a single Exclusion filter. + properties: + attributes: + $ref: '#/components/schemas/ASMExclusionFilterListAttributes' + id: + description: The ID of the Exclusion filter. + example: 3dd-0uc-h1s + type: string + type: + $ref: '#/components/schemas/ASMExclusionFilterType' + type: object AWSRelatedAccount: description: AWS related account. properties: @@ -33577,6 +33883,125 @@ paths: We are gradually onboarding support for more sources. If you have any feedback, contact [Datadog Support](https://docs.datadoghq.com/help/).' + /api/v2/remote_config/products/asm/waf/exclusion_filters: + get: + description: Retrieve a list of ASM exclusion filters. + operationId: ListASMExclusionFilters + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterListResponse' + description: OK + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: List ASM Exclusion Filters + tags: + - ASM Exclusion Filters + post: + description: Create a new exclusion filter with the given parameters. + operationId: CreateASMExclusionFilter + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterCreateRequest' + description: The definition of the new Exclusion filter. + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterResponse' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '409': + $ref: '#/components/responses/ConflictResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Create a ASM WAF Exclusion filter + tags: + - ASM Exclusion Filters + x-codegen-request-body-name: body + /api/v2/remote_config/products/asm/waf/exclusion_filters/{exclusion_filter_id}: + delete: + description: Delete a specific ASM Exclusion filter. + operationId: DeleteASMExclusionFilter + parameters: + - $ref: '#/components/parameters/ASMExclusionFilterID' + responses: + '204': + description: OK + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Delete a ASM Exclusion Filter + tags: + - ASM Exclusion Filters + get: + description: Retrieve a specific ASM exclusion filter by ID. + operationId: GetASMExclusionFilters + parameters: + - $ref: '#/components/parameters/ASMExclusionFilterID' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterResponse' + description: OK + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Get a specific ASM Exclusion Filter + tags: + - ASM Exclusion Filters + patch: + description: 'Update a specific Exclusion filter. + + Returns the Exclusion filter object when the request is successful.' + operationId: UpdateASMExclusionFilter + parameters: + - $ref: '#/components/parameters/ASMExclusionFilterID' + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterUpdateRequest' + description: New definition of the Exclusion filter. + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ASMExclusionFilterResponse' + description: OK + '400': + $ref: '#/components/responses/BadRequestResponse' + '403': + $ref: '#/components/responses/NotAuthorizedResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + '409': + $ref: '#/components/responses/ConcurrentModificationResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + summary: Update a ASM Exclusion filter + tags: + - ASM Exclusion Filters + x-codegen-request-body-name: body /api/v2/remote_config/products/cws/agent_rules: get: description: Get the list of Cloud Security Management Threats Agent rules. @@ -39496,6 +39921,9 @@ tags: description: Find out more at url: https://docs.datadoghq.com/tracing/trace_pipeline/trace_retention/ name: APM Retention Filters +- description: Exclusion filters in ASM libraries are used to circumvent false positives + in protection. + name: ASM Exclusion Filters - description: Search your Audit Logs events over HTTP. name: Audit - description: '[The AuthN Mappings API](https://docs.datadoghq.com/account_management/authn_mapping/?tab=example) diff --git a/examples/v2_asm-exclusion-filters_CreateASMExclusionFilter.rs b/examples/v2_asm-exclusion-filters_CreateASMExclusionFilter.rs new file mode 100644 index 000000000..7ecb36952 --- /dev/null +++ b/examples/v2_asm-exclusion-filters_CreateASMExclusionFilter.rs @@ -0,0 +1,30 @@ +// Create a ASM WAF Exclusion filter returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI; +use datadog_api_client::datadogV2::model::ASMExclusionFilterCreateAttributes; +use datadog_api_client::datadogV2::model::ASMExclusionFilterCreateData; +use datadog_api_client::datadogV2::model::ASMExclusionFilterCreateRequest; +use datadog_api_client::datadogV2::model::ASMExclusionFilterRulesTarget; +use datadog_api_client::datadogV2::model::ASMExclusionFilterScope; +use datadog_api_client::datadogV2::model::ASMExclusionFilterType; + +#[tokio::main] +async fn main() { + let body = ASMExclusionFilterCreateRequest::new(ASMExclusionFilterCreateData::new( + ASMExclusionFilterCreateAttributes::new("my description".to_string(), true) + .path_glob("*".to_string()) + .rules_target(vec![ASMExclusionFilterRulesTarget::new()]) + .scope(vec![ASMExclusionFilterScope::new() + .env("staging".to_string()) + .service("container-resolver".to_string())]), + ASMExclusionFilterType::EXCLUSION_FILTER, + )); + let configuration = datadog::Configuration::new(); + let api = ASMExclusionFiltersAPI::with_config(configuration); + let resp = api.create_asm_exclusion_filter(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_asm-exclusion-filters_DeleteASMExclusionFilter.rs b/examples/v2_asm-exclusion-filters_DeleteASMExclusionFilter.rs new file mode 100644 index 000000000..641f2027f --- /dev/null +++ b/examples/v2_asm-exclusion-filters_DeleteASMExclusionFilter.rs @@ -0,0 +1,17 @@ +// Delete a ASM Exclusion Filter returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI; + +#[tokio::main] +async fn main() { + let configuration = datadog::Configuration::new(); + let api = ASMExclusionFiltersAPI::with_config(configuration); + let resp = api + .delete_asm_exclusion_filter("exclusion_filter_id".to_string()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_asm-exclusion-filters_GetASMExclusionFilters.rs b/examples/v2_asm-exclusion-filters_GetASMExclusionFilters.rs new file mode 100644 index 000000000..5e512ebdd --- /dev/null +++ b/examples/v2_asm-exclusion-filters_GetASMExclusionFilters.rs @@ -0,0 +1,17 @@ +// Get a specific ASM Exclusion Filter returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI; + +#[tokio::main] +async fn main() { + let configuration = datadog::Configuration::new(); + let api = ASMExclusionFiltersAPI::with_config(configuration); + let resp = api + .get_asm_exclusion_filters("exclusion_filter_id".to_string()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_asm-exclusion-filters_ListASMExclusionFilters.rs b/examples/v2_asm-exclusion-filters_ListASMExclusionFilters.rs new file mode 100644 index 000000000..da6b3ed7b --- /dev/null +++ b/examples/v2_asm-exclusion-filters_ListASMExclusionFilters.rs @@ -0,0 +1,15 @@ +// List ASM Exclusion Filters returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI; + +#[tokio::main] +async fn main() { + let configuration = datadog::Configuration::new(); + let api = ASMExclusionFiltersAPI::with_config(configuration); + let resp = api.list_asm_exclusion_filters().await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_asm-exclusion-filters_UpdateASMExclusionFilter.rs b/examples/v2_asm-exclusion-filters_UpdateASMExclusionFilter.rs new file mode 100644 index 000000000..f5af2cdf5 --- /dev/null +++ b/examples/v2_asm-exclusion-filters_UpdateASMExclusionFilter.rs @@ -0,0 +1,38 @@ +// Update a ASM Exclusion filter returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI; +use datadog_api_client::datadogV2::model::ASMExclusionFilterRulesTarget; +use datadog_api_client::datadogV2::model::ASMExclusionFilterScope; +use datadog_api_client::datadogV2::model::ASMExclusionFilterType; +use datadog_api_client::datadogV2::model::ASMExclusionFilterUpdateAttributes; +use datadog_api_client::datadogV2::model::ASMExclusionFilterUpdateData; +use datadog_api_client::datadogV2::model::ASMExclusionFilterUpdateRequest; + +#[tokio::main] +async fn main() { + let body = ASMExclusionFilterUpdateRequest::new( + ASMExclusionFilterUpdateData::new( + ASMExclusionFilterUpdateAttributes::new("My Exclusion filter".to_string(), true) + .ip_list(vec!["127.0.0.1".to_string()]) + .path_glob("/lfi_include/*".to_string()) + .rules_target(vec![ASMExclusionFilterRulesTarget::new() + .rule_id("dog-913-009".to_string()) + .rule_name("WhiteHat Security OOB domain".to_string())]) + .scope(vec![ASMExclusionFilterScope::new() + .env("dd-appsec-php-support".to_string()) + .service("anil-php-weblog".to_string())]), + ASMExclusionFilterType::EXCLUSION_FILTER, + ) + .id("3dd-0uc-h1s".to_string()), + ); + let configuration = datadog::Configuration::new(); + let api = ASMExclusionFiltersAPI::with_config(configuration); + let resp = api + .update_asm_exclusion_filter("exclusion_filter_id".to_string(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadogV2/api/api_asm_exclusion_filters.rs b/src/datadogV2/api/api_asm_exclusion_filters.rs new file mode 100644 index 000000000..c7d461c7e --- /dev/null +++ b/src/datadogV2/api/api_asm_exclusion_filters.rs @@ -0,0 +1,742 @@ +// 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; + +/// CreateASMExclusionFilterError is a struct for typed errors of method [`ASMExclusionFiltersAPI::create_asm_exclusion_filter`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateASMExclusionFilterError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// DeleteASMExclusionFilterError is a struct for typed errors of method [`ASMExclusionFiltersAPI::delete_asm_exclusion_filter`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum DeleteASMExclusionFilterError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// GetASMExclusionFiltersError is a struct for typed errors of method [`ASMExclusionFiltersAPI::get_asm_exclusion_filters`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetASMExclusionFiltersError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// ListASMExclusionFiltersError is a struct for typed errors of method [`ASMExclusionFiltersAPI::list_asm_exclusion_filters`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ListASMExclusionFiltersError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// UpdateASMExclusionFilterError is a struct for typed errors of method [`ASMExclusionFiltersAPI::update_asm_exclusion_filter`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UpdateASMExclusionFilterError { + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + +/// Exclusion filters in ASM libraries are used to circumvent false positives in protection. +#[derive(Debug, Clone)] +pub struct ASMExclusionFiltersAPI { + config: datadog::Configuration, + client: reqwest_middleware::ClientWithMiddleware, +} + +impl Default for ASMExclusionFiltersAPI { + fn default() -> Self { + Self::with_config(datadog::Configuration::default()) + } +} + +impl ASMExclusionFiltersAPI { + 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 } + } + + /// Create a new exclusion filter with the given parameters. + pub async fn create_asm_exclusion_filter( + &self, + body: crate::datadogV2::model::ASMExclusionFilterCreateRequest, + ) -> Result< + crate::datadogV2::model::ASMExclusionFilterResponse, + datadog::Error, + > { + match self.create_asm_exclusion_filter_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), + } + } + + /// Create a new exclusion filter with the given parameters. + pub async fn create_asm_exclusion_filter_with_http_info( + &self, + body: crate::datadogV2::model::ASMExclusionFilterCreateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_asm_exclusion_filter"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/remote_config/products/asm/waf/exclusion_filters", + local_configuration.get_operation_host(operation_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::POST, 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)) + } + } + + /// Delete a specific ASM Exclusion filter. + pub async fn delete_asm_exclusion_filter( + &self, + exclusion_filter_id: String, + ) -> Result<(), datadog::Error> { + match self + .delete_asm_exclusion_filter_with_http_info(exclusion_filter_id) + .await + { + Ok(_) => Ok(()), + Err(err) => Err(err), + } + } + + /// Delete a specific ASM Exclusion filter. + pub async fn delete_asm_exclusion_filter_with_http_info( + &self, + exclusion_filter_id: String, + ) -> Result, datadog::Error> { + let local_configuration = &self.config; + let operation_id = "v2.delete_asm_exclusion_filter"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/remote_config/products/asm/waf/exclusion_filters/{exclusion_filter_id}", + local_configuration.get_operation_host(operation_id), + exclusion_filter_id = datadog::urlencode(exclusion_filter_id) + ); + let mut local_req_builder = + local_client.request(reqwest::Method::DELETE, local_uri_str.as_str()); + + // build headers + let mut headers = HeaderMap::new(); + headers.insert("Accept", HeaderValue::from_static("*/*")); + + // 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() { + Ok(datadog::ResponseContent { + status: local_status, + content: local_content, + entity: None, + }) + } 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)) + } + } + + /// Retrieve a specific ASM exclusion filter by ID. + pub async fn get_asm_exclusion_filters( + &self, + exclusion_filter_id: String, + ) -> Result< + crate::datadogV2::model::ASMExclusionFilterResponse, + datadog::Error, + > { + match self + .get_asm_exclusion_filters_with_http_info(exclusion_filter_id) + .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), + } + } + + /// Retrieve a specific ASM exclusion filter by ID. + pub async fn get_asm_exclusion_filters_with_http_info( + &self, + exclusion_filter_id: String, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_asm_exclusion_filters"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/remote_config/products/asm/waf/exclusion_filters/{exclusion_filter_id}", + local_configuration.get_operation_host(operation_id), + exclusion_filter_id = datadog::urlencode(exclusion_filter_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)) + } + } + + /// Retrieve a list of ASM exclusion filters. + pub async fn list_asm_exclusion_filters( + &self, + ) -> Result< + crate::datadogV2::model::ASMExclusionFilterListResponse, + datadog::Error, + > { + match self.list_asm_exclusion_filters_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), + } + } + + /// Retrieve a list of ASM exclusion filters. + pub async fn list_asm_exclusion_filters_with_http_info( + &self, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.list_asm_exclusion_filters"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/remote_config/products/asm/waf/exclusion_filters", + 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 a specific Exclusion filter. + /// Returns the Exclusion filter object when the request is successful. + pub async fn update_asm_exclusion_filter( + &self, + exclusion_filter_id: String, + body: crate::datadogV2::model::ASMExclusionFilterUpdateRequest, + ) -> Result< + crate::datadogV2::model::ASMExclusionFilterResponse, + datadog::Error, + > { + match self + .update_asm_exclusion_filter_with_http_info(exclusion_filter_id, 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 a specific Exclusion filter. + /// Returns the Exclusion filter object when the request is successful. + pub async fn update_asm_exclusion_filter_with_http_info( + &self, + exclusion_filter_id: String, + body: crate::datadogV2::model::ASMExclusionFilterUpdateRequest, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.update_asm_exclusion_filter"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/remote_config/products/asm/waf/exclusion_filters/{exclusion_filter_id}", + local_configuration.get_operation_host(operation_id), + exclusion_filter_id = datadog::urlencode(exclusion_filter_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 f8c2eaa47..3c11cdab7 100644 --- a/src/datadogV2/api/mod.rs +++ b/src/datadogV2/api/mod.rs @@ -4,6 +4,7 @@ pub mod api_api_management; pub mod api_apm_retention_filters; +pub mod api_asm_exclusion_filters; pub mod api_audit; pub mod api_authn_mappings; pub mod api_case_management; diff --git a/src/datadogV2/mod.rs b/src/datadogV2/mod.rs index 43e99b9a8..54f73fda4 100644 --- a/src/datadogV2/mod.rs +++ b/src/datadogV2/mod.rs @@ -5,6 +5,7 @@ pub mod api; pub use self::api::api_api_management; pub use self::api::api_apm_retention_filters; +pub use self::api::api_asm_exclusion_filters; pub use self::api::api_audit; pub use self::api::api_authn_mappings; pub use self::api::api_case_management; diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 01586e021..469270ac9 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -2086,6 +2086,42 @@ pub mod model_timeseries_response_series; pub use self::model_timeseries_response_series::TimeseriesResponseSeries; pub mod model_timeseries_formula_response_type; pub use self::model_timeseries_formula_response_type::TimeseriesFormulaResponseType; +pub mod model_asm_exclusion_filter_list_response; +pub use self::model_asm_exclusion_filter_list_response::ASMExclusionFilterListResponse; +pub mod model_asm_exclusion_list_filter_data; +pub use self::model_asm_exclusion_list_filter_data::ASMExclusionListFilterData; +pub mod model_asm_exclusion_filter_list_attributes; +pub use self::model_asm_exclusion_filter_list_attributes::ASMExclusionFilterListAttributes; +pub mod model_asm_exclusion_filter_metadata; +pub use self::model_asm_exclusion_filter_metadata::ASMExclusionFilterMetadata; +pub mod model_asm_exclusion_filter_list_rules_target; +pub use self::model_asm_exclusion_filter_list_rules_target::ASMExclusionFilterListRulesTarget; +pub mod model_asm_exclusion_filter_list_rules_target_tags; +pub use self::model_asm_exclusion_filter_list_rules_target_tags::ASMExclusionFilterListRulesTargetTags; +pub mod model_asm_exclusion_filter_scope; +pub use self::model_asm_exclusion_filter_scope::ASMExclusionFilterScope; +pub mod model_asm_exclusion_filter_type; +pub use self::model_asm_exclusion_filter_type::ASMExclusionFilterType; +pub mod model_asm_exclusion_filter_create_request; +pub use self::model_asm_exclusion_filter_create_request::ASMExclusionFilterCreateRequest; +pub mod model_asm_exclusion_filter_create_data; +pub use self::model_asm_exclusion_filter_create_data::ASMExclusionFilterCreateData; +pub mod model_asm_exclusion_filter_create_attributes; +pub use self::model_asm_exclusion_filter_create_attributes::ASMExclusionFilterCreateAttributes; +pub mod model_asm_exclusion_filter_rules_target; +pub use self::model_asm_exclusion_filter_rules_target::ASMExclusionFilterRulesTarget; +pub mod model_asm_exclusion_filter_response; +pub use self::model_asm_exclusion_filter_response::ASMExclusionFilterResponse; +pub mod model_asm_exclusion_filter_data; +pub use self::model_asm_exclusion_filter_data::ASMExclusionFilterData; +pub mod model_asm_exclusion_filter_attributes; +pub use self::model_asm_exclusion_filter_attributes::ASMExclusionFilterAttributes; +pub mod model_asm_exclusion_filter_update_request; +pub use self::model_asm_exclusion_filter_update_request::ASMExclusionFilterUpdateRequest; +pub mod model_asm_exclusion_filter_update_data; +pub use self::model_asm_exclusion_filter_update_data::ASMExclusionFilterUpdateData; +pub mod model_asm_exclusion_filter_update_attributes; +pub use self::model_asm_exclusion_filter_update_attributes::ASMExclusionFilterUpdateAttributes; pub mod model_cloud_workload_security_agent_rules_list_response; pub use self::model_cloud_workload_security_agent_rules_list_response::CloudWorkloadSecurityAgentRulesListResponse; pub mod model_cloud_workload_security_agent_rule_data; diff --git a/src/datadogV2/model/model_asm_exclusion_filter_attributes.rs b/src/datadogV2/model/model_asm_exclusion_filter_attributes.rs new file mode 100644 index 000000000..7e09be441 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_attributes.rs @@ -0,0 +1,215 @@ +// 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 attributes of the ASM WAF exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterAttributes { + /// A description for the exclusion filter. + #[serde(rename = "description")] + pub description: Option, + /// Indicates whether the exclusion filter is enabled. + #[serde(rename = "enabled")] + pub enabled: Option, + /// The IPs list for the exclusion filter. + #[serde(rename = "ip_list")] + pub ip_list: Option>, + /// Metadata about the exclusion filter. + #[serde(rename = "metadata")] + pub metadata: Option, + /// The path glob for the exclusion filter. + #[serde(rename = "path_glob")] + pub path_glob: Option, + /// A list of rules targeted by the exclusion filter. + #[serde(rename = "rules_target")] + pub rules_target: Option>, + /// The scope of the exclusion filter. + #[serde(rename = "scope")] + pub scope: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterAttributes { + pub fn new() -> ASMExclusionFilterAttributes { + ASMExclusionFilterAttributes { + description: None, + enabled: None, + ip_list: None, + metadata: None, + path_glob: None, + rules_target: None, + scope: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn description(mut self, value: String) -> Self { + self.description = Some(value); + self + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn ip_list(mut self, value: Vec) -> Self { + self.ip_list = Some(value); + self + } + + pub fn metadata(mut self, value: crate::datadogV2::model::ASMExclusionFilterMetadata) -> Self { + self.metadata = Some(value); + self + } + + pub fn path_glob(mut self, value: String) -> Self { + self.path_glob = Some(value); + self + } + + pub fn rules_target( + mut self, + value: Vec, + ) -> Self { + self.rules_target = Some(value); + self + } + + pub fn scope(mut self, value: Vec) -> Self { + self.scope = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterAttributesVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterAttributesVisitor { + type Value = ASMExclusionFilterAttributes; + + 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 description: Option = None; + let mut enabled: Option = None; + let mut ip_list: Option> = None; + let mut metadata: Option = + None; + let mut path_glob: Option = None; + let mut rules_target: Option< + Vec, + > = None; + let mut scope: 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() { + "description" => { + if v.is_null() { + continue; + } + description = + 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)?); + } + "ip_list" => { + if v.is_null() { + continue; + } + ip_list = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "metadata" => { + if v.is_null() { + continue; + } + metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "path_glob" => { + if v.is_null() { + continue; + } + path_glob = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "rules_target" => { + if v.is_null() { + continue; + } + rules_target = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + if v.is_null() { + continue; + } + scope = 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 = ASMExclusionFilterAttributes { + description, + enabled, + ip_list, + metadata, + path_glob, + rules_target, + scope, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_create_attributes.rs b/src/datadogV2/model/model_asm_exclusion_filter_create_attributes.rs new file mode 100644 index 000000000..8c79e62ce --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_create_attributes.rs @@ -0,0 +1,178 @@ +// 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}; + +/// Create a new ASM WAF exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterCreateAttributes { + /// A description for the exclusion filter. + #[serde(rename = "description")] + pub description: String, + /// Indicates whether the exclusion filter is enabled. + #[serde(rename = "enabled")] + pub enabled: bool, + /// The IPs list for the exclusion filter. + #[serde(rename = "ip_list")] + pub ip_list: Option>, + /// The path glob for the exclusion filter. + #[serde(rename = "path_glob")] + pub path_glob: Option, + /// A list of rules targeted by the exclusion filter. + #[serde(rename = "rules_target")] + pub rules_target: Option>, + /// The scope of the exclusion filter. + #[serde(rename = "scope")] + pub scope: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterCreateAttributes { + pub fn new(description: String, enabled: bool) -> ASMExclusionFilterCreateAttributes { + ASMExclusionFilterCreateAttributes { + description, + enabled, + ip_list: None, + path_glob: None, + rules_target: None, + scope: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn ip_list(mut self, value: Vec) -> Self { + self.ip_list = Some(value); + self + } + + pub fn path_glob(mut self, value: String) -> Self { + self.path_glob = Some(value); + self + } + + pub fn rules_target( + mut self, + value: Vec, + ) -> Self { + self.rules_target = Some(value); + self + } + + pub fn scope(mut self, value: Vec) -> Self { + self.scope = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterCreateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterCreateAttributesVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterCreateAttributesVisitor { + type Value = ASMExclusionFilterCreateAttributes; + + 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 description: Option = None; + let mut enabled: Option = None; + let mut ip_list: Option> = None; + let mut path_glob: Option = None; + let mut rules_target: Option< + Vec, + > = None; + let mut scope: 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() { + "description" => { + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ip_list" => { + if v.is_null() { + continue; + } + ip_list = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "path_glob" => { + if v.is_null() { + continue; + } + path_glob = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "rules_target" => { + if v.is_null() { + continue; + } + rules_target = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + if v.is_null() { + continue; + } + scope = 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 description = + description.ok_or_else(|| M::Error::missing_field("description"))?; + let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?; + + let content = ASMExclusionFilterCreateAttributes { + description, + enabled, + ip_list, + path_glob, + rules_target, + scope, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterCreateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_create_data.rs b/src/datadogV2/model/model_asm_exclusion_filter_create_data.rs new file mode 100644 index 000000000..4506e57c1 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_create_data.rs @@ -0,0 +1,115 @@ +// 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}; + +/// Object for a single exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterCreateData { + /// Create a new ASM WAF exclusion filter. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::ASMExclusionFilterCreateAttributes, + /// The type of the resource. The value should always be `exclusion_filter`. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ASMExclusionFilterType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterCreateData { + pub fn new( + attributes: crate::datadogV2::model::ASMExclusionFilterCreateAttributes, + type_: crate::datadogV2::model::ASMExclusionFilterType, + ) -> ASMExclusionFilterCreateData { + ASMExclusionFilterCreateData { + attributes, + type_, + 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 ASMExclusionFilterCreateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterCreateDataVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterCreateDataVisitor { + type Value = ASMExclusionFilterCreateData; + + 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::ASMExclusionFilterCreateAttributes, + > = 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" => { + attributes = 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::ASMExclusionFilterType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ASMExclusionFilterCreateData { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterCreateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_create_request.rs b/src/datadogV2/model/model_asm_exclusion_filter_create_request.rs new file mode 100644 index 000000000..18ed7fdf3 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_create_request.rs @@ -0,0 +1,94 @@ +// 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 object that includes the exclusion filter to create. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterCreateRequest { + /// Object for a single exclusion filter. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::ASMExclusionFilterCreateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterCreateRequest { + pub fn new( + data: crate::datadogV2::model::ASMExclusionFilterCreateData, + ) -> ASMExclusionFilterCreateRequest { + ASMExclusionFilterCreateRequest { + 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 ASMExclusionFilterCreateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterCreateRequestVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterCreateRequestVisitor { + type Value = ASMExclusionFilterCreateRequest; + + 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 = ASMExclusionFilterCreateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterCreateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_data.rs b/src/datadogV2/model/model_asm_exclusion_filter_data.rs new file mode 100644 index 000000000..b56d84064 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_data.rs @@ -0,0 +1,151 @@ +// 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}; + +/// Object for a single Exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterData { + /// The attributes of the ASM WAF exclusion filter. + #[serde(rename = "attributes")] + pub attributes: Option, + /// The ID of the Exclusion filter. + #[serde(rename = "id")] + pub id: Option, + /// The type of the resource. The value should always be `exclusion_filter`. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterData { + pub fn new() -> ASMExclusionFilterData { + ASMExclusionFilterData { + attributes: None, + id: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::ASMExclusionFilterAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::ASMExclusionFilterType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterData { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterDataVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterDataVisitor { + type Value = ASMExclusionFilterData; + + 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" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::ASMExclusionFilterType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = ASMExclusionFilterData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterDataVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_list_attributes.rs b/src/datadogV2/model/model_asm_exclusion_filter_list_attributes.rs new file mode 100644 index 000000000..cfda99147 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_list_attributes.rs @@ -0,0 +1,215 @@ +// 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 attributes of the ASM WAF exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterListAttributes { + /// A description for the exclusion filter. + #[serde(rename = "description")] + pub description: Option, + /// Indicates whether the exclusion filter is enabled. + #[serde(rename = "enabled")] + pub enabled: Option, + /// The IPs list for the exclusion filter. + #[serde(rename = "ip_list")] + pub ip_list: Option>, + /// Metadata about the exclusion filter. + #[serde(rename = "metadata")] + pub metadata: Option, + /// The path glob for the exclusion filter. + #[serde(rename = "path_glob")] + pub path_glob: Option, + /// A list of rules targeted by the exclusion filter. + #[serde(rename = "rules_target")] + pub rules_target: Option>, + /// The scope of the exclusion filter. + #[serde(rename = "scope")] + pub scope: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterListAttributes { + pub fn new() -> ASMExclusionFilterListAttributes { + ASMExclusionFilterListAttributes { + description: None, + enabled: None, + ip_list: None, + metadata: None, + path_glob: None, + rules_target: None, + scope: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn description(mut self, value: String) -> Self { + self.description = Some(value); + self + } + + pub fn enabled(mut self, value: bool) -> Self { + self.enabled = Some(value); + self + } + + pub fn ip_list(mut self, value: Vec) -> Self { + self.ip_list = Some(value); + self + } + + pub fn metadata(mut self, value: crate::datadogV2::model::ASMExclusionFilterMetadata) -> Self { + self.metadata = Some(value); + self + } + + pub fn path_glob(mut self, value: String) -> Self { + self.path_glob = Some(value); + self + } + + pub fn rules_target( + mut self, + value: Vec, + ) -> Self { + self.rules_target = Some(value); + self + } + + pub fn scope(mut self, value: Vec) -> Self { + self.scope = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterListAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterListAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterListAttributesVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterListAttributesVisitor { + type Value = ASMExclusionFilterListAttributes; + + 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 description: Option = None; + let mut enabled: Option = None; + let mut ip_list: Option> = None; + let mut metadata: Option = + None; + let mut path_glob: Option = None; + let mut rules_target: Option< + Vec, + > = None; + let mut scope: 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() { + "description" => { + if v.is_null() { + continue; + } + description = + 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)?); + } + "ip_list" => { + if v.is_null() { + continue; + } + ip_list = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "metadata" => { + if v.is_null() { + continue; + } + metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "path_glob" => { + if v.is_null() { + continue; + } + path_glob = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "rules_target" => { + if v.is_null() { + continue; + } + rules_target = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + if v.is_null() { + continue; + } + scope = 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 = ASMExclusionFilterListAttributes { + description, + enabled, + ip_list, + metadata, + path_glob, + rules_target, + scope, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterListAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_list_response.rs b/src/datadogV2/model/model_asm_exclusion_filter_list_response.rs new file mode 100644 index 000000000..43247f099 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_list_response.rs @@ -0,0 +1,106 @@ +// 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 object that includes a list of exclusion filters. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterListResponse { + /// The ASMExclusionFilterResponse data. + #[serde(rename = "data")] + pub data: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterListResponse { + pub fn new() -> ASMExclusionFilterListResponse { + ASMExclusionFilterListResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: Vec) -> 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 ASMExclusionFilterListResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterListResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterListResponseVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterListResponseVisitor { + type Value = ASMExclusionFilterListResponse; + + 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 = ASMExclusionFilterListResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterListResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target.rs b/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target.rs new file mode 100644 index 000000000..56050f671 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target.rs @@ -0,0 +1,110 @@ +// 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}; + +/// A rule targeted by the exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterListRulesTarget { + /// Tags identifying the category and type of the targeted rule. + #[serde(rename = "tags")] + pub tags: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterListRulesTarget { + pub fn new() -> ASMExclusionFilterListRulesTarget { + ASMExclusionFilterListRulesTarget { + tags: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn tags( + mut self, + value: crate::datadogV2::model::ASMExclusionFilterListRulesTargetTags, + ) -> Self { + self.tags = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterListRulesTarget { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterListRulesTarget { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterListRulesTargetVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterListRulesTargetVisitor { + type Value = ASMExclusionFilterListRulesTarget; + + 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 tags: Option< + crate::datadogV2::model::ASMExclusionFilterListRulesTargetTags, + > = 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() { + "tags" => { + if v.is_null() { + continue; + } + tags = 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 = ASMExclusionFilterListRulesTarget { + tags, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterListRulesTargetVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target_tags.rs b/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target_tags.rs new file mode 100644 index 000000000..18d3b073b --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_list_rules_target_tags.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}; + +/// Tags identifying the category and type of the targeted rule. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterListRulesTargetTags { + /// The category of the rule. + #[serde(rename = "category")] + pub category: Option, + /// The type of the rule. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterListRulesTargetTags { + pub fn new() -> ASMExclusionFilterListRulesTargetTags { + ASMExclusionFilterListRulesTargetTags { + category: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn category(mut self, value: String) -> Self { + self.category = Some(value); + self + } + + pub fn type_(mut self, value: String) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterListRulesTargetTags { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterListRulesTargetTags { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterListRulesTargetTagsVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterListRulesTargetTagsVisitor { + type Value = ASMExclusionFilterListRulesTargetTags; + + 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 category: 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() { + "category" => { + if v.is_null() { + continue; + } + category = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = 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 = ASMExclusionFilterListRulesTargetTags { + category, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterListRulesTargetTagsVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_metadata.rs b/src/datadogV2/model/model_asm_exclusion_filter_metadata.rs new file mode 100644 index 000000000..4cdc83b4e --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_metadata.rs @@ -0,0 +1,158 @@ +// 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}; + +/// Metadata about the exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterMetadata { + /// The timestamp when the exclusion filter was added. + #[serde(rename = "added_at")] + pub added_at: Option>, + /// The email address of the user who added the exclusion filter. + #[serde(rename = "added_by")] + pub added_by: Option, + /// The timestamp when the exclusion filter was last modified. + #[serde(rename = "modified_at")] + pub modified_at: Option>, + /// The email address of the user who last modified the exclusion filter. + #[serde(rename = "modified_by")] + pub modified_by: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterMetadata { + pub fn new() -> ASMExclusionFilterMetadata { + ASMExclusionFilterMetadata { + added_at: None, + added_by: None, + modified_at: None, + modified_by: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn added_at(mut self, value: chrono::DateTime) -> Self { + self.added_at = Some(value); + self + } + + pub fn added_by(mut self, value: String) -> Self { + self.added_by = Some(value); + self + } + + pub fn modified_at(mut self, value: chrono::DateTime) -> Self { + self.modified_at = Some(value); + self + } + + pub fn modified_by(mut self, value: String) -> Self { + self.modified_by = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterMetadata { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterMetadata { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterMetadataVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterMetadataVisitor { + type Value = ASMExclusionFilterMetadata; + + 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 added_at: Option> = None; + let mut added_by: Option = None; + let mut modified_at: Option> = None; + let mut modified_by: 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() { + "added_at" => { + if v.is_null() { + continue; + } + added_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "added_by" => { + if v.is_null() { + continue; + } + added_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_at" => { + if v.is_null() { + continue; + } + modified_at = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "modified_by" => { + if v.is_null() { + continue; + } + modified_by = + 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 = ASMExclusionFilterMetadata { + added_at, + added_by, + modified_at, + modified_by, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterMetadataVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_response.rs b/src/datadogV2/model/model_asm_exclusion_filter_response.rs new file mode 100644 index 000000000..737776c7b --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_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 object that includes a list of exclusion filters. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterResponse { + /// The ASMExclusionFilterResponse data. + #[serde(rename = "data")] + pub data: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterResponse { + pub fn new() -> ASMExclusionFilterResponse { + ASMExclusionFilterResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: Vec) -> 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 ASMExclusionFilterResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterResponseVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterResponseVisitor { + type Value = ASMExclusionFilterResponse; + + 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 = ASMExclusionFilterResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_rules_target.rs b/src/datadogV2/model/model_asm_exclusion_filter_rules_target.rs new file mode 100644 index 000000000..62c0ed1b0 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_rules_target.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}; + +/// A rule targeted by the exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterRulesTarget { + /// The ID of the targeted rule. + #[serde(rename = "rule_id")] + pub rule_id: Option, + /// The name of the targeted rule. + #[serde(rename = "rule_name")] + pub rule_name: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterRulesTarget { + pub fn new() -> ASMExclusionFilterRulesTarget { + ASMExclusionFilterRulesTarget { + rule_id: None, + rule_name: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn rule_id(mut self, value: String) -> Self { + self.rule_id = Some(value); + self + } + + pub fn rule_name(mut self, value: String) -> Self { + self.rule_name = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterRulesTarget { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterRulesTarget { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterRulesTargetVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterRulesTargetVisitor { + type Value = ASMExclusionFilterRulesTarget; + + 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 rule_id: Option = None; + let mut rule_name: 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() { + "rule_id" => { + if v.is_null() { + continue; + } + rule_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "rule_name" => { + if v.is_null() { + continue; + } + rule_name = 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 = ASMExclusionFilterRulesTarget { + rule_id, + rule_name, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterRulesTargetVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_scope.rs b/src/datadogV2/model/model_asm_exclusion_filter_scope.rs new file mode 100644 index 000000000..0d5424c57 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_scope.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 scope of the exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterScope { + /// The environment scope for the exclusion filter. + #[serde(rename = "env")] + pub env: Option, + /// The service scope for the exclusion filter. + #[serde(rename = "service")] + pub service: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterScope { + pub fn new() -> ASMExclusionFilterScope { + ASMExclusionFilterScope { + env: None, + service: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn env(mut self, value: String) -> Self { + self.env = Some(value); + self + } + + pub fn service(mut self, value: String) -> Self { + self.service = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionFilterScope { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterScope { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterScopeVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterScopeVisitor { + type Value = ASMExclusionFilterScope; + + 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 env: Option = None; + let mut service: 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() { + "env" => { + if v.is_null() { + continue; + } + env = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "service" => { + if v.is_null() { + continue; + } + service = 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 = ASMExclusionFilterScope { + env, + service, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterScopeVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_type.rs b/src/datadogV2/model/model_asm_exclusion_filter_type.rs new file mode 100644 index 000000000..8dc68ae63 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_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 ASMExclusionFilterType { + EXCLUSION_FILTER, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ASMExclusionFilterType { + fn to_string(&self) -> String { + match self { + Self::EXCLUSION_FILTER => String::from("exclusion_filter"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ASMExclusionFilterType { + 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 ASMExclusionFilterType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "exclusion_filter" => Self::EXCLUSION_FILTER, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_update_attributes.rs b/src/datadogV2/model/model_asm_exclusion_filter_update_attributes.rs new file mode 100644 index 000000000..24dadabbb --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_update_attributes.rs @@ -0,0 +1,178 @@ +// 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}; + +/// Update an existing ASM Exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterUpdateAttributes { + /// The description of the Exclusion filter. + #[serde(rename = "description")] + pub description: String, + /// Whether the Exclusion filter is enabled. + #[serde(rename = "enabled")] + pub enabled: bool, + /// The IPs list for the exclusion filter. + #[serde(rename = "ip_list")] + pub ip_list: Option>, + /// The path glob for the exclusion filter. + #[serde(rename = "path_glob")] + pub path_glob: Option, + /// A list of rules targeted by the exclusion filter. + #[serde(rename = "rules_target")] + pub rules_target: Option>, + /// The scope of the exclusion filter. + #[serde(rename = "scope")] + pub scope: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterUpdateAttributes { + pub fn new(description: String, enabled: bool) -> ASMExclusionFilterUpdateAttributes { + ASMExclusionFilterUpdateAttributes { + description, + enabled, + ip_list: None, + path_glob: None, + rules_target: None, + scope: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn ip_list(mut self, value: Vec) -> Self { + self.ip_list = Some(value); + self + } + + pub fn path_glob(mut self, value: String) -> Self { + self.path_glob = Some(value); + self + } + + pub fn rules_target( + mut self, + value: Vec, + ) -> Self { + self.rules_target = Some(value); + self + } + + pub fn scope(mut self, value: Vec) -> Self { + self.scope = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ASMExclusionFilterUpdateAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterUpdateAttributesVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterUpdateAttributesVisitor { + type Value = ASMExclusionFilterUpdateAttributes; + + 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 description: Option = None; + let mut enabled: Option = None; + let mut ip_list: Option> = None; + let mut path_glob: Option = None; + let mut rules_target: Option< + Vec, + > = None; + let mut scope: 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() { + "description" => { + description = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "enabled" => { + enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "ip_list" => { + if v.is_null() { + continue; + } + ip_list = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "path_glob" => { + if v.is_null() { + continue; + } + path_glob = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "rules_target" => { + if v.is_null() { + continue; + } + rules_target = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + if v.is_null() { + continue; + } + scope = 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 description = + description.ok_or_else(|| M::Error::missing_field("description"))?; + let enabled = enabled.ok_or_else(|| M::Error::missing_field("enabled"))?; + + let content = ASMExclusionFilterUpdateAttributes { + description, + enabled, + ip_list, + path_glob, + rules_target, + scope, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterUpdateAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_update_data.rs b/src/datadogV2/model/model_asm_exclusion_filter_update_data.rs new file mode 100644 index 000000000..e97637ae6 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_update_data.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}; + +/// Object for a single Exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterUpdateData { + /// Update an existing ASM Exclusion filter. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::ASMExclusionFilterUpdateAttributes, + /// The ID of the exclusion filter. + #[serde(rename = "id")] + pub id: Option, + /// The type of the resource. The value should always be `exclusion_filter`. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ASMExclusionFilterType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterUpdateData { + pub fn new( + attributes: crate::datadogV2::model::ASMExclusionFilterUpdateAttributes, + type_: crate::datadogV2::model::ASMExclusionFilterType, + ) -> ASMExclusionFilterUpdateData { + ASMExclusionFilterUpdateData { + attributes, + id: None, + type_, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn id(mut self, value: String) -> 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 ASMExclusionFilterUpdateData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterUpdateDataVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterUpdateDataVisitor { + type Value = ASMExclusionFilterUpdateData; + + 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::ASMExclusionFilterUpdateAttributes, + > = 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" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "id" => { + if v.is_null() { + continue; + } + 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::ASMExclusionFilterType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ASMExclusionFilterUpdateData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterUpdateDataVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_filter_update_request.rs b/src/datadogV2/model/model_asm_exclusion_filter_update_request.rs new file mode 100644 index 000000000..e12981340 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_filter_update_request.rs @@ -0,0 +1,94 @@ +// 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 object that includes the Exclusion filter with the attributes to update. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionFilterUpdateRequest { + /// Object for a single Exclusion filter. + #[serde(rename = "data")] + pub data: crate::datadogV2::model::ASMExclusionFilterUpdateData, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionFilterUpdateRequest { + pub fn new( + data: crate::datadogV2::model::ASMExclusionFilterUpdateData, + ) -> ASMExclusionFilterUpdateRequest { + ASMExclusionFilterUpdateRequest { + 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 ASMExclusionFilterUpdateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionFilterUpdateRequestVisitor; + impl<'a> Visitor<'a> for ASMExclusionFilterUpdateRequestVisitor { + type Value = ASMExclusionFilterUpdateRequest; + + 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 = ASMExclusionFilterUpdateRequest { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionFilterUpdateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_asm_exclusion_list_filter_data.rs b/src/datadogV2/model/model_asm_exclusion_list_filter_data.rs new file mode 100644 index 000000000..1a36538e5 --- /dev/null +++ b/src/datadogV2/model/model_asm_exclusion_list_filter_data.rs @@ -0,0 +1,152 @@ +// 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}; + +/// Object for a single Exclusion filter. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ASMExclusionListFilterData { + /// The attributes of the ASM WAF exclusion filter. + #[serde(rename = "attributes")] + pub attributes: Option, + /// The ID of the Exclusion filter. + #[serde(rename = "id")] + pub id: Option, + /// The type of the resource. The value should always be `exclusion_filter`. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ASMExclusionListFilterData { + pub fn new() -> ASMExclusionListFilterData { + ASMExclusionListFilterData { + attributes: None, + id: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::ASMExclusionFilterListAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn id(mut self, value: String) -> Self { + self.id = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::ASMExclusionFilterType) -> Self { + self.type_ = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ASMExclusionListFilterData { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ASMExclusionListFilterData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ASMExclusionListFilterDataVisitor; + impl<'a> Visitor<'a> for ASMExclusionListFilterDataVisitor { + type Value = ASMExclusionListFilterData; + + 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::ASMExclusionFilterListAttributes, + > = 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" => { + if v.is_null() { + continue; + } + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + if v.is_null() { + continue; + } + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV2::model::ASMExclusionFilterType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = ASMExclusionListFilterData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ASMExclusionListFilterDataVisitor) + } +} diff --git a/tests/scenarios/features/v2/asm_exclusion_filters.feature b/tests/scenarios/features/v2/asm_exclusion_filters.feature new file mode 100644 index 000000000..56e415b46 --- /dev/null +++ b/tests/scenarios/features/v2/asm_exclusion_filters.feature @@ -0,0 +1,89 @@ +@endpoint(asm-exclusion-filters) @endpoint(asm-exclusion-filters-v2) +Feature: ASM Exclusion Filters + Exclusion filters in ASM libraries are used to circumvent false positives + in protection. + + Background: + Given a valid "apiKeyAuth" key in the system + And a valid "appKeyAuth" key in the system + And an instance of "ASMExclusionFilters" API + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Create a ASM WAF Exclusion filter returns "Bad Request" response + Given new "CreateASMExclusionFilter" request + And body with value {"data": {"type": "exclusion_filter"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Create a ASM WAF Exclusion filter returns "Conflict" response + Given new "CreateASMExclusionFilter" request + And body with value {"data": {"type": "exclusion_filter"}} + When the request is sent + Then the response status is 409 Conflict + + @skip @team:DataDog/asm-respond-backend + Scenario: Create a ASM WAF Exclusion filter returns "OK" response + Given new "CreateASMExclusionFilter" request + And body with value {"data": {"type": "exclusion_filter","attributes":{"description":"my description","enabled":true,"path_glob":"*","rules_target":[{"tags":{"category":"attack_attempt","type":"sql_injection"}}],"scope":[{"env":"staging","service":"container-resolver"}]}}} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Delete a ASM Exclusion Filter returns "Not Found" response + Given new "DeleteASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Delete a ASM Exclusion Filter returns "OK" response + Given new "DeleteASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 204 OK + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Get a specific ASM Exclusion Filter returns "OK" response + Given new "GetASMExclusionFilters" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: List ASM Exclusion Filters returns "OK" response + Given new "ListASMExclusionFilters" request + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Update a ASM Exclusion filter returns "Bad Request" response + Given new "UpdateASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"description": "My Exclusion filter", "enabled": true, "ip_list": ["127.0.0.1"], "path_glob": "/lfi_include/*", "rules_target": [{"rule_id": "dog-913-009", "rule_name": "WhiteHat Security OOB domain"}], "scope": [{"env": "dd-appsec-php-support", "service": "anil-php-weblog"}]}, "id": "3dd-0uc-h1s", "type": "exclusion_filter"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Update a ASM Exclusion filter returns "Concurrent Modification" response + Given new "UpdateASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"description": "My Exclusion filter", "enabled": true, "ip_list": ["127.0.0.1"], "path_glob": "/lfi_include/*", "rules_target": [{"rule_id": "dog-913-009", "rule_name": "WhiteHat Security OOB domain"}], "scope": [{"env": "dd-appsec-php-support", "service": "anil-php-weblog"}]}, "id": "3dd-0uc-h1s", "type": "exclusion_filter"}} + When the request is sent + Then the response status is 409 Concurrent Modification + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Update a ASM Exclusion filter returns "Not Found" response + Given new "UpdateASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"description": "My Exclusion filter", "enabled": true, "ip_list": ["127.0.0.1"], "path_glob": "/lfi_include/*", "rules_target": [{"rule_id": "dog-913-009", "rule_name": "WhiteHat Security OOB domain"}], "scope": [{"env": "dd-appsec-php-support", "service": "anil-php-weblog"}]}, "id": "3dd-0uc-h1s", "type": "exclusion_filter"}} + When the request is sent + Then the response status is 404 Not Found + + @generated @skip @team:DataDog/asm-respond-backend + Scenario: Update a ASM Exclusion filter returns "OK" response + Given new "UpdateASMExclusionFilter" request + And request contains "exclusion_filter_id" parameter from "REPLACE.ME" + And body with value {"data": {"attributes": {"description": "My Exclusion filter", "enabled": true, "ip_list": ["127.0.0.1"], "path_glob": "/lfi_include/*", "rules_target": [{"rule_id": "dog-913-009", "rule_name": "WhiteHat Security OOB domain"}], "scope": [{"env": "dd-appsec-php-support", "service": "anil-php-weblog"}]}, "id": "3dd-0uc-h1s", "type": "exclusion_filter"}} + When the request is sent + Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/given.json b/tests/scenarios/features/v2/given.json index 65187625d..d9b1d6a99 100644 --- a/tests/scenarios/features/v2/given.json +++ b/tests/scenarios/features/v2/given.json @@ -379,6 +379,18 @@ "tag": "Powerpack", "operationId": "CreatePowerpack" }, + { + "parameters": [ + { + "name": "body", + "value": "{\n \"data\": {\n \"type\": \"exclusion_filter\",\n \"attributes\": {\n \"description\": \"My Exclusion Filter\",\n \"enabled\": true,\n \"path_glob\": \"*\",\n \"rules_target\": [\n {\n \"tags\": {\n \"category\":\"attack_attempt\",\n \"type\":\"xss\"\n }\n }\n ],\n \"scope\": [\n {\n \"env\": \"staging\",\n \"service\": \"event-query\"\n }\n ]\n }\n }\n}" + } + ], + "step": "there is a valid \"exclusion_filter\" in the system", + "key": "exclusion_filter", + "tag": "ASM Exclusion Filters", + "operationId": "CreateASMExclusionFilter" + }, { "parameters": [ { diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index c8228c1a9..12ae99663 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -1473,6 +1473,43 @@ "type": "idempotent" } }, + "ListASMExclusionFilters": { + "tag": "ASM Exclusion Filters", + "undo": { + "type": "safe" + } + }, + "CreateASMExclusionFilter": { + "tag": "ASM Exclusion Filters", + "undo": { + "operationId": "DeleteASMExclusionFilter", + "parameters": [ + { + "name": "exclusion_filter_id", + "source": "data.id" + } + ], + "type": "unsafe" + } + }, + "DeleteASMExclusionFilter": { + "tag": "ASM Exclusion Filters", + "undo": { + "type": "idempotent" + } + }, + "GetASMExclusionFilters": { + "tag": "ASM Exclusion Filters", + "undo": { + "type": "safe" + } + }, + "UpdateASMExclusionFilter": { + "tag": "ASM Exclusion Filters", + "undo": { + "type": "idempotent" + } + }, "ListCSMThreatsAgentRules": { "tag": "CSM Threats", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index d5aec076d..f034516b9 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -96,6 +96,8 @@ pub struct ApiInstances { Option, pub v2_api_powerpack: Option, pub v2_api_processes: Option, + pub v2_api_asm_exclusion_filters: + Option, pub v2_api_csm_threats: Option, pub v2_api_restriction_policies: Option, @@ -635,6 +637,12 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) { ), ); } + "ASMExclusionFilters" => { + world.api_instances.v2_api_asm_exclusion_filters = Some(datadogV2::api_asm_exclusion_filters::ASMExclusionFiltersAPI::with_client_and_config( + world.config.clone(), + world.http_client.as_ref().unwrap().clone() + )); + } "CSMThreats" => { world.api_instances.v2_api_csm_threats = Some( datadogV2::api_csm_threats::CSMThreatsAPI::with_client_and_config( @@ -2568,6 +2576,26 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.ListProcessesWithPagination".into(), test_v2_list_processes_with_pagination, ); + world.function_mappings.insert( + "v2.ListASMExclusionFilters".into(), + test_v2_list_asm_exclusion_filters, + ); + world.function_mappings.insert( + "v2.CreateASMExclusionFilter".into(), + test_v2_create_asm_exclusion_filter, + ); + world.function_mappings.insert( + "v2.DeleteASMExclusionFilter".into(), + test_v2_delete_asm_exclusion_filter, + ); + world.function_mappings.insert( + "v2.GetASMExclusionFilters".into(), + test_v2_get_asm_exclusion_filters, + ); + world.function_mappings.insert( + "v2.UpdateASMExclusionFilter".into(), + test_v2_update_asm_exclusion_filter, + ); world.function_mappings.insert( "v2.ListCSMThreatsAgentRules".into(), test_v2_list_csm_threats_agent_rules, @@ -19271,6 +19299,152 @@ fn test_v2_list_processes_with_pagination( world.response.code = 200; } +fn test_v2_list_asm_exclusion_filters( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_asm_exclusion_filters + .as_ref() + .expect("api instance not found"); + let response = match block_on(api.list_asm_exclusion_filters_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_create_asm_exclusion_filter( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_asm_exclusion_filters + .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.create_asm_exclusion_filter_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_delete_asm_exclusion_filter( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_asm_exclusion_filters + .as_ref() + .expect("api instance not found"); + let exclusion_filter_id = + serde_json::from_value(_parameters.get("exclusion_filter_id").unwrap().clone()).unwrap(); + let response = + match block_on(api.delete_asm_exclusion_filter_with_http_info(exclusion_filter_id)) { + 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_get_asm_exclusion_filters( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_asm_exclusion_filters + .as_ref() + .expect("api instance not found"); + let exclusion_filter_id = + serde_json::from_value(_parameters.get("exclusion_filter_id").unwrap().clone()).unwrap(); + let response = match block_on(api.get_asm_exclusion_filters_with_http_info(exclusion_filter_id)) + { + 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_update_asm_exclusion_filter( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_asm_exclusion_filters + .as_ref() + .expect("api instance not found"); + let exclusion_filter_id = + serde_json::from_value(_parameters.get("exclusion_filter_id").unwrap().clone()).unwrap(); + let body = serde_json::from_value(_parameters.get("body").unwrap().clone()).unwrap(); + let response = + match block_on(api.update_asm_exclusion_filter_with_http_info(exclusion_filter_id, 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_list_csm_threats_agent_rules( world: &mut DatadogWorld, _parameters: &HashMap,