Skip to content

Commit 349556a

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add OpenAPI specs for ListDatasetReportSchedules and PrintReport (#1830)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 0815bf1 commit 349556a

19 files changed

Lines changed: 2421 additions & 22 deletions

.generator/schemas/v2/openapi.yaml

Lines changed: 444 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// List dataset report schedules returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_report_schedules::ReportSchedulesAPI;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
let configuration = datadog::Configuration::new();
8+
let api = ReportSchedulesAPI::with_config(configuration);
9+
let resp = api
10+
.list_dataset_report_schedules("dataset_id".to_string())
11+
.await;
12+
if let Ok(value) = resp {
13+
println!("{:#?}", value);
14+
} else {
15+
println!("{:#?}", resp.unwrap_err());
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Print a report returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_report_schedules::ReportSchedulesAPI;
4+
use datadog_api_client::datadogV2::model::PrintReportRequest;
5+
use datadog_api_client::datadogV2::model::PrintReportRequestAttributes;
6+
use datadog_api_client::datadogV2::model::PrintReportRequestData;
7+
use datadog_api_client::datadogV2::model::PrintReportType;
8+
use datadog_api_client::datadogV2::model::ReportScheduleResourceType;
9+
use datadog_api_client::datadogV2::model::ReportScheduleTemplateVariable;
10+
11+
#[tokio::main]
12+
async fn main() {
13+
let body = PrintReportRequest::new(PrintReportRequestData::new(
14+
PrintReportRequestAttributes::new(
15+
"abc-def-ghi".to_string(),
16+
ReportScheduleResourceType::DASHBOARD,
17+
vec![ReportScheduleTemplateVariable::new(
18+
"env".to_string(),
19+
vec!["prod".to_string()],
20+
)],
21+
"America/New_York".to_string(),
22+
)
23+
.from_ts(1780318800000)
24+
.timeframe("1w".to_string())
25+
.to_ts(1780923600000),
26+
PrintReportType::REPORT,
27+
));
28+
let configuration = datadog::Configuration::new();
29+
let api = ReportSchedulesAPI::with_config(configuration);
30+
let resp = api.print_report(body).await;
31+
if let Ok(value) = resp {
32+
println!("{:#?}", value);
33+
} else {
34+
println!("{:#?}", resp.unwrap_err());
35+
}
36+
}

src/datadogV2/api/api_report_schedules.rs

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ pub enum GetReportSchedulesForResourceError {
9191
UnknownValue(serde_json::Value),
9292
}
9393

94+
/// ListDatasetReportSchedulesError is a struct for typed errors of method [`ReportSchedulesAPI::list_dataset_report_schedules`]
95+
#[derive(Debug, Clone, Serialize, Deserialize)]
96+
#[serde(untagged)]
97+
pub enum ListDatasetReportSchedulesError {
98+
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
99+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
100+
UnknownValue(serde_json::Value),
101+
}
102+
94103
/// ListReportSchedulesError is a struct for typed errors of method [`ReportSchedulesAPI::list_report_schedules`]
95104
#[derive(Debug, Clone, Serialize, Deserialize)]
96105
#[serde(untagged)]
@@ -109,6 +118,15 @@ pub enum PatchReportScheduleError {
109118
UnknownValue(serde_json::Value),
110119
}
111120

121+
/// PrintReportError is a struct for typed errors of method [`ReportSchedulesAPI::print_report`]
122+
#[derive(Debug, Clone, Serialize, Deserialize)]
123+
#[serde(untagged)]
124+
pub enum PrintReportError {
125+
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
126+
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
127+
UnknownValue(serde_json::Value),
128+
}
129+
112130
/// ToggleReportScheduleError is a struct for typed errors of method [`ReportSchedulesAPI::toggle_report_schedule`]
113131
#[derive(Debug, Clone, Serialize, Deserialize)]
114132
#[serde(untagged)]
@@ -705,6 +723,122 @@ impl ReportSchedulesAPI {
705723
}
706724
}
707725

726+
/// Retrieve all report schedules for a given published dataset.
727+
/// Returns report schedules belonging to the authenticated user's organization that target the specified dataset.
728+
/// Requires the `generate_log_reports` or `manage_log_reports` permission.
729+
pub async fn list_dataset_report_schedules(
730+
&self,
731+
dataset_id: String,
732+
) -> Result<
733+
crate::datadogV2::model::DatasetReportScheduleListResponse,
734+
datadog::Error<ListDatasetReportSchedulesError>,
735+
> {
736+
match self
737+
.list_dataset_report_schedules_with_http_info(dataset_id)
738+
.await
739+
{
740+
Ok(response_content) => {
741+
if let Some(e) = response_content.entity {
742+
Ok(e)
743+
} else {
744+
Err(datadog::Error::Serde(serde::de::Error::custom(
745+
"response content was None",
746+
)))
747+
}
748+
}
749+
Err(err) => Err(err),
750+
}
751+
}
752+
753+
/// Retrieve all report schedules for a given published dataset.
754+
/// Returns report schedules belonging to the authenticated user's organization that target the specified dataset.
755+
/// Requires the `generate_log_reports` or `manage_log_reports` permission.
756+
pub async fn list_dataset_report_schedules_with_http_info(
757+
&self,
758+
dataset_id: String,
759+
) -> Result<
760+
datadog::ResponseContent<crate::datadogV2::model::DatasetReportScheduleListResponse>,
761+
datadog::Error<ListDatasetReportSchedulesError>,
762+
> {
763+
let local_configuration = &self.config;
764+
let operation_id = "v2.list_dataset_report_schedules";
765+
766+
let local_client = &self.client;
767+
768+
let local_uri_str = format!(
769+
"{}/api/v2/reporting/dataset/{dataset_id}/schedules",
770+
local_configuration.get_operation_host(operation_id),
771+
dataset_id = datadog::urlencode(dataset_id)
772+
);
773+
let mut local_req_builder =
774+
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
775+
776+
// build headers
777+
let mut headers = HeaderMap::new();
778+
headers.insert("Accept", HeaderValue::from_static("application/json"));
779+
780+
// build user agent
781+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
782+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
783+
Err(e) => {
784+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
785+
headers.insert(
786+
reqwest::header::USER_AGENT,
787+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
788+
)
789+
}
790+
};
791+
792+
// build auth
793+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
794+
headers.insert(
795+
"DD-API-KEY",
796+
HeaderValue::from_str(local_key.key.as_str())
797+
.expect("failed to parse DD-API-KEY header"),
798+
);
799+
};
800+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
801+
headers.insert(
802+
"DD-APPLICATION-KEY",
803+
HeaderValue::from_str(local_key.key.as_str())
804+
.expect("failed to parse DD-APPLICATION-KEY header"),
805+
);
806+
};
807+
808+
local_req_builder = local_req_builder.headers(headers);
809+
let local_req = local_req_builder.build()?;
810+
log::debug!("request content: {:?}", local_req.body());
811+
let local_resp = local_client.execute(local_req).await?;
812+
813+
let local_status = local_resp.status();
814+
let local_content = local_resp.text().await?;
815+
log::debug!("response content: {}", local_content);
816+
817+
if !local_status.is_client_error() && !local_status.is_server_error() {
818+
match serde_json::from_str::<crate::datadogV2::model::DatasetReportScheduleListResponse>(
819+
&local_content,
820+
) {
821+
Ok(e) => {
822+
return Ok(datadog::ResponseContent {
823+
status: local_status,
824+
content: local_content,
825+
entity: Some(e),
826+
})
827+
}
828+
Err(e) => return Err(datadog::Error::Serde(e)),
829+
};
830+
} else {
831+
let local_entity: Option<ListDatasetReportSchedulesError> =
832+
serde_json::from_str(&local_content).ok();
833+
let local_error = datadog::ResponseContent {
834+
status: local_status,
835+
content: local_content,
836+
entity: local_entity,
837+
};
838+
Err(datadog::Error::ResponseError(local_error))
839+
}
840+
}
841+
708842
/// List dashboard and integration dashboard report schedules for the organization.
709843
/// The response is paginated and can be filtered by title, author UUID, or recipients.
710844
/// Requires the `generate_dashboard_reports` permission.
@@ -1020,6 +1154,162 @@ impl ReportSchedulesAPI {
10201154
}
10211155
}
10221156

