diff --git a/.apigentools-info b/.apigentools-info index a87b3bd02..3d6f58a04 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-11-20 21:48:42.107867", - "spec_repo_commit": "34905ccb" + "regenerated": "2024-11-21 20:23:39.100315", + "spec_repo_commit": "ad36259c" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-11-20 21:48:42.126846", - "spec_repo_commit": "34905ccb" + "regenerated": "2024-11-21 20:23:39.119286", + "spec_repo_commit": "ad36259c" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 91a7d81a1..33e7c854d 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -4556,6 +4556,127 @@ components: format: int64 type: integer type: object + ChangeEventCustomAttributes: + description: Object representing custom change event attributes. + properties: + author: + $ref: '#/components/schemas/ChangeEventCustomAttributesAuthor' + change_metadata: + additionalProperties: {} + description: Free form object with information related to the `change` event. + Can be arbitrarily nested and contain any valid JSON. + example: + dd: + team: datadog_team + user_email: datadog@datadog.com + user_id: datadog_user_id + user_name: datadog_username + resource_link: datadog.com/feature/fallback_payments_test + type: object + changed_resource: + $ref: '#/components/schemas/ChangeEventCustomAttributesChangedResource' + impacted_resources: + description: 'A list of resources impacted by this change. It is recommended + to provide an impacted resource to display + + the change event at the right location. Only resources of type `service` + are supported.' + example: + - name: payments_api + type: service + items: + $ref: '#/components/schemas/ChangeEventCustomAttributesImpactedResourcesItems' + type: array + new_value: + additionalProperties: {} + description: Free form object to track new value of the changed resource. + example: + enabled: true + percentage: 50% + rule: + datacenter: devcycle.us1.prod + type: object + prev_value: + additionalProperties: {} + description: Free form object to track previous value of the changed resource. + example: + enabled: true + percentage: 10% + rule: + datacenter: devcycle.us1.prod + type: object + required: + - changed_resource + type: object + ChangeEventCustomAttributesAuthor: + description: Object representing the entity which made the change. Optional + field but if provided should include `type` and `name`. + properties: + name: + description: Author's name. Limited to 128 characters. + example: datadog@datadog.com + maxLength: 128 + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesAuthorType' + required: + - name + - type + type: object + ChangeEventCustomAttributesAuthorType: + description: Author's type. + enum: + - user + - system + example: user + type: string + x-enum-varnames: + - USER + - SYSTEM + ChangeEventCustomAttributesChangedResource: + description: Object representing a uniquely identified resource. Only the resource + type `feature_flag` is supported. + properties: + name: + description: Resource's name. + example: fallback_payments_test + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesChangedResourceType' + required: + - type + - name + type: object + ChangeEventCustomAttributesChangedResourceType: + description: Resource's type. + enum: + - feature_flag + example: feature_flag + type: string + x-enum-varnames: + - FEATURE_FLAG + ChangeEventCustomAttributesImpactedResourcesItems: + description: Object representing a uniquely identified resource. Only the resource + type `service` is supported. + properties: + name: + description: Resource's name. + example: payments_api + type: string + type: + $ref: '#/components/schemas/ChangeEventCustomAttributesImpactedResourcesItemsType' + required: + - type + - name + type: object + ChangeEventCustomAttributesImpactedResourcesItemsType: + description: Resource's type. + enum: + - service + example: service + type: string + x-enum-varnames: + - SERVICE ChargebackBreakdown: description: Charges breakdown. properties: @@ -9335,6 +9456,125 @@ components: example: Oh boy! type: string type: object + EventCategory: + description: Event category to identify the type of event. Only the value `change` + is supported. Support for other categories are coming. please reach out to + datadog support if you're interested. + enum: + - change + example: change + type: string + x-enum-varnames: + - CHANGE + EventCreateRequest: + description: Object representing an event creation request. + properties: + attributes: + $ref: '#/components/schemas/EventPayload' + type: + $ref: '#/components/schemas/EventCreateRequestType' + type: object + EventCreateRequestPayload: + description: Payload for creating an event. + properties: + data: + $ref: '#/components/schemas/EventCreateRequest' + type: object + EventCreateRequestType: + description: Entity type. + enum: + - event + example: event + type: string + x-enum-varnames: + - EVENT + EventCreateResponse: + description: Object containing an event response. + properties: + attributes: + $ref: '#/components/schemas/EventCreateResponseAttributes' + type: + description: Event type + example: event + type: string + type: object + EventCreateResponseAttributes: + description: JSON object containing all events attributes and their associated + values. + properties: + attributes: + $ref: '#/components/schemas/EventCreateResponseAttributesAttributes' + type: object + EventCreateResponseAttributesAttributes: + description: JSON object of attributes from your events. + properties: + evt: + $ref: '#/components/schemas/EventCreateResponseAttributesAttributesEvt' + type: object + EventCreateResponseAttributesAttributesEvt: + description: JSON object of event system attributes. + properties: + id: + description: Event id + type: string + type: object + EventCreateResponsePayload: + description: Response containing information about created event. + properties: + data: + $ref: '#/components/schemas/EventCreateResponse' + type: object + EventPayload: + description: Event attributes. + properties: + aggregation_key: + description: An arbitrary string to use for aggregation when correlating + events. Limited to 100 characters. + maxLength: 100 + type: string + attributes: + $ref: '#/components/schemas/EventPayloadAttributes' + category: + $ref: '#/components/schemas/EventCategory' + message: + description: The body of the event. Limited to 4000 characters. + example: payment_processed feature flag has been enabled + maxLength: 4000 + type: string + tags: + description: 'A list of tags to apply to the event. + + Refer to [Tags docs](https://docs.datadoghq.com/getting_started/tagging/).' + example: + - environment:test + items: + description: A tag. + type: string + type: array + timestamp: + description: 'Timestamp when the event occurred. Must follow [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) + format. + + For example `"2017-01-15T01:30:15.010000Z"`. + + Defaults to the timestamp of receipt. Limited to values no older than + 18 hours.' + type: string + title: + description: The event title. Limited to 500 characters. + example: payment_processed feature flag updated + maxLength: 500 + type: string + required: + - title + - category + - attributes + type: object + EventPayloadAttributes: + description: JSON object for custom attributes. Schema are different per each + event category. + oneOf: + - $ref: '#/components/schemas/ChangeEventCustomAttributes' EventPriority: description: The priority of the event's monitor. For example, `normal` or `low`. enum: @@ -31196,6 +31436,82 @@ paths: operator: OR permissions: - events_read + post: + description: This endpoint allows you to post events. Only events with `change` + category are under General Availability. + operationId: CreateEvent + requestBody: + content: + application/json: + examples: + json-request-body: + value: + data: + attributes: + attributes: + author: + name: datadog@datadog.com + type: user + change_metadata: + dd: + team: datadog_team + user_email: datadog@datadog.com + user_id: datadog_user_id + user_name: datadog_username + resource_link: datadog.com/feature/fallback_payments_test + changed_resource: + name: fallback_payments_test + type: feature_flag + impacted_resources: + - name: payments_api + type: service + new_value: + enabled: true + percentage: 50% + rule: + datacenter: devcycle.us1.prod + prev_value: + enabled: true + percentage: 10% + rule: + datacenter: devcycle.us1.prod + category: change + message: payment_processed feature flag has been enabled + tags: + - environment:test + title: payment_processed feature flag updated + type: event + schema: + $ref: '#/components/schemas/EventCreateRequestPayload' + description: Event request object + required: true + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/EventCreateResponsePayload' + description: OK + '400': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Bad request + '403': + content: + application/json: + schema: + $ref: '#/components/schemas/JSONAPIErrorResponse' + description: Forbidden + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + security: + - apiKeyAuth: [] + summary: Post an event + tags: + - Events + x-codegen-request-body-name: body /api/v2/events/search: post: description: 'List endpoint returns events that match an events search query. diff --git a/.generator/src/generator/formatter.py b/.generator/src/generator/formatter.py index bce71b288..bfe2f37df 100644 --- a/.generator/src/generator/formatter.py +++ b/.generator/src/generator/formatter.py @@ -624,10 +624,13 @@ def format_data_with_schema_dict( imports.add("std::collections::BTreeMap") if schema.get("additionalProperties") == {}: for k, v in data.items(): - if isinstance(v, (int, float)): + if isinstance(v, bool): + imports.add("serde_json::Value") + parameters += f'("{k}".to_string(), Value::from(\"{v}\")),' + elif isinstance(v, (int, float)): imports.add("serde_json::Value") parameters += f'("{k}".to_string(), Value::from({v})),' - if isinstance(v, str): + elif isinstance(v, str): imports.add("serde_json::Value") parameters += f'("{k}".to_string(), Value::from(\"{v}\")),' return f"BTreeMap::from([{parameters}])", imports diff --git a/examples/v2_events_CreateEvent.rs b/examples/v2_events_CreateEvent.rs new file mode 100644 index 000000000..e53d0c702 --- /dev/null +++ b/examples/v2_events_CreateEvent.rs @@ -0,0 +1,72 @@ +// Post an event returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_events::EventsAPI; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributes; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesAuthor; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesAuthorType; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesChangedResource; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesChangedResourceType; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesImpactedResourcesItems; +use datadog_api_client::datadogV2::model::ChangeEventCustomAttributesImpactedResourcesItemsType; +use datadog_api_client::datadogV2::model::EventCategory; +use datadog_api_client::datadogV2::model::EventCreateRequest; +use datadog_api_client::datadogV2::model::EventCreateRequestPayload; +use datadog_api_client::datadogV2::model::EventCreateRequestType; +use datadog_api_client::datadogV2::model::EventPayload; +use datadog_api_client::datadogV2::model::EventPayloadAttributes; +use serde_json::Value; +use std::collections::BTreeMap; + +#[tokio::main] +async fn main() { + let body = EventCreateRequestPayload::new().data( + EventCreateRequest::new() + .attributes( + EventPayload::new( + EventPayloadAttributes::ChangeEventCustomAttributes(Box::new( + ChangeEventCustomAttributes::new( + ChangeEventCustomAttributesChangedResource::new( + "fallback_payments_test".to_string(), + ChangeEventCustomAttributesChangedResourceType::FEATURE_FLAG, + ), + ) + .author(ChangeEventCustomAttributesAuthor::new( + "datadog@datadog.com".to_string(), + ChangeEventCustomAttributesAuthorType::USER, + )) + .change_metadata(BTreeMap::from([( + "resource_link".to_string(), + Value::from("datadog.com/feature/fallback_payments_test"), + )])) + .impacted_resources(vec![ + ChangeEventCustomAttributesImpactedResourcesItems::new( + "payments_api".to_string(), + ChangeEventCustomAttributesImpactedResourcesItemsType::SERVICE, + ), + ]) + .new_value(BTreeMap::from([ + ("enabled".to_string(), Value::from("True")), + ("percentage".to_string(), Value::from("50%")), + ])) + .prev_value(BTreeMap::from([ + ("enabled".to_string(), Value::from("True")), + ("percentage".to_string(), Value::from("10%")), + ])), + )), + EventCategory::CHANGE, + "payment_processed feature flag updated".to_string(), + ) + .message("payment_processed feature flag has been enabled".to_string()) + .tags(vec!["environment:test".to_string()]), + ) + .type_(EventCreateRequestType::EVENT), + ); + let configuration = datadog::Configuration::new(); + let api = EventsAPI::with_config(configuration); + let resp = api.create_event(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadogV2/api/api_events.rs b/src/datadogV2/api/api_events.rs index be74840d0..60336e9ca 100644 --- a/src/datadogV2/api/api_events.rs +++ b/src/datadogV2/api/api_events.rs @@ -77,6 +77,15 @@ impl SearchEventsOptionalParams { } } +/// CreateEventError is a struct for typed errors of method [`EventsAPI::create_event`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum CreateEventError { + JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + UnknownValue(serde_json::Value), +} + /// ListEventsError is a struct for typed errors of method [`EventsAPI::list_events`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -159,6 +168,150 @@ impl EventsAPI { Self { config, client } } + /// This endpoint allows you to post events. Only events with `change` category are under General Availability. + pub async fn create_event( + &self, + body: crate::datadogV2::model::EventCreateRequestPayload, + ) -> Result> + { + match self.create_event_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), + } + } + + /// This endpoint allows you to post events. Only events with `change` category are under General Availability. + pub async fn create_event_with_http_info( + &self, + body: crate::datadogV2::model::EventCreateRequestPayload, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.create_event"; + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/events", + 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"), + ); + }; + + // 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)) + } + } + /// List endpoint returns events that match an events search query. /// [Results are paginated similarly to logs](). /// diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 44651cd97..80a6be94e 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -1040,6 +1040,42 @@ pub mod model_events_response_metadata_page; pub use self::model_events_response_metadata_page::EventsResponseMetadataPage; pub mod model_events_warning; pub use self::model_events_warning::EventsWarning; +pub mod model_event_create_request_payload; +pub use self::model_event_create_request_payload::EventCreateRequestPayload; +pub mod model_event_create_request; +pub use self::model_event_create_request::EventCreateRequest; +pub mod model_event_payload; +pub use self::model_event_payload::EventPayload; +pub mod model_change_event_custom_attributes; +pub use self::model_change_event_custom_attributes::ChangeEventCustomAttributes; +pub mod model_change_event_custom_attributes_author; +pub use self::model_change_event_custom_attributes_author::ChangeEventCustomAttributesAuthor; +pub mod model_change_event_custom_attributes_author_type; +pub use self::model_change_event_custom_attributes_author_type::ChangeEventCustomAttributesAuthorType; +pub mod model_change_event_custom_attributes_changed_resource; +pub use self::model_change_event_custom_attributes_changed_resource::ChangeEventCustomAttributesChangedResource; +pub mod model_change_event_custom_attributes_changed_resource_type; +pub use self::model_change_event_custom_attributes_changed_resource_type::ChangeEventCustomAttributesChangedResourceType; +pub mod model_change_event_custom_attributes_impacted_resources_items; +pub use self::model_change_event_custom_attributes_impacted_resources_items::ChangeEventCustomAttributesImpactedResourcesItems; +pub mod model_change_event_custom_attributes_impacted_resources_items_type; +pub use self::model_change_event_custom_attributes_impacted_resources_items_type::ChangeEventCustomAttributesImpactedResourcesItemsType; +pub mod model_event_payload_attributes; +pub use self::model_event_payload_attributes::EventPayloadAttributes; +pub mod model_event_category; +pub use self::model_event_category::EventCategory; +pub mod model_event_create_request_type; +pub use self::model_event_create_request_type::EventCreateRequestType; +pub mod model_event_create_response_payload; +pub use self::model_event_create_response_payload::EventCreateResponsePayload; +pub mod model_event_create_response; +pub use self::model_event_create_response::EventCreateResponse; +pub mod model_event_create_response_attributes; +pub use self::model_event_create_response_attributes::EventCreateResponseAttributes; +pub mod model_event_create_response_attributes_attributes; +pub use self::model_event_create_response_attributes_attributes::EventCreateResponseAttributesAttributes; +pub mod model_event_create_response_attributes_attributes_evt; +pub use self::model_event_create_response_attributes_attributes_evt::EventCreateResponseAttributesAttributesEvt; pub mod model_events_list_request; pub use self::model_events_list_request::EventsListRequest; pub mod model_events_query_filter; diff --git a/src/datadogV2/model/model_change_event_custom_attributes.rs b/src/datadogV2/model/model_change_event_custom_attributes.rs new file mode 100644 index 000000000..804cc2338 --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes.rs @@ -0,0 +1,209 @@ +// 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 representing custom change event attributes. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ChangeEventCustomAttributes { + /// Object representing the entity which made the change. Optional field but if provided should include `type` and `name`. + #[serde(rename = "author")] + pub author: Option, + /// Free form object with information related to the `change` event. Can be arbitrarily nested and contain any valid JSON. + #[serde(rename = "change_metadata")] + pub change_metadata: Option>, + /// Object representing a uniquely identified resource. Only the resource type `feature_flag` is supported. + #[serde(rename = "changed_resource")] + pub changed_resource: crate::datadogV2::model::ChangeEventCustomAttributesChangedResource, + /// A list of resources impacted by this change. It is recommended to provide an impacted resource to display + /// the change event at the right location. Only resources of type `service` are supported. + #[serde(rename = "impacted_resources")] + pub impacted_resources: + Option>, + /// Free form object to track new value of the changed resource. + #[serde(rename = "new_value")] + pub new_value: Option>, + /// Free form object to track previous value of the changed resource. + #[serde(rename = "prev_value")] + pub prev_value: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ChangeEventCustomAttributes { + pub fn new( + changed_resource: crate::datadogV2::model::ChangeEventCustomAttributesChangedResource, + ) -> ChangeEventCustomAttributes { + ChangeEventCustomAttributes { + author: None, + change_metadata: None, + changed_resource, + impacted_resources: None, + new_value: None, + prev_value: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn author( + mut self, + value: crate::datadogV2::model::ChangeEventCustomAttributesAuthor, + ) -> Self { + self.author = Some(value); + self + } + + pub fn change_metadata( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.change_metadata = Some(value); + self + } + + pub fn impacted_resources( + mut self, + value: Vec, + ) -> Self { + self.impacted_resources = Some(value); + self + } + + pub fn new_value( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.new_value = Some(value); + self + } + + pub fn prev_value( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.prev_value = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for ChangeEventCustomAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ChangeEventCustomAttributesVisitor; + impl<'a> Visitor<'a> for ChangeEventCustomAttributesVisitor { + type Value = ChangeEventCustomAttributes; + + 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 author: Option = + None; + let mut change_metadata: Option< + std::collections::BTreeMap, + > = None; + let mut changed_resource: Option< + crate::datadogV2::model::ChangeEventCustomAttributesChangedResource, + > = None; + let mut impacted_resources: Option< + Vec, + > = None; + let mut new_value: Option> = + None; + let mut prev_value: 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() { + "author" => { + if v.is_null() { + continue; + } + author = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "change_metadata" => { + if v.is_null() { + continue; + } + change_metadata = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "changed_resource" => { + changed_resource = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "impacted_resources" => { + if v.is_null() { + continue; + } + impacted_resources = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "new_value" => { + if v.is_null() { + continue; + } + new_value = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "prev_value" => { + if v.is_null() { + continue; + } + prev_value = 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 changed_resource = + changed_resource.ok_or_else(|| M::Error::missing_field("changed_resource"))?; + + let content = ChangeEventCustomAttributes { + author, + change_metadata, + changed_resource, + impacted_resources, + new_value, + prev_value, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ChangeEventCustomAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_author.rs b/src/datadogV2/model/model_change_event_custom_attributes_author.rs new file mode 100644 index 000000000..f18b0ae18 --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_author.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 representing the entity which made the change. Optional field but if provided should include `type` and `name`. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ChangeEventCustomAttributesAuthor { + /// Author's name. Limited to 128 characters. + #[serde(rename = "name")] + pub name: String, + /// Author's type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ChangeEventCustomAttributesAuthorType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ChangeEventCustomAttributesAuthor { + pub fn new( + name: String, + type_: crate::datadogV2::model::ChangeEventCustomAttributesAuthorType, + ) -> ChangeEventCustomAttributesAuthor { + ChangeEventCustomAttributesAuthor { + name, + 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 ChangeEventCustomAttributesAuthor { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ChangeEventCustomAttributesAuthorVisitor; + impl<'a> Visitor<'a> for ChangeEventCustomAttributesAuthorVisitor { + type Value = ChangeEventCustomAttributesAuthor; + + 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 name: Option = None; + let mut type_: Option< + crate::datadogV2::model::ChangeEventCustomAttributesAuthorType, + > = 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() { + "name" => { + name = 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::ChangeEventCustomAttributesAuthorType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ChangeEventCustomAttributesAuthor { + name, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ChangeEventCustomAttributesAuthorVisitor) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_author_type.rs b/src/datadogV2/model/model_change_event_custom_attributes_author_type.rs new file mode 100644 index 000000000..9e657c6ca --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_author_type.rs @@ -0,0 +1,51 @@ +// 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 ChangeEventCustomAttributesAuthorType { + USER, + SYSTEM, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ChangeEventCustomAttributesAuthorType { + fn to_string(&self) -> String { + match self { + Self::USER => String::from("user"), + Self::SYSTEM => String::from("system"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ChangeEventCustomAttributesAuthorType { + 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 ChangeEventCustomAttributesAuthorType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "user" => Self::USER, + "system" => Self::SYSTEM, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_changed_resource.rs b/src/datadogV2/model/model_change_event_custom_attributes_changed_resource.rs new file mode 100644 index 000000000..e77f890cc --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_changed_resource.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 representing a uniquely identified resource. Only the resource type `feature_flag` is supported. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ChangeEventCustomAttributesChangedResource { + /// Resource's name. + #[serde(rename = "name")] + pub name: String, + /// Resource's type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ChangeEventCustomAttributesChangedResourceType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ChangeEventCustomAttributesChangedResource { + pub fn new( + name: String, + type_: crate::datadogV2::model::ChangeEventCustomAttributesChangedResourceType, + ) -> ChangeEventCustomAttributesChangedResource { + ChangeEventCustomAttributesChangedResource { + name, + 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 ChangeEventCustomAttributesChangedResource { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ChangeEventCustomAttributesChangedResourceVisitor; + impl<'a> Visitor<'a> for ChangeEventCustomAttributesChangedResourceVisitor { + type Value = ChangeEventCustomAttributesChangedResource; + + 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 name: Option = None; + let mut type_: Option< + crate::datadogV2::model::ChangeEventCustomAttributesChangedResourceType, + > = 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() { + "name" => { + name = 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::ChangeEventCustomAttributesChangedResourceType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ChangeEventCustomAttributesChangedResource { + name, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ChangeEventCustomAttributesChangedResourceVisitor) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_changed_resource_type.rs b/src/datadogV2/model/model_change_event_custom_attributes_changed_resource_type.rs new file mode 100644 index 000000000..2a0775426 --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_changed_resource_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 ChangeEventCustomAttributesChangedResourceType { + FEATURE_FLAG, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ChangeEventCustomAttributesChangedResourceType { + fn to_string(&self) -> String { + match self { + Self::FEATURE_FLAG => String::from("feature_flag"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ChangeEventCustomAttributesChangedResourceType { + 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 ChangeEventCustomAttributesChangedResourceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "feature_flag" => Self::FEATURE_FLAG, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items.rs b/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items.rs new file mode 100644 index 000000000..bfa7b99a3 --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items.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 representing a uniquely identified resource. Only the resource type `service` is supported. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ChangeEventCustomAttributesImpactedResourcesItems { + /// Resource's name. + #[serde(rename = "name")] + pub name: String, + /// Resource's type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ChangeEventCustomAttributesImpactedResourcesItemsType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ChangeEventCustomAttributesImpactedResourcesItems { + pub fn new( + name: String, + type_: crate::datadogV2::model::ChangeEventCustomAttributesImpactedResourcesItemsType, + ) -> ChangeEventCustomAttributesImpactedResourcesItems { + ChangeEventCustomAttributesImpactedResourcesItems { + name, + 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 ChangeEventCustomAttributesImpactedResourcesItems { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ChangeEventCustomAttributesImpactedResourcesItemsVisitor; + impl<'a> Visitor<'a> for ChangeEventCustomAttributesImpactedResourcesItemsVisitor { + type Value = ChangeEventCustomAttributesImpactedResourcesItems; + + 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 name: Option = None; + let mut type_: Option< + crate::datadogV2::model::ChangeEventCustomAttributesImpactedResourcesItemsType, + > = 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() { + "name" => { + name = 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::ChangeEventCustomAttributesImpactedResourcesItemsType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let name = name.ok_or_else(|| M::Error::missing_field("name"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ChangeEventCustomAttributesImpactedResourcesItems { + name, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ChangeEventCustomAttributesImpactedResourcesItemsVisitor) + } +} diff --git a/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items_type.rs b/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items_type.rs new file mode 100644 index 000000000..bbf9bec5d --- /dev/null +++ b/src/datadogV2/model/model_change_event_custom_attributes_impacted_resources_items_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 ChangeEventCustomAttributesImpactedResourcesItemsType { + SERVICE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ChangeEventCustomAttributesImpactedResourcesItemsType { + fn to_string(&self) -> String { + match self { + Self::SERVICE => String::from("service"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ChangeEventCustomAttributesImpactedResourcesItemsType { + 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 ChangeEventCustomAttributesImpactedResourcesItemsType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "service" => Self::SERVICE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_event_category.rs b/src/datadogV2/model/model_event_category.rs new file mode 100644 index 000000000..88e9853f0 --- /dev/null +++ b/src/datadogV2/model/model_event_category.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 EventCategory { + CHANGE, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for EventCategory { + fn to_string(&self) -> String { + match self { + Self::CHANGE => String::from("change"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for EventCategory { + 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 EventCategory { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "change" => Self::CHANGE, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_event_create_request.rs b/src/datadogV2/model/model_event_create_request.rs new file mode 100644 index 000000000..e3c94c233 --- /dev/null +++ b/src/datadogV2/model/model_event_create_request.rs @@ -0,0 +1,130 @@ +// 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 representing an event creation request. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateRequest { + /// Event attributes. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Entity type. + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateRequest { + pub fn new() -> EventCreateRequest { + EventCreateRequest { + attributes: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes(mut self, value: crate::datadogV2::model::EventPayload) -> Self { + self.attributes = Some(value); + self + } + + pub fn type_(mut self, value: crate::datadogV2::model::EventCreateRequestType) -> 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 EventCreateRequest { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateRequest { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateRequestVisitor; + impl<'a> Visitor<'a> for EventCreateRequestVisitor { + type Value = EventCreateRequest; + + 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 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)?); + } + "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::EventCreateRequestType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = EventCreateRequest { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateRequestVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_request_payload.rs b/src/datadogV2/model/model_event_create_request_payload.rs new file mode 100644 index 000000000..6c3647d74 --- /dev/null +++ b/src/datadogV2/model/model_event_create_request_payload.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}; + +/// Payload for creating an event. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateRequestPayload { + /// Object representing an event creation request. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateRequestPayload { + pub fn new() -> EventCreateRequestPayload { + EventCreateRequestPayload { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::EventCreateRequest) -> 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 EventCreateRequestPayload { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateRequestPayload { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateRequestPayloadVisitor; + impl<'a> Visitor<'a> for EventCreateRequestPayloadVisitor { + type Value = EventCreateRequestPayload; + + 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 = EventCreateRequestPayload { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateRequestPayloadVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_request_type.rs b/src/datadogV2/model/model_event_create_request_type.rs new file mode 100644 index 000000000..e23de3786 --- /dev/null +++ b/src/datadogV2/model/model_event_create_request_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 EventCreateRequestType { + EVENT, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for EventCreateRequestType { + fn to_string(&self) -> String { + match self { + Self::EVENT => String::from("event"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for EventCreateRequestType { + 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 EventCreateRequestType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "event" => Self::EVENT, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_event_create_response.rs b/src/datadogV2/model/model_event_create_response.rs new file mode 100644 index 000000000..f2221e65c --- /dev/null +++ b/src/datadogV2/model/model_event_create_response.rs @@ -0,0 +1,126 @@ +// 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 containing an event response. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateResponse { + /// JSON object containing all events attributes and their associated values. + #[serde(rename = "attributes")] + pub attributes: Option, + /// Event type + #[serde(rename = "type")] + pub type_: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateResponse { + pub fn new() -> EventCreateResponse { + EventCreateResponse { + attributes: None, + type_: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::EventCreateResponseAttributes, + ) -> Self { + self.attributes = 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 EventCreateResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateResponseVisitor; + impl<'a> Visitor<'a> for EventCreateResponseVisitor { + type Value = EventCreateResponse; + + 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 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)?); + } + "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 = EventCreateResponse { + attributes, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_response_attributes.rs b/src/datadogV2/model/model_event_create_response_attributes.rs new file mode 100644 index 000000000..62a509d30 --- /dev/null +++ b/src/datadogV2/model/model_event_create_response_attributes.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}; + +/// JSON object containing all events attributes and their associated values. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateResponseAttributes { + /// JSON object of attributes from your events. + #[serde(rename = "attributes")] + pub attributes: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateResponseAttributes { + pub fn new() -> EventCreateResponseAttributes { + EventCreateResponseAttributes { + attributes: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn attributes( + mut self, + value: crate::datadogV2::model::EventCreateResponseAttributesAttributes, + ) -> Self { + self.attributes = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for EventCreateResponseAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateResponseAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateResponseAttributesVisitor; + impl<'a> Visitor<'a> for EventCreateResponseAttributesVisitor { + type Value = EventCreateResponseAttributes; + + 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::EventCreateResponseAttributesAttributes, + > = 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)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + + let content = EventCreateResponseAttributes { + attributes, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateResponseAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_response_attributes_attributes.rs b/src/datadogV2/model/model_event_create_response_attributes_attributes.rs new file mode 100644 index 000000000..72263842e --- /dev/null +++ b/src/datadogV2/model/model_event_create_response_attributes_attributes.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}; + +/// JSON object of attributes from your events. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateResponseAttributesAttributes { + /// JSON object of event system attributes. + #[serde(rename = "evt")] + pub evt: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateResponseAttributesAttributes { + pub fn new() -> EventCreateResponseAttributesAttributes { + EventCreateResponseAttributesAttributes { + evt: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn evt( + mut self, + value: crate::datadogV2::model::EventCreateResponseAttributesAttributesEvt, + ) -> Self { + self.evt = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for EventCreateResponseAttributesAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateResponseAttributesAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateResponseAttributesAttributesVisitor; + impl<'a> Visitor<'a> for EventCreateResponseAttributesAttributesVisitor { + type Value = EventCreateResponseAttributesAttributes; + + 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 evt: Option< + crate::datadogV2::model::EventCreateResponseAttributesAttributesEvt, + > = 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() { + "evt" => { + if v.is_null() { + continue; + } + evt = 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 = EventCreateResponseAttributesAttributes { + evt, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateResponseAttributesAttributesVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_response_attributes_attributes_evt.rs b/src/datadogV2/model/model_event_create_response_attributes_attributes_evt.rs new file mode 100644 index 000000000..b84d12c63 --- /dev/null +++ b/src/datadogV2/model/model_event_create_response_attributes_attributes_evt.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}; + +/// JSON object of event system attributes. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateResponseAttributesAttributesEvt { + /// Event id + #[serde(rename = "id")] + pub id: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateResponseAttributesAttributesEvt { + pub fn new() -> EventCreateResponseAttributesAttributesEvt { + EventCreateResponseAttributesAttributesEvt { + id: None, + 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 Default for EventCreateResponseAttributesAttributesEvt { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateResponseAttributesAttributesEvt { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateResponseAttributesAttributesEvtVisitor; + impl<'a> Visitor<'a> for EventCreateResponseAttributesAttributesEvtVisitor { + type Value = EventCreateResponseAttributesAttributesEvt; + + 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 id: 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() { + "id" => { + if v.is_null() { + continue; + } + id = 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 = EventCreateResponseAttributesAttributesEvt { + id, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateResponseAttributesAttributesEvtVisitor) + } +} diff --git a/src/datadogV2/model/model_event_create_response_payload.rs b/src/datadogV2/model/model_event_create_response_payload.rs new file mode 100644 index 000000000..89502129a --- /dev/null +++ b/src/datadogV2/model/model_event_create_response_payload.rs @@ -0,0 +1,105 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Response containing information about created event. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventCreateResponsePayload { + /// Object containing an event response. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventCreateResponsePayload { + pub fn new() -> EventCreateResponsePayload { + EventCreateResponsePayload { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::EventCreateResponse) -> 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 EventCreateResponsePayload { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for EventCreateResponsePayload { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventCreateResponsePayloadVisitor; + impl<'a> Visitor<'a> for EventCreateResponsePayloadVisitor { + type Value = EventCreateResponsePayload; + + 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 = EventCreateResponsePayload { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventCreateResponsePayloadVisitor) + } +} diff --git a/src/datadogV2/model/model_event_payload.rs b/src/datadogV2/model/model_event_payload.rs new file mode 100644 index 000000000..bda36f4d2 --- /dev/null +++ b/src/datadogV2/model/model_event_payload.rs @@ -0,0 +1,206 @@ +// 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}; + +/// Event attributes. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct EventPayload { + /// An arbitrary string to use for aggregation when correlating events. Limited to 100 characters. + #[serde(rename = "aggregation_key")] + pub aggregation_key: Option, + /// JSON object for custom attributes. Schema are different per each event category. + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::EventPayloadAttributes, + /// Event category to identify the type of event. Only the value `change` is supported. Support for other categories are coming. please reach out to datadog support if you're interested. + #[serde(rename = "category")] + pub category: crate::datadogV2::model::EventCategory, + /// The body of the event. Limited to 4000 characters. + #[serde(rename = "message")] + pub message: Option, + /// A list of tags to apply to the event. + /// Refer to [Tags docs](). + #[serde(rename = "tags")] + pub tags: Option>, + /// Timestamp when the event occurred. Must follow [ISO 8601]() format. + /// For example `"2017-01-15T01:30:15.010000Z"`. + /// Defaults to the timestamp of receipt. Limited to values no older than 18 hours. + #[serde(rename = "timestamp")] + pub timestamp: Option, + /// The event title. Limited to 500 characters. + #[serde(rename = "title")] + pub title: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl EventPayload { + pub fn new( + attributes: crate::datadogV2::model::EventPayloadAttributes, + category: crate::datadogV2::model::EventCategory, + title: String, + ) -> EventPayload { + EventPayload { + aggregation_key: None, + attributes, + category, + message: None, + tags: None, + timestamp: None, + title, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn aggregation_key(mut self, value: String) -> Self { + self.aggregation_key = Some(value); + self + } + + pub fn message(mut self, value: String) -> Self { + self.message = Some(value); + self + } + + pub fn tags(mut self, value: Vec) -> Self { + self.tags = Some(value); + self + } + + pub fn timestamp(mut self, value: String) -> Self { + self.timestamp = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for EventPayload { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct EventPayloadVisitor; + impl<'a> Visitor<'a> for EventPayloadVisitor { + type Value = EventPayload; + + 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 aggregation_key: Option = None; + let mut attributes: Option = None; + let mut category: Option = None; + let mut message: Option = None; + let mut tags: Option> = None; + let mut timestamp: Option = None; + let mut title: 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() { + "aggregation_key" => { + if v.is_null() { + continue; + } + aggregation_key = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "attributes" => { + attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _attributes) = attributes { + match _attributes { + crate::datadogV2::model::EventPayloadAttributes::UnparsedObject(_attributes) => { + _unparsed = true; + }, + _ => {} + } + } + } + "category" => { + category = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _category) = category { + match _category { + crate::datadogV2::model::EventCategory::UnparsedObject( + _category, + ) => { + _unparsed = true; + } + _ => {} + } + } + } + "message" => { + if v.is_null() { + continue; + } + message = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "tags" => { + if v.is_null() { + continue; + } + tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "timestamp" => { + if v.is_null() { + continue; + } + timestamp = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "title" => { + title = 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 attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?; + let category = category.ok_or_else(|| M::Error::missing_field("category"))?; + let title = title.ok_or_else(|| M::Error::missing_field("title"))?; + + let content = EventPayload { + aggregation_key, + attributes, + category, + message, + tags, + timestamp, + title, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(EventPayloadVisitor) + } +} diff --git a/src/datadogV2/model/model_event_payload_attributes.rs b/src/datadogV2/model/model_event_payload_attributes.rs new file mode 100644 index 000000000..30e651ce1 --- /dev/null +++ b/src/datadogV2/model/model_event_payload_attributes.rs @@ -0,0 +1,34 @@ +// 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}; + +/// JSON object for custom attributes. Schema are different per each event category. +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum EventPayloadAttributes { + ChangeEventCustomAttributes(Box), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for EventPayloadAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value: serde_json::Value = Deserialize::deserialize(deserializer)?; + if let Ok(_v) = serde_json::from_value::< + Box, + >(value.clone()) + { + if !_v._unparsed { + return Ok(EventPayloadAttributes::ChangeEventCustomAttributes(_v)); + } + } + + return Ok(EventPayloadAttributes::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/tests/scenarios/features/v2/events.feature b/tests/scenarios/features/v2/events.feature index 9a1c79072..2013c242f 100644 --- a/tests/scenarios/features/v2/events.feature +++ b/tests/scenarios/features/v2/events.feature @@ -7,24 +7,26 @@ Feature: Events Background: Given a valid "apiKeyAuth" key in the system - And a valid "appKeyAuth" key in the system And an instance of "Events" API @generated @skip @team:DataDog/event-management Scenario: Get a list of events returns "Bad Request" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request When the request is sent Then the response status is 400 Bad Request @skip-validation @team:DataDog/event-management Scenario: Get a list of events returns "OK" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request When the request is sent Then the response status is 200 OK @replay-only @skip-validation @team:DataDog/event-management @with-pagination Scenario: Get a list of events returns "OK" response with pagination - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request And request contains "filter[from]" parameter with value "now-15m" And request contains "filter[to]" parameter with value "now" And request contains "page[limit]" parameter with value 2 @@ -34,7 +36,8 @@ Feature: Events @team:DataDog/event-management Scenario: Get a quick list of events returns "OK" response - Given new "ListEvents" request + Given a valid "appKeyAuth" key in the system + And new "ListEvents" request And request contains "filter[query]" parameter with value "datadog-agent" And request contains "filter[from]" parameter with value "2020-09-17T11:48:36+01:00" And request contains "filter[to]" parameter with value "2020-09-17T12:48:36+01:00" @@ -43,16 +46,32 @@ Feature: Events Then the response status is 200 OK And the response "data" has length 0 + @generated @skip @team:DataDog/event-management + Scenario: Post an event returns "Bad request" response + Given new "CreateEvent" request + And body with value {"data": {"attributes": {"attributes": {"author": {"name": "datadog@datadog.com", "type": "user"}, "change_metadata": {"dd": {"team": "datadog_team", "user_email": "datadog@datadog.com", "user_id": "datadog_user_id", "user_name": "datadog_username"}, "resource_link": "datadog.com/feature/fallback_payments_test"}, "changed_resource": {"name": "fallback_payments_test", "type": "feature_flag"}, "impacted_resources": [{"name": "payments_api", "type": "service"}], "new_value": {"enabled": true, "percentage": "50%", "rule": {"datacenter": "devcycle.us1.prod"}}, "prev_value": {"enabled": true, "percentage": "10%", "rule": {"datacenter": "devcycle.us1.prod"}}}, "category": "change", "message": "payment_processed feature flag has been enabled", "tags": ["environment:test"], "title": "payment_processed feature flag updated"}, "type": "event"}} + When the request is sent + Then the response status is 400 Bad request + + @generated @skip @team:DataDog/event-management + Scenario: Post an event returns "OK" response + Given new "CreateEvent" request + And body with value {"data": {"attributes": {"attributes": {"author": {"name": "datadog@datadog.com", "type": "user"}, "change_metadata": {"dd": {"team": "datadog_team", "user_email": "datadog@datadog.com", "user_id": "datadog_user_id", "user_name": "datadog_username"}, "resource_link": "datadog.com/feature/fallback_payments_test"}, "changed_resource": {"name": "fallback_payments_test", "type": "feature_flag"}, "impacted_resources": [{"name": "payments_api", "type": "service"}], "new_value": {"enabled": true, "percentage": "50%", "rule": {"datacenter": "devcycle.us1.prod"}}, "prev_value": {"enabled": true, "percentage": "10%", "rule": {"datacenter": "devcycle.us1.prod"}}}, "category": "change", "message": "payment_processed feature flag has been enabled", "tags": ["environment:test"], "title": "payment_processed feature flag updated"}, "type": "event"}} + When the request is sent + Then the response status is 200 OK + @team:DataDog/event-management Scenario: Search events returns "Bad Request" response - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"from": "now-15m", "query": "service:web* AND @http.status_code:[200 TO 299]", "to": "now"}, "options": {"timezone": "GMT"}, "page": {"cursor": "eyJzdGFydEF0IjoiQVFBQUFYS2tMS3pPbm40NGV3QUFBQUJCV0V0clRFdDZVbG8zY3pCRmNsbHJiVmxDWlEifQ==", "limit": 25}, "sort": "timestamp"} When the request is sent Then the response status is 400 Bad Request @team:DataDog/event-management Scenario: Search events returns "OK" response - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"query": "datadog-agent", "from": "2020-09-17T11:48:36+01:00", "to": "2020-09-17T12:48:36+01:00"}, "sort": "timestamp", "page": {"limit": 5}} When the request is sent Then the response status is 200 OK @@ -60,7 +79,8 @@ Feature: Events @replay-only @skip-validation @team:DataDog/event-management @with-pagination Scenario: Search events returns "OK" response with pagination - Given new "SearchEvents" request + Given a valid "appKeyAuth" key in the system + And new "SearchEvents" request And body with value {"filter": {"from": "now-15m", "to": "now"}, "options": {"timezone": "GMT"}, "page": {"limit": 2}, "sort": "timestamp"} When the request with pagination is sent Then the response status is 200 OK diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index dcb4deb9a..91f554953 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -608,6 +608,12 @@ "type": "safe" } }, + "CreateEvent": { + "tag": "Events", + "undo": { + "type": "unsafe" + } + }, "SearchEvents": { "tag": "Events", "undo": { diff --git a/tests/scenarios/fixtures.rs b/tests/scenarios/fixtures.rs index 99fbad878..723c63e11 100644 --- a/tests/scenarios/fixtures.rs +++ b/tests/scenarios/fixtures.rs @@ -863,6 +863,10 @@ fn build_undo( world.api_name.clone().unwrap() }; + if undo.get("operationId").is_none() { + return Ok(None); + } + let mut undo_operation = UndoOperation { operation_id: undo .get("operationId") diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index edc7df4bf..726a7fd33 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -2007,6 +2007,9 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.ListEventsWithPagination".into(), test_v2_list_events_with_pagination, ); + world + .function_mappings + .insert("v2.CreateEvent".into(), test_v2_create_event); world .function_mappings .insert("v2.SearchEvents".into(), test_v2_search_events); @@ -14263,6 +14266,31 @@ fn test_v2_list_events_with_pagination( world.response.code = 200; } +fn test_v2_create_event(world: &mut DatadogWorld, _parameters: &HashMap) { + let api = world + .api_instances + .v2_api_events + .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_event_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_search_events(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances