|
| 1 | +// Code generated by openapi-transformer. DO NOT EDIT. |
| 2 | + |
| 3 | +use anyhow::Result; |
| 4 | +use datadog_api_client::datadogV2::api_downtimes::{DowntimesAPI, GetDowntimeOptionalParams}; |
| 5 | + |
| 6 | +use crate::config::Config; |
| 7 | +use crate::formatter; |
| 8 | + |
| 9 | +#[derive(clap::Subcommand)] |
| 10 | +pub enum Command { |
| 11 | + /// Get a downtime |
| 12 | + /// |
| 13 | + /// Get downtime detail by `downtime_id`. |
| 14 | + Get { |
| 15 | + /// ID of the downtime to fetch. |
| 16 | + downtime_id: String, |
| 17 | + /// Comma-separated list of resource paths for related resources to include in the response. Supported resource |
| 18 | + /// paths are `created_by` and `monitor`. |
| 19 | + #[arg(long)] include: Option<String>, |
| 20 | + }, |
| 21 | +} |
| 22 | + |
| 23 | +pub async fn run(cfg: &Config, command: Command) -> Result<()> { |
| 24 | + match command { |
| 25 | + Command::Get { downtime_id, include } => get(cfg, downtime_id, include).await, |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +/// Get a downtime |
| 30 | +/// |
| 31 | +/// Get downtime detail by `downtime_id`. |
| 32 | +pub async fn get(cfg: &Config, downtime_id: String, include: Option<String>) -> Result<()> { |
| 33 | + let api = crate::make_api!(DowntimesAPI, cfg); |
| 34 | + let mut params = GetDowntimeOptionalParams::default(); |
| 35 | + if let Some(v) = include { |
| 36 | + params = params.include(v); |
| 37 | + } |
| 38 | + let resp = api |
| 39 | + .get_downtime(downtime_id, params) |
| 40 | + .await |
| 41 | + .map_err(|e| anyhow::anyhow!("failed to get_downtime: {:?}", e))?; |
| 42 | + formatter::output(cfg, &resp) |
| 43 | +} |
| 44 | + |
| 45 | +#[cfg(test)] |
| 46 | +mod tests { |
| 47 | + use crate::test_support::*; |
| 48 | + |
| 49 | + #[tokio::test] |
| 50 | + async fn test_get_ok() { |
| 51 | + let _lock = lock_env().await; |
| 52 | + let mut server = mockito::Server::new_async().await; |
| 53 | + let cfg = test_config(&server.url()); |
| 54 | + 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; |
| 55 | + let result = super::get(&cfg, "test".to_string(), None).await; |
| 56 | + assert!(result.is_ok(), "get failed: {:?}", result.err()); |
| 57 | + cleanup_env(); |
| 58 | + } |
| 59 | +} |
0 commit comments