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
505 changes: 480 additions & 25 deletions .generator/schemas/v2/openapi.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions examples/v2_report-schedules_ListDatasetReportSchedules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// List dataset report schedules returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_report_schedules::ReportSchedulesAPI;

#[tokio::main]
async fn main() {
let configuration = datadog::Configuration::new();
let api = ReportSchedulesAPI::with_config(configuration);
let resp = api
.list_dataset_report_schedules("dataset_id".to_string())
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
36 changes: 36 additions & 0 deletions examples/v2_report-schedules_PrintReport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Print a report returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_report_schedules::ReportSchedulesAPI;
use datadog_api_client::datadogV2::model::PrintReportRequest;
use datadog_api_client::datadogV2::model::PrintReportRequestAttributes;
use datadog_api_client::datadogV2::model::PrintReportRequestData;
use datadog_api_client::datadogV2::model::PrintReportType;
use datadog_api_client::datadogV2::model::ReportScheduleResourceType;
use datadog_api_client::datadogV2::model::ReportScheduleTemplateVariable;

#[tokio::main]
async fn main() {
let body = PrintReportRequest::new(PrintReportRequestData::new(
PrintReportRequestAttributes::new(
"abc-def-ghi".to_string(),
ReportScheduleResourceType::DASHBOARD,
vec![ReportScheduleTemplateVariable::new(
"env".to_string(),
vec!["prod".to_string()],
)],
"America/New_York".to_string(),
)
.from_ts(1780318800000)
.timeframe("1w".to_string())
.to_ts(1780923600000),
PrintReportType::REPORT,
));
let configuration = datadog::Configuration::new();
let api = ReportSchedulesAPI::with_config(configuration);
let resp = api.print_report(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
290 changes: 290 additions & 0 deletions src/datadogV2/api/api_report_schedules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ pub enum GetReportSchedulesForResourceError {
UnknownValue(serde_json::Value),
}

/// ListDatasetReportSchedulesError is a struct for typed errors of method [`ReportSchedulesAPI::list_dataset_report_schedules`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListDatasetReportSchedulesError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// ListReportSchedulesError is a struct for typed errors of method [`ReportSchedulesAPI::list_report_schedules`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand All @@ -109,6 +118,15 @@ pub enum PatchReportScheduleError {
UnknownValue(serde_json::Value),
}

/// PrintReportError is a struct for typed errors of method [`ReportSchedulesAPI::print_report`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PrintReportError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}

/// ToggleReportScheduleError is a struct for typed errors of method [`ReportSchedulesAPI::toggle_report_schedule`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -705,6 +723,122 @@ impl ReportSchedulesAPI {
}
}

/// Retrieve all report schedules for a given published dataset.
/// Returns report schedules belonging to the authenticated user's organization that target the specified dataset.
/// Requires the `generate_log_reports` or `manage_log_reports` permission.
pub async fn list_dataset_report_schedules(
&self,
dataset_id: String,
) -> Result<
crate::datadogV2::model::DatasetReportScheduleListResponse,
datadog::Error<ListDatasetReportSchedulesError>,
> {
match self
.list_dataset_report_schedules_with_http_info(dataset_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),
}
}

/// Retrieve all report schedules for a given published dataset.
/// Returns report schedules belonging to the authenticated user's organization that target the specified dataset.
/// Requires the `generate_log_reports` or `manage_log_reports` permission.
pub async fn list_dataset_report_schedules_with_http_info(
&self,
dataset_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::DatasetReportScheduleListResponse>,
datadog::Error<ListDatasetReportSchedulesError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_dataset_report_schedules";

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/reporting/dataset/{dataset_id}/schedules",
local_configuration.get_operation_host(operation_id),
dataset_id = datadog::urlencode(dataset_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::<crate::datadogV2::model::DatasetReportScheduleListResponse>(
&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<ListDatasetReportSchedulesError> =
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 dashboard and integration dashboard report schedules for the organization.
/// The response is paginated and can be filtered by title, author UUID, or recipients.
/// Requires the `generate_dashboard_reports` permission.
Expand Down Expand Up @@ -1020,6 +1154,162 @@ impl ReportSchedulesAPI {
}
}

/// Initiate a one-off, print-only report for a dashboard or integration dashboard.
/// The report is rendered as a PDF and made available for download through the URL returned in the response.
/// Requires a reporting permission appropriate to the targeted resource type.
pub async fn print_report(
&self,
body: crate::datadogV2::model::PrintReportRequest,
) -> Result<crate::datadogV2::model::PrintReportResponse, datadog::Error<PrintReportError>>
{
match self.print_report_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),
}
}

/// Initiate a one-off, print-only report for a dashboard or integration dashboard.
/// The report is rendered as a PDF and made available for download through the URL returned in the response.
/// Requires a reporting permission appropriate to the targeted resource type.
pub async fn print_report_with_http_info(
&self,
body: crate::datadogV2::model::PrintReportRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::PrintReportResponse>,
datadog::Error<PrintReportError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.print_report";

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/reporting/print",
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"),
);
};
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"),
);
};

// 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)),
}
}
#[cfg(feature = "zstd")]
"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::<crate::datadogV2::model::PrintReportResponse>(
&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<PrintReportError> = 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))
}
}

/// Activate or pause a report schedule by setting its status to `active` or `inactive`.
/// Requires a reporting write permission appropriate to the targeted resource type and schedule ownership.
pub async fn toggle_report_schedule(
Expand Down
Loading
Loading