1157+
/// Initiate a one-off, print-only report for a dashboard or integration dashboard.
1158+
/// The report is rendered as a PDF and made available for download through the URL returned in the response.
1159+
/// Requires a reporting permission appropriate to the targeted resource type.
1160+
pub async fn print_report(
1161+
&self,
1162+
body: crate::datadogV2::model::PrintReportRequest,
1163+
) -> Result<crate::datadogV2::model::PrintReportResponse, datadog::Error<PrintReportError>>
1164+
{
1165+
match self.print_report_with_http_info(body).await {
1166+
Ok(response_content) => {
1167+
if let Some(e) = response_content.entity {
1168+
Ok(e)
1169+
} else {
1170+
Err(datadog::Error::Serde(serde::de::Error::custom(
1171+
"response content was None",
1172+
)))
1173+
}
1174+
}
1175+
Err(err) => Err(err),
1176+
}
1177+
}
1178+
1179+
/// Initiate a one-off, print-only report for a dashboard or integration dashboard.
1180+
/// The report is rendered as a PDF and made available for download through the URL returned in the response.
1181+
/// Requires a reporting permission appropriate to the targeted resource type.
1182+
pub async fn print_report_with_http_info(
1183+
&self,
1184+
body: crate::datadogV2::model::PrintReportRequest,
1185+
) -> Result<
1186+
datadog::ResponseContent<crate::datadogV2::model::PrintReportResponse>,
1187+
datadog::Error<PrintReportError>,
1188+
> {
1189+
let local_configuration = &self.config;
1190+
let operation_id = "v2.print_report";
1191+
1192+
let local_client = &self.client;
1193+
1194+
let local_uri_str = format!(
1195+
"{}/api/v2/reporting/print",
1196+
local_configuration.get_operation_host(operation_id)
1197+
);
1198+
let mut local_req_builder =
1199+
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1200+
1201+
// build headers
1202+
let mut headers = HeaderMap::new();
1203+
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1204+
headers.insert("Accept", HeaderValue::from_static("application/json"));
1205+
1206+
// build user agent
1207+
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1208+
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1209+
Err(e) => {
1210+
log::warn!("Failed to parse user agent header: {e}, falling back to default");
1211+
headers.insert(
1212+
reqwest::header::USER_AGENT,
1213+
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1214+
)
1215+
}
1216+
};
1217+
1218+
// build auth
1219+
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1220+
headers.insert(
1221+
"DD-API-KEY",
1222+
HeaderValue::from_str(local_key.key.as_str())
1223+
.expect("failed to parse DD-API-KEY header"),
1224+
);
1225+
};
1226+
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1227+
headers.insert(
1228+
"DD-APPLICATION-KEY",
1229+
HeaderValue::from_str(local_key.key.as_str())
1230+
.expect("failed to parse DD-APPLICATION-KEY header"),
1231+
);
1232+
};
1233+
1234+
// build body parameters
1235+
let output = Vec::new();
1236+
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1237+
if body.serialize(&mut ser).is_ok() {
1238+
if let Some(content_encoding) = headers.get("Content-Encoding") {
1239+
match content_encoding.to_str().unwrap_or_default() {
1240+
"gzip" => {
1241+
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1242+
let _ = enc.write_all(ser.into_inner().as_slice());
1243+
match enc.finish() {
1244+
Ok(buf) => {
1245+
local_req_builder = local_req_builder.body(buf);
1246+
}
1247+
Err(e) => return Err(datadog::Error::Io(e)),
1248+
}
1249+
}
1250+
"deflate" => {
1251+
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1252+
let _ = enc.write_all(ser.into_inner().as_slice());
1253+
match enc.finish() {
1254+
Ok(buf) => {
1255+
local_req_builder = local_req_builder.body(buf);
1256+
}
1257+
Err(e) => return Err(datadog::Error::Io(e)),
1258+
}
1259+
}
1260+
#[cfg(feature = "zstd")]
1261+
"zstd1" => {
1262+
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1263+
let _ = enc.write_all(ser.into_inner().as_slice());
1264+
match enc.finish() {
1265+
Ok(buf) => {
1266+
local_req_builder = local_req_builder.body(buf);
1267+
}
1268+
Err(e) => return Err(datadog::Error::Io(e)),
1269+
}
1270+
}
1271+
_ => {
1272+
local_req_builder = local_req_builder.body(ser.into_inner());
1273+
}
1274+
}
1275+
} else {
1276+
local_req_builder = local_req_builder.body(ser.into_inner());
1277+
}
1278+
}
1279+
1280+
local_req_builder = local_req_builder.headers(headers);
1281+
let local_req = local_req_builder.build()?;
1282+
log::debug!("request content: {:?}", local_req.body());
1283+
let local_resp = local_client.execute(local_req).await?;
1284+
1285+
let local_status = local_resp.status();
1286+
let local_content = local_resp.text().await?;
1287+
log::debug!("response content: {}", local_content);
1288+
1289+
if !local_status.is_client_error() && !local_status.is_server_error() {
1290+
match serde_json::from_str::<crate::datadogV2::model::PrintReportResponse>(
1291+
&local_content,
1292+
) {
1293+
Ok(e) => {
1294+
return Ok(datadog::ResponseContent {
1295+
status: local_status,
1296+
content: local_content,
1297+
entity: Some(e),
1298+
})
1299+
}
1300+
Err(e) => return Err(datadog::Error::Serde(e)),
1301+
};
1302+
} else {
1303+
let local_entity: Option<PrintReportError> = serde_json::from_str(&local_content).ok();
1304+
let local_error = datadog::ResponseContent {
1305+
status: local_status,
1306+
content: local_content,
1307+
entity: local_entity,
1308+
};
1309+
Err(datadog::Error::ResponseError(local_error))
1310+
}
1311+
}
1312+
10231313
/// Activate or pause a report schedule by setting its status to `active` or `inactive`.
10241314
/// Requires a reporting write permission appropriate to the targeted resource type and schedule ownership.
10251315
pub async fn toggle_report_schedule(

0 commit comments

Comments
 (0)