diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 7760d58c0..52a93c634 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -17075,6 +17075,12 @@ components: required: - id type: object + DeploymentGateRulesResponse: + description: Response for a deployment gate rules. + properties: + data: + $ref: '#/components/schemas/ListDeploymentRuleResponseData' + type: object DeploymentMetadata: description: Metadata object containing the publication creation information. properties: @@ -30199,6 +30205,37 @@ components: type: string x-enum-varnames: - LIST_CONNECTIONS_RESPONSE + ListDeploymentRuleResponseData: + description: Data for a list of deployment rules. + properties: + attributes: + $ref: '#/components/schemas/ListDeploymentRulesResponseDataAttributes' + id: + description: Unique identifier of the deployment rule. + example: 1111-2222-3333-4444-555566667777 + type: string + type: + $ref: '#/components/schemas/ListDeploymentRulesDataType' + required: + - type + - attributes + - id + type: object + ListDeploymentRulesDataType: + description: List deployment rule resource type. + enum: + - list_deployment_rules + example: list_deployment_rules + type: string + x-enum-varnames: + - LIST_DEPLOYMENT_RULES + ListDeploymentRulesResponseDataAttributes: + properties: + rules: + items: + $ref: '#/components/schemas/DeploymentRuleResponseDataAttributes' + type: array + type: object ListDevicesResponse: description: List devices response. properties: @@ -66236,6 +66273,50 @@ paths: If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' /api/v2/deployment_gates/{gate_id}/rules: + get: + description: Endpoint to get rules for a deployment gate. + operationId: GetDeploymentGateRules + parameters: + - description: The ID of the deployment gate. + in: path + name: gate_id + required: true + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/DeploymentGateRulesResponse' + description: OK + '400': + $ref: '#/components/responses/HTTPCDGatesBadRequestResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '429': + $ref: '#/components/responses/TooManyRequestsResponse' + '500': + content: + application/json: + schema: + $ref: '#/components/schemas/HTTPCIAppErrors' + description: Internal Server Error + security: + - apiKeyAuth: [] + appKeyAuth: [] + summary: Get rules for a deployment gate + tags: + - Deployment Gates + x-permission: + operator: OR + permissions: + - deployment_gates_read + x-unstable: '**Note**: This endpoint is in preview and may be subject to change. + + If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' post: description: Endpoint to create a deployment rule. A gate for the rule must already exist. diff --git a/examples/v2_deployment-gates_GetDeploymentGateRules.rs b/examples/v2_deployment-gates_GetDeploymentGateRules.rs new file mode 100644 index 000000000..71e4a8b40 --- /dev/null +++ b/examples/v2_deployment-gates_GetDeploymentGateRules.rs @@ -0,0 +1,20 @@ +// Get rules for a deployment gate returns "OK" response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_deployment_gates::DeploymentGatesAPI; + +#[tokio::main] +async fn main() { + // there is a valid "deployment_gate" in the system + let deployment_gate_data_id = std::env::var("DEPLOYMENT_GATE_DATA_ID").unwrap(); + let mut configuration = datadog::Configuration::new(); + configuration.set_unstable_operation_enabled("v2.GetDeploymentGateRules", true); + let api = DeploymentGatesAPI::with_config(configuration); + let resp = api + .get_deployment_gate_rules(deployment_gate_data_id.clone()) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index 3c3f8b5d9..d5bb85b60 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -183,6 +183,7 @@ impl Default for Configuration { ("v2.delete_deployment_gate".to_owned(), false), ("v2.delete_deployment_rule".to_owned(), false), ("v2.get_deployment_gate".to_owned(), false), + ("v2.get_deployment_gate_rules".to_owned(), false), ("v2.get_deployment_rule".to_owned(), false), ("v2.update_deployment_gate".to_owned(), false), ("v2.update_deployment_rule".to_owned(), false), diff --git a/src/datadogV2/api/api_deployment_gates.rs b/src/datadogV2/api/api_deployment_gates.rs index bb6810ef0..8504f15f3 100644 --- a/src/datadogV2/api/api_deployment_gates.rs +++ b/src/datadogV2/api/api_deployment_gates.rs @@ -64,6 +64,16 @@ pub enum GetDeploymentGateError { UnknownValue(serde_json::Value), } +/// GetDeploymentGateRulesError is a struct for typed errors of method [`DeploymentGatesAPI::get_deployment_gate_rules`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum GetDeploymentGateRulesError { + HTTPCDGatesBadRequestResponse(crate::datadogV2::model::HTTPCDGatesBadRequestResponse), + APIErrorResponse(crate::datadogV2::model::APIErrorResponse), + HTTPCIAppErrors(crate::datadogV2::model::HTTPCIAppErrors), + UnknownValue(serde_json::Value), +} + /// GetDeploymentRuleError is a struct for typed errors of method [`DeploymentGatesAPI::get_deployment_rule`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -807,6 +817,123 @@ impl DeploymentGatesAPI { } } + /// Endpoint to get rules for a deployment gate. + pub async fn get_deployment_gate_rules( + &self, + gate_id: String, + ) -> Result< + crate::datadogV2::model::DeploymentGateRulesResponse, + datadog::Error, + > { + match self.get_deployment_gate_rules_with_http_info(gate_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), + } + } + + /// Endpoint to get rules for a deployment gate. + pub async fn get_deployment_gate_rules_with_http_info( + &self, + gate_id: String, + ) -> Result< + datadog::ResponseContent, + datadog::Error, + > { + let local_configuration = &self.config; + let operation_id = "v2.get_deployment_gate_rules"; + if local_configuration.is_unstable_operation_enabled(operation_id) { + warn!("Using unstable operation {operation_id}"); + } else { + let local_error = datadog::UnstableOperationDisabledError { + msg: "Operation 'v2.get_deployment_gate_rules' is not enabled".to_string(), + }; + return Err(datadog::Error::UnstableOperationDisabledError(local_error)); + } + + let local_client = &self.client; + + let local_uri_str = format!( + "{}/api/v2/deployment_gates/{gate_id}/rules", + local_configuration.get_operation_host(operation_id), + gate_id = datadog::urlencode(gate_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)) + } + } + /// Endpoint to get a deployment rule. pub async fn get_deployment_rule( &self, diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 9b70a01ff..74756e911 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -2210,32 +2210,40 @@ pub mod model_deployment_gate_response_data_attributes_updated_by; pub use self::model_deployment_gate_response_data_attributes_updated_by::DeploymentGateResponseDataAttributesUpdatedBy; pub mod model_httpcd_gates_bad_request_response; pub use self::model_httpcd_gates_bad_request_response::HTTPCDGatesBadRequestResponse; -pub mod model_create_deployment_rule_params; -pub use self::model_create_deployment_rule_params::CreateDeploymentRuleParams; -pub mod model_create_deployment_rule_params_data; -pub use self::model_create_deployment_rule_params_data::CreateDeploymentRuleParamsData; -pub mod model_create_deployment_rule_params_data_attributes; -pub use self::model_create_deployment_rule_params_data_attributes::CreateDeploymentRuleParamsDataAttributes; +pub mod model_deployment_gate_rules_response; +pub use self::model_deployment_gate_rules_response::DeploymentGateRulesResponse; +pub mod model_list_deployment_rule_response_data; +pub use self::model_list_deployment_rule_response_data::ListDeploymentRuleResponseData; +pub mod model_list_deployment_rules_response_data_attributes; +pub use self::model_list_deployment_rules_response_data_attributes::ListDeploymentRulesResponseDataAttributes; +pub mod model_deployment_rule_response_data_attributes; +pub use self::model_deployment_rule_response_data_attributes::DeploymentRuleResponseDataAttributes; +pub mod model_deployment_rule_response_data_attributes_created_by; +pub use self::model_deployment_rule_response_data_attributes_created_by::DeploymentRuleResponseDataAttributesCreatedBy; pub mod model_deployment_rule_options_faulty_deployment_detection; pub use self::model_deployment_rule_options_faulty_deployment_detection::DeploymentRuleOptionsFaultyDeploymentDetection; pub mod model_deployment_rule_options_monitor; pub use self::model_deployment_rule_options_monitor::DeploymentRuleOptionsMonitor; pub mod model_deployment_rules_options; pub use self::model_deployment_rules_options::DeploymentRulesOptions; +pub mod model_deployment_rule_response_data_attributes_type; +pub use self::model_deployment_rule_response_data_attributes_type::DeploymentRuleResponseDataAttributesType; +pub mod model_deployment_rule_response_data_attributes_updated_by; +pub use self::model_deployment_rule_response_data_attributes_updated_by::DeploymentRuleResponseDataAttributesUpdatedBy; +pub mod model_list_deployment_rules_data_type; +pub use self::model_list_deployment_rules_data_type::ListDeploymentRulesDataType; +pub mod model_create_deployment_rule_params; +pub use self::model_create_deployment_rule_params::CreateDeploymentRuleParams; +pub mod model_create_deployment_rule_params_data; +pub use self::model_create_deployment_rule_params_data::CreateDeploymentRuleParamsData; +pub mod model_create_deployment_rule_params_data_attributes; +pub use self::model_create_deployment_rule_params_data_attributes::CreateDeploymentRuleParamsDataAttributes; pub mod model_deployment_rule_data_type; pub use self::model_deployment_rule_data_type::DeploymentRuleDataType; pub mod model_deployment_rule_response; pub use self::model_deployment_rule_response::DeploymentRuleResponse; pub mod model_deployment_rule_response_data; pub use self::model_deployment_rule_response_data::DeploymentRuleResponseData; -pub mod model_deployment_rule_response_data_attributes; -pub use self::model_deployment_rule_response_data_attributes::DeploymentRuleResponseDataAttributes; -pub mod model_deployment_rule_response_data_attributes_created_by; -pub use self::model_deployment_rule_response_data_attributes_created_by::DeploymentRuleResponseDataAttributesCreatedBy; -pub mod model_deployment_rule_response_data_attributes_type; -pub use self::model_deployment_rule_response_data_attributes_type::DeploymentRuleResponseDataAttributesType; -pub mod model_deployment_rule_response_data_attributes_updated_by; -pub use self::model_deployment_rule_response_data_attributes_updated_by::DeploymentRuleResponseDataAttributesUpdatedBy; pub mod model_httpcd_gates_not_found_response; pub use self::model_httpcd_gates_not_found_response::HTTPCDGatesNotFoundResponse; pub mod model_httpcd_rules_not_found_response; diff --git a/src/datadogV2/model/model_deployment_gate_rules_response.rs b/src/datadogV2/model/model_deployment_gate_rules_response.rs new file mode 100644 index 000000000..6ecaff2e5 --- /dev/null +++ b/src/datadogV2/model/model_deployment_gate_rules_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 for a deployment gate rules. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct DeploymentGateRulesResponse { + /// Data for a list of deployment rules. + #[serde(rename = "data")] + pub data: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl DeploymentGateRulesResponse { + pub fn new() -> DeploymentGateRulesResponse { + DeploymentGateRulesResponse { + data: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn data(mut self, value: crate::datadogV2::model::ListDeploymentRuleResponseData) -> 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 DeploymentGateRulesResponse { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for DeploymentGateRulesResponse { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct DeploymentGateRulesResponseVisitor; + impl<'a> Visitor<'a> for DeploymentGateRulesResponseVisitor { + type Value = DeploymentGateRulesResponse; + + 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 = DeploymentGateRulesResponse { + data, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(DeploymentGateRulesResponseVisitor) + } +} diff --git a/src/datadogV2/model/model_list_deployment_rule_response_data.rs b/src/datadogV2/model/model_list_deployment_rule_response_data.rs new file mode 100644 index 000000000..277cd15bb --- /dev/null +++ b/src/datadogV2/model/model_list_deployment_rule_response_data.rs @@ -0,0 +1,125 @@ +// 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}; + +/// Data for a list of deployment rules. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListDeploymentRuleResponseData { + #[serde(rename = "attributes")] + pub attributes: crate::datadogV2::model::ListDeploymentRulesResponseDataAttributes, + /// Unique identifier of the deployment rule. + #[serde(rename = "id")] + pub id: String, + /// List deployment rule resource type. + #[serde(rename = "type")] + pub type_: crate::datadogV2::model::ListDeploymentRulesDataType, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListDeploymentRuleResponseData { + pub fn new( + attributes: crate::datadogV2::model::ListDeploymentRulesResponseDataAttributes, + id: String, + type_: crate::datadogV2::model::ListDeploymentRulesDataType, + ) -> ListDeploymentRuleResponseData { + ListDeploymentRuleResponseData { + attributes, + id, + 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 ListDeploymentRuleResponseData { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListDeploymentRuleResponseDataVisitor; + impl<'a> Visitor<'a> for ListDeploymentRuleResponseDataVisitor { + type Value = ListDeploymentRuleResponseData; + + 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::ListDeploymentRulesResponseDataAttributes, + > = 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" => { + 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::ListDeploymentRulesDataType::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 id = id.ok_or_else(|| M::Error::missing_field("id"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + + let content = ListDeploymentRuleResponseData { + attributes, + id, + type_, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListDeploymentRuleResponseDataVisitor) + } +} diff --git a/src/datadogV2/model/model_list_deployment_rules_data_type.rs b/src/datadogV2/model/model_list_deployment_rules_data_type.rs new file mode 100644 index 000000000..a0b25a177 --- /dev/null +++ b/src/datadogV2/model/model_list_deployment_rules_data_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 ListDeploymentRulesDataType { + LIST_DEPLOYMENT_RULES, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for ListDeploymentRulesDataType { + fn to_string(&self) -> String { + match self { + Self::LIST_DEPLOYMENT_RULES => String::from("list_deployment_rules"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for ListDeploymentRulesDataType { + 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 ListDeploymentRulesDataType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "list_deployment_rules" => Self::LIST_DEPLOYMENT_RULES, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV2/model/model_list_deployment_rules_response_data_attributes.rs b/src/datadogV2/model/model_list_deployment_rules_response_data_attributes.rs new file mode 100644 index 000000000..884eb50bf --- /dev/null +++ b/src/datadogV2/model/model_list_deployment_rules_response_data_attributes.rs @@ -0,0 +1,108 @@ +// 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}; + +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct ListDeploymentRulesResponseDataAttributes { + #[serde(rename = "rules")] + pub rules: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl ListDeploymentRulesResponseDataAttributes { + pub fn new() -> ListDeploymentRulesResponseDataAttributes { + ListDeploymentRulesResponseDataAttributes { + rules: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn rules( + mut self, + value: Vec, + ) -> Self { + self.rules = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl Default for ListDeploymentRulesResponseDataAttributes { + fn default() -> Self { + Self::new() + } +} + +impl<'de> Deserialize<'de> for ListDeploymentRulesResponseDataAttributes { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct ListDeploymentRulesResponseDataAttributesVisitor; + impl<'a> Visitor<'a> for ListDeploymentRulesResponseDataAttributesVisitor { + type Value = ListDeploymentRulesResponseDataAttributes; + + 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 rules: Option< + Vec, + > = 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() { + "rules" => { + if v.is_null() { + continue; + } + rules = 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 = ListDeploymentRulesResponseDataAttributes { + rules, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(ListDeploymentRulesResponseDataAttributesVisitor) + } +} diff --git a/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.frozen new file mode 100644 index 000000000..5305f1cfe --- /dev/null +++ b/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-12-10T19:27:22.958Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.json b/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.json new file mode 100644 index 000000000..920b04523 --- /dev/null +++ b/tests/scenarios/cassettes/v2/deployment_gates/Get-rules-for-a-deployment-gate-returns-OK-response.json @@ -0,0 +1,91 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"dry_run\":false,\"env\":\"production\",\"identifier\":\"my-gate-testgetrulesforadeploymentgatereturnsokresponse1765394842\",\"service\":\"my-service\"},\"type\":\"deployment_gate\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/deployment_gates" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"718d7fb4-bbc4-4b69-8a1b-98dda014726d\",\"type\":\"deployment_gate\",\"attributes\":{\"created_at\":\"2025-12-10T19:27:24.004043Z\",\"created_by\":{\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"},\"dry_run\":false,\"env\":\"production\",\"identifier\":\"my-gate-testgetrulesforadeploymentgatereturnsokresponse1765394842\",\"service\":\"my-service\",\"updated_at\":\"2025-12-10T19:27:24.004043Z\",\"updated_by\":{\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 10 Dec 2025 19:27:22 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "get", + "uri": "https://api.datadoghq.com/api/v2/deployment_gates/718d7fb4-bbc4-4b69-8a1b-98dda014726d/rules" + }, + "response": { + "body": { + "string": "{\"data\":{\"id\":\"718d7fb4-bbc4-4b69-8a1b-98dda014726d\",\"type\":\"list_deployment_rules\",\"attributes\":{\"rules\":[]}}}", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/vnd.api+json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 10 Dec 2025 19:27:22 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/deployment_gates/718d7fb4-bbc4-4b69-8a1b-98dda014726d" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": {}, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Wed, 10 Dec 2025 19:27:22 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v2/deployment_gates.feature b/tests/scenarios/features/v2/deployment_gates.feature index e4023c565..cb0c5a126 100644 --- a/tests/scenarios/features/v2/deployment_gates.feature +++ b/tests/scenarios/features/v2/deployment_gates.feature @@ -207,6 +207,23 @@ Feature: Deployment Gates When the request is sent Then the response status is 200 OK + @generated @skip @team:DataDog/ci-app-backend + Scenario: Get rules for a deployment gate returns "Bad request." response + Given operation "GetDeploymentGateRules" enabled + And new "GetDeploymentGateRules" request + And request contains "gate_id" parameter from "REPLACE.ME" + When the request is sent + Then the response status is 400 Bad request. + + @team:DataDog/ci-app-backend + Scenario: Get rules for a deployment gate returns "OK" response + Given there is a valid "deployment_gate" in the system + And operation "GetDeploymentGateRules" enabled + And new "GetDeploymentGateRules" request + And request contains "gate_id" parameter from "deployment_gate.data.id" + When the request is sent + Then the response status is 200 OK + @team:DataDog/ci-app-backend Scenario: Update deployment gate returns "Bad Request" response Given operation "UpdateDeploymentGate" enabled diff --git a/tests/scenarios/features/v2/undo.json b/tests/scenarios/features/v2/undo.json index 71dba8f3e..396d52383 100644 --- a/tests/scenarios/features/v2/undo.json +++ b/tests/scenarios/features/v2/undo.json @@ -1335,6 +1335,12 @@ "type": "unsafe" } }, + "GetDeploymentGateRules": { + "tag": "Deployment Gates", + "undo": { + "type": "safe" + } + }, "CreateDeploymentRule": { "tag": "Deployment Gates", "undo": { diff --git a/tests/scenarios/function_mappings.rs b/tests/scenarios/function_mappings.rs index 72b47b7ff..c8ddcbe5b 100644 --- a/tests/scenarios/function_mappings.rs +++ b/tests/scenarios/function_mappings.rs @@ -2895,6 +2895,10 @@ pub fn collect_function_calls(world: &mut DatadogWorld) { "v2.CreateDeploymentGate".into(), test_v2_create_deployment_gate, ); + world.function_mappings.insert( + "v2.GetDeploymentGateRules".into(), + test_v2_get_deployment_gate_rules, + ); world.function_mappings.insert( "v2.CreateDeploymentRule".into(), test_v2_create_deployment_rule, @@ -21323,6 +21327,34 @@ fn test_v2_create_deployment_gate(world: &mut DatadogWorld, _parameters: &HashMa world.response.code = response.status.as_u16(); } +fn test_v2_get_deployment_gate_rules( + world: &mut DatadogWorld, + _parameters: &HashMap, +) { + let api = world + .api_instances + .v2_api_deployment_gates + .as_ref() + .expect("api instance not found"); + let gate_id = serde_json::from_value(_parameters.get("gate_id").unwrap().clone()).unwrap(); + let response = match block_on(api.get_deployment_gate_rules_with_http_info(gate_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_create_deployment_rule(world: &mut DatadogWorld, _parameters: &HashMap) { let api = world .api_instances