Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ zip = { version = "8", default-features = false, features = ["deflate"], optiona

# Datadog API client — pinned to a git rev
# 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 = "008f178b20563bd3b708756cf50cc9e18084709e", optional = true, default-features = false }
datadog-api-client = { git = "https://github.com/DataDog/datadog-api-client-rust", rev = "0c6dbfbf73069fc670ca25083918606ecd6f58a2", optional = true, default-features = false }

# HTTP middleware (version-matched to DD client; compiles on all targets)
reqwest-middleware = "0.5"
Expand Down
85 changes: 84 additions & 1 deletion src/generated/downtime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Code generated by openapi-transformer. DO NOT EDIT.

use anyhow::Result;
use datadog_api_client::datadogV2::api_downtimes::{DowntimesAPI, GetDowntimeOptionalParams};
use datadog_api_client::datadogV2::api_downtimes::{
DowntimesAPI, GetDowntimeOptionalParams, ListDowntimesOptionalParams,
};
use datadog_api_client::datadogV2::model::DowntimeCreateRequest;

use crate::config::Config;
Expand Down Expand Up @@ -45,6 +47,24 @@ pub enum Command {
#[arg(long = "with-run-as")]
with_run_as: Option<bool>,
},
/// Get all downtimes
///
/// Get all scheduled downtimes.
List {
/// Only return downtimes that are active when the request is made.
#[arg(long = "current-only")]
current_only: Option<bool>,
/// 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")]
include: Option<String>,
/// Specific offset to use as the beginning of the returned page.
#[arg(long = "page-offset")]
page_offset: Option<i64>,
/// Maximum number of downtimes in the response.
#[arg(long = "page-limit")]
page_limit: Option<i64>,
},
}

pub async fn run(cfg: &Config, command: Command) -> Result<()> {
Expand All @@ -56,6 +76,12 @@ pub async fn run(cfg: &Config, command: Command) -> Result<()> {
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,
}
}

Expand Down Expand Up @@ -110,6 +136,52 @@ pub async fn get(
formatter::output(cfg, &resp)
}

/// Get all downtimes
///
/// Get all scheduled downtimes.
pub async fn list(
cfg: &Config,
current_only: Option<bool>,
include: Option<String>,
page_offset: Option<i64>,
page_limit: Option<i64>,
) -> 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<String> = None;
let meta = formatter::Metadata {
count: Some(count),
truncated,
command: Some("downtime list".to_string()),
next_action,
};
formatter::format_and_print(
&resp,
&cfg.output_format,
cfg.agent_mode,
Some(&meta),
cfg.jq.as_deref(),
)
}

#[cfg(test)]
mod tests {
use crate::test_support::*;
Expand All @@ -124,4 +196,15 @@ mod tests {
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();
}
}
1 change: 1 addition & 0 deletions src/generated/surface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ downtime
downtime.cancel
downtime.create
downtime.get
downtime.list
Loading