From 9f3b48af41a194a48a5b6967abb477a750b6c4d5 Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Fri, 18 Sep 2026 14:11:05 +0000 Subject: [PATCH] Regenerate client from commit 57b70f0 of spec repo --- Cargo.lock | 4 +- Cargo.toml | 2 +- src/client.rs | 2 + src/config.rs | 2 + src/formatter.rs | 2 + src/generated/downtimes.rs | 300 +++++++++++++++++++++++++++++++++++++ src/generated/mod.rs | 25 +++- src/util.rs | 2 + 8 files changed, 329 insertions(+), 10 deletions(-) create mode 100644 src/generated/downtimes.rs diff --git a/Cargo.lock b/Cargo.lock index 6ae28fbb..44930b73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1068,8 +1068,8 @@ checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" [[package]] name = "datadog-api-client" -version = "0.35.0" -source = "git+https://github.com/DataDog/datadog-api-client-rust?rev=68fea1224e7ce303787b842811103b99c6406cf4#68fea1224e7ce303787b842811103b99c6406cf4" +version = "0.36.0" +source = "git+https://github.com/DataDog/datadog-api-client-rust?rev=e32b89365fc8df6d564da0549de82a79f2381a3b#e32b89365fc8df6d564da0549de82a79f2381a3b" dependencies = [ "async-stream", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 7ff62b40..968abd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,7 @@ zip = { version = "8", default-features = false, features = ["deflate"], optiona # Datadog API client — pinned to 0.33.0 tag # Use default-features = false; feature sets are activated per-target via features above -datadog-api-client = { git = "https://github.com/DataDog/datadog-api-client-rust", rev = "68fea1224e7ce303787b842811103b99c6406cf4", optional = true, default-features = false } +datadog-api-client = { git = "https://github.com/DataDog/datadog-api-client-rust", rev = "e32b89365fc8df6d564da0549de82a79f2381a3b", optional = true, default-features = false } # HTTP middleware (version-matched to DD client; compiles on all targets) reqwest-middleware = "0.5" diff --git a/src/client.rs b/src/client.rs index e7253d00..a2ada8e5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,3 +1,5 @@ +// Code generated by openapi-transformer. DO NOT EDIT. + use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; #[cfg(not(target_arch = "wasm32"))] diff --git a/src/config.rs b/src/config.rs index f0b55653..d6e9d06a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +// Code generated by openapi-transformer. DO NOT EDIT. + use anyhow::{bail, Result}; #[cfg(not(feature = "browser"))] use serde::Deserialize; diff --git a/src/formatter.rs b/src/formatter.rs index da48c545..fa1fa517 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -1,3 +1,5 @@ +// Code generated by openapi-transformer. DO NOT EDIT. + use anyhow::Result; use serde::Serialize; diff --git a/src/generated/downtimes.rs b/src/generated/downtimes.rs new file mode 100644 index 00000000..523378d3 --- /dev/null +++ b/src/generated/downtimes.rs @@ -0,0 +1,300 @@ +// Code generated by openapi-transformer. DO NOT EDIT. + +use anyhow::Result; +use datadog_api_client::datadogV2::api_downtimes::{ + DowntimesAPI, GetDowntimeOptionalParams, ListDowntimesOptionalParams, + ListMonitorDowntimesOptionalParams, +}; +use datadog_api_client::datadogV2::model::{DowntimeCreateRequest, DowntimeUpdateRequest}; + +use crate::config::Config; +use crate::formatter; +use crate::util; + +#[derive(clap::Subcommand)] +pub enum Command { + /// Cancel a downtime + /// + /// Cancel a downtime. + /// + /// **Note**: Downtimes canceled through the API are no longer active, but are retained for approximately two days before being permanently removed. The downtime may still appear in search results until it is permanently removed. + Cancel { + /// ID of the downtime to cancel. + downtime_id: String, + }, + /// Schedule a downtime + /// + /// Schedule a downtime. + Create { + #[arg(long)] + file: String, + }, + /// Get a downtime + /// + /// Get downtime detail by `downtime_id`. + Get { + /// ID of the downtime to fetch. + downtime_id: String, + /// Comma-separated list of resource paths for related resources to include in the response. Supported resource + /// paths are `created_by` and `monitor`. + #[arg(long)] + include: Option, + /// If `true`, include the `run_as` attribute in the response, which lists the principals allowed to + /// act on behalf of the downtime. + /// + /// **Note**: This feature is currently in Preview and may not be available for all organizations. + #[arg(long)] + with_run_as: Option, + }, + /// Get all downtimes + /// + /// List scheduled downtimes, optionally filtering to those that are active when the request is made. + List { + /// Only return downtimes that are active when the request is made. + #[arg(long)] + current_only: Option, + /// Comma-separated list of resource paths for related resources to include in the response. Supported resource + /// paths are `created_by` and `monitor`. + #[arg(long)] + include: Option, + /// Specific offset to use as the beginning of the returned page. + #[arg(long)] + page_offset: Option, + /// Maximum number of downtimes in the response. + #[arg(long)] + page_limit: Option, + }, + /// Get active downtimes for a monitor + /// + /// Get all active downtimes for the specified monitor. + ListMonitor { + /// The id of the monitor. + monitor_id: i64, + /// Specific offset to use as the beginning of the returned page. + #[arg(long)] + page_offset: Option, + /// Maximum number of downtimes in the response. + #[arg(long)] + page_limit: Option, + }, + /// Update a downtime + /// + /// Update a downtime by `downtime_id`. + Update { + /// ID of the downtime to update. + downtime_id: String, + #[arg(long)] + file: String, + }, +} + +pub async fn run(cfg: &Config, command: Command) -> Result<()> { + match command { + Command::Cancel { downtime_id } => cancel(cfg, downtime_id).await, + Command::Create { file } => create(cfg, &file).await, + Command::Get { + downtime_id, + include, + with_run_as, + } => get(cfg, downtime_id, include, with_run_as).await, + Command::List { + current_only, + include, + page_offset, + page_limit, + } => list(cfg, current_only, include, page_offset, page_limit).await, + Command::ListMonitor { + monitor_id, + page_offset, + page_limit, + } => list_monitor(cfg, monitor_id, page_offset, page_limit).await, + Command::Update { downtime_id, file } => update(cfg, downtime_id, &file).await, + } +} + +/// Cancel a downtime +/// +/// Cancel a downtime. +/// +/// **Note**: Downtimes canceled through the API are no longer active, but are retained for approximately two days before being permanently removed. The downtime may still appear in search results until it is permanently removed. +pub async fn cancel(cfg: &Config, downtime_id: String) -> Result<()> { + let api = crate::make_api!(DowntimesAPI, cfg); + api.cancel_downtime(downtime_id) + .await + .map_err(|e| anyhow::anyhow!("failed to cancel_downtime: {:?}", e))?; + println!("downtimes cancel: ok"); + Ok(()) +} + +/// Schedule a downtime +/// +/// Schedule a downtime. +pub async fn create(cfg: &Config, file: &str) -> Result<()> { + let body: DowntimeCreateRequest = util::read_json_file(file)?; + let api = crate::make_api!(DowntimesAPI, cfg); + let resp = api + .create_downtime(body) + .await + .map_err(|e| anyhow::anyhow!("failed to create_downtime: {:?}", e))?; + formatter::output(cfg, &resp) +} + +/// Get a downtime +/// +/// Get downtime detail by `downtime_id`. +pub async fn get( + cfg: &Config, + downtime_id: String, + include: Option, + with_run_as: Option, +) -> Result<()> { + let api = crate::make_api!(DowntimesAPI, cfg); + let mut params = GetDowntimeOptionalParams::default(); + if let Some(v) = include { + params = params.include(v); + } + if let Some(v) = with_run_as { + params = params.with_run_as(v); + } + let resp = api + .get_downtime(downtime_id, params) + .await + .map_err(|e| anyhow::anyhow!("failed to get_downtime: {:?}", e))?; + formatter::output(cfg, &resp) +} + +/// Get all downtimes +/// +/// List scheduled downtimes, optionally filtering to those that are active when the request is made. +pub async fn list( + cfg: &Config, + current_only: Option, + include: Option, + page_offset: Option, + page_limit: Option, +) -> Result<()> { + let api = crate::make_api!(DowntimesAPI, cfg); + let mut params = ListDowntimesOptionalParams::default(); + if let Some(v) = current_only { + params = params.current_only(v); + } + if let Some(v) = include { + params = params.include(v); + } + if let Some(v) = page_offset { + params = params.page_offset(v); + } + if let Some(v) = page_limit { + params = params.page_limit(v); + } + let resp = api + .list_downtimes(params) + .await + .map_err(|e| anyhow::anyhow!("failed to list_downtimes: {:?}", e))?; + let count = resp.data.as_ref().map_or(0, |d| d.len()); + let truncated = false; + let next_action: Option = None; + let meta = formatter::Metadata { + count: Some(count), + truncated, + command: Some("downtimes list".to_string()), + next_action, + }; + formatter::format_and_print( + &resp, + &cfg.output_format, + cfg.agent_mode, + Some(&meta), + cfg.jq.as_deref(), + ) +} + +/// Get active downtimes for a monitor +/// +/// Get all active downtimes for the specified monitor. +pub async fn list_monitor( + cfg: &Config, + monitor_id: i64, + page_offset: Option, + page_limit: Option, +) -> Result<()> { + let api = crate::make_api!(DowntimesAPI, cfg); + let mut params = ListMonitorDowntimesOptionalParams::default(); + if let Some(v) = page_offset { + params = params.page_offset(v); + } + if let Some(v) = page_limit { + params = params.page_limit(v); + } + let resp = api + .list_monitor_downtimes(monitor_id, params) + .await + .map_err(|e| anyhow::anyhow!("failed to list_monitor_downtimes: {:?}", e))?; + let count = resp.data.as_ref().map_or(0, |d| d.len()); + let truncated = false; + let next_action: Option = None; + let meta = formatter::Metadata { + count: Some(count), + truncated, + command: Some("downtimes list_monitor".to_string()), + next_action, + }; + formatter::format_and_print( + &resp, + &cfg.output_format, + cfg.agent_mode, + Some(&meta), + cfg.jq.as_deref(), + ) +} + +/// Update a downtime +/// +/// Update a downtime by `downtime_id`. +pub async fn update(cfg: &Config, downtime_id: String, file: &str) -> Result<()> { + let body: DowntimeUpdateRequest = util::read_json_file(file)?; + let api = crate::make_api!(DowntimesAPI, cfg); + let resp = api + .update_downtime(downtime_id, body) + .await + .map_err(|e| anyhow::anyhow!("failed to update_downtime: {:?}", e))?; + formatter::output(cfg, &resp) +} + +#[cfg(test)] +mod tests { + use crate::test_support::*; + + #[tokio::test] + async fn test_get_ok() { + let _lock = lock_env().await; + let mut server = mockito::Server::new_async().await; + let cfg = test_config(&server.url()); + let _mock = mock_any(&mut server, "GET", r##"{"data": {"attributes": {"created": "2024-01-01T00:00:00+00:00", "display_timezone": "America/New_York", "message": "Message about the downtime", "modified": "2024-01-01T00:00:00+00:00", "monitor_identifier": {"monitor_tags": ["*"]}, "mute_first_recovery_notification": false, "notify_end_states": ["alert", "warn"], "notify_end_types": ["canceled", "expired"], "scope": "env:(staging OR prod) AND datacenter:us-east-1", "status": "active"}, "id": "00000000-0000-1234-0000-000000000000", "type": "downtime"}}"##).await; + let result = super::get(&cfg, "test".to_string(), None, None).await; + assert!(result.is_ok(), "get failed: {:?}", result.err()); + cleanup_env(); + } + + #[tokio::test] + async fn test_list_ok() { + let _lock = lock_env().await; + let mut server = mockito::Server::new_async().await; + let cfg = test_config(&server.url()); + let _mock = mock_any(&mut server, "GET", r##"{"data": [{"attributes": {"created": "2024-01-01T00:00:00+00:00", "display_timezone": "America/New_York", "message": "Message about the downtime", "modified": "2024-01-01T00:00:00+00:00", "monitor_identifier": {"monitor_tags": ["*"]}, "mute_first_recovery_notification": false, "notify_end_states": ["alert", "warn"], "notify_end_types": ["canceled", "expired"], "scope": "env:(staging OR prod) AND datacenter:us-east-1", "status": "active"}, "id": "00000000-0000-1234-0000-000000000000", "type": "downtime"}], "meta": {"page": {"total_filtered_count": 1}}}"##).await; + let result = super::list(&cfg, None, None, None, None).await; + assert!(result.is_ok(), "list failed: {:?}", result.err()); + cleanup_env(); + } + + #[tokio::test] + async fn test_list_monitor_ok() { + let _lock = lock_env().await; + let mut server = mockito::Server::new_async().await; + let cfg = test_config(&server.url()); + let _mock = mock_any(&mut server, "GET", r##"{"data": [{"attributes": {"end": "2024-01-01T01:00:00+00:00", "groups": ["service:postgres"], "scope": "env:(staging OR prod) AND datacenter:us-east-1", "start": "2024-01-01T00:00:00+00:00"}, "id": "00000000-0000-1234-0000-000000000000", "type": "downtime_match"}], "meta": {"page": {"total_filtered_count": 1}}}"##).await; + let result = super::list_monitor(&cfg, 1, None, None).await; + assert!(result.is_ok(), "list_monitor failed: {:?}", result.err()); + cleanup_env(); + } +} diff --git a/src/generated/mod.rs b/src/generated/mod.rs index a9c96d15..0c9e5d96 100644 --- a/src/generated/mod.rs +++ b/src/generated/mod.rs @@ -1,15 +1,26 @@ -// Stable integration point for openapi-transformer-generated pup commands. -// -// Future regenerations add variants to `GeneratedCommand` and modules within -// this directory in place; main.rs never needs to change again. +// Code generated by openapi-transformer. DO NOT EDIT. + +pub mod downtimes; use anyhow::Result; use crate::config::Config; +/// All spec-generated pup commands. +/// +/// Re-run the generator to add or remove tags; pup never needs manual changes +/// for new commands. #[derive(clap::Subcommand)] -pub enum GeneratedCommand {} +pub enum GeneratedCommand { + /// Manage downtimes resources + Downtimes { + #[command(subcommand)] + action: downtimes::Command, + }, +} -pub async fn run(_cfg: &Config, command: GeneratedCommand) -> Result<()> { - match command {} +pub async fn run(cfg: &Config, command: GeneratedCommand) -> Result<()> { + match command { + GeneratedCommand::Downtimes { action } => downtimes::run(cfg, action).await, + } } diff --git a/src/util.rs b/src/util.rs index 785be68c..29f9c954 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,3 +1,5 @@ +// Code generated by openapi-transformer. DO NOT EDIT. + use anyhow::Result; /// Read a JSON file and deserialize into the specified type.