// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use crate::datadog;
use flate2::{
write::{GzEncoder, ZlibEncoder},
Compression,
};
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
/// GetAppOptionalParams is a struct for passing parameters to the method [`AppBuilderAPI::get_app`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetAppOptionalParams {
/// The version number of the app to retrieve. If not specified, the latest version is returned. Version numbers start at 1 and increment with each update. The special values `latest` and `deployed` can be used to retrieve the latest version or the published version, respectively.
pub version: Option<String>,
}
impl GetAppOptionalParams {
/// The version number of the app to retrieve. If not specified, the latest version is returned. Version numbers start at 1 and increment with each update. The special values `latest` and `deployed` can be used to retrieve the latest version or the published version, respectively.
pub fn version(mut self, value: String) -> Self {
self.version = Some(value);
self
}
}
/// ListAppsOptionalParams is a struct for passing parameters to the method [`AppBuilderAPI::list_apps`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListAppsOptionalParams {
/// The number of apps to return per page.
pub limit: Option<i64>,
/// The page number to return.
pub page: Option<i64>,
/// Filter apps by the app creator. Usually the user's email.
pub filter_user_name: Option<String>,
/// Filter apps by the app creator's UUID.
pub filter_user_uuid: Option<uuid::Uuid>,
/// Filter by app name.
pub filter_name: Option<String>,
/// Filter apps by the app name or the app creator.
pub filter_query: Option<String>,
/// Filter apps by whether they are published.
pub filter_deployed: Option<bool>,
/// Filter apps by tags.
pub filter_tags: Option<String>,
/// Filter apps by whether you have added them to your favorites.
pub filter_favorite: Option<bool>,
/// Filter apps by whether they are enabled for self-service.
pub filter_self_service: Option<bool>,
/// The fields and direction to sort apps by.
pub sort: Option<Vec<crate::datadogV2::model::AppsSortField>>,
}
impl ListAppsOptionalParams {
/// The number of apps to return per page.
pub fn limit(mut self, value: i64) -> Self {
self.limit = Some(value);
self
}
/// The page number to return.
pub fn page(mut self, value: i64) -> Self {
self.page = Some(value);
self
}
/// Filter apps by the app creator. Usually the user's email.
pub fn filter_user_name(mut self, value: String) -> Self {
self.filter_user_name = Some(value);
self
}
/// Filter apps by the app creator's UUID.
pub fn filter_user_uuid(mut self, value: uuid::Uuid) -> Self {
self.filter_user_uuid = Some(value);
self
}
/// Filter by app name.
pub fn filter_name(mut self, value: String) -> Self {
self.filter_name = Some(value);
self
}
/// Filter apps by the app name or the app creator.
pub fn filter_query(mut self, value: String) -> Self {
self.filter_query = Some(value);
self
}
/// Filter apps by whether they are published.
pub fn filter_deployed(mut self, value: bool) -> Self {
self.filter_deployed = Some(value);
self
}
/// Filter apps by tags.
pub fn filter_tags(mut self, value: String) -> Self {
self.filter_tags = Some(value);
self
}
/// Filter apps by whether you have added them to your favorites.
pub fn filter_favorite(mut self, value: bool) -> Self {
self.filter_favorite = Some(value);
self
}
/// Filter apps by whether they are enabled for self-service.
pub fn filter_self_service(mut self, value: bool) -> Self {
self.filter_self_service = Some(value);
self
}
/// The fields and direction to sort apps by.
pub fn sort(mut self, value: Vec<crate::datadogV2::model::AppsSortField>) -> Self {
self.sort = Some(value);
self
}
}
/// CreateAppError is a struct for typed errors of method [`AppBuilderAPI::create_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// DeleteAppError is a struct for typed errors of method [`AppBuilderAPI::delete_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// DeleteAppsError is a struct for typed errors of method [`AppBuilderAPI::delete_apps`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAppsError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// GetAppError is a struct for typed errors of method [`AppBuilderAPI::get_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// ListAppsError is a struct for typed errors of method [`AppBuilderAPI::list_apps`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAppsError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// PublishAppError is a struct for typed errors of method [`AppBuilderAPI::publish_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PublishAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// UnpublishAppError is a struct for typed errors of method [`AppBuilderAPI::unpublish_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UnpublishAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// UpdateAppError is a struct for typed errors of method [`AppBuilderAPI::update_app`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAppError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
/// Datadog App Builder provides a low-code solution to rapidly develop and integrate secure, customized applications into your monitoring stack that are built to accelerate remediation at scale. These API endpoints allow you to create, read, update, delete, and publish apps.
#[derive(Debug, Clone)]
pub struct AppBuilderAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}
impl Default for AppBuilderAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}
impl AppBuilderAPI {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: datadog::Configuration) -> Self {
let reqwest_client_builder = {
let builder = reqwest::Client::builder();
#[cfg(not(target_arch = "wasm32"))]
let builder = if let Some(proxy_url) = &config.proxy_url {
builder.proxy(reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL"))
} else {
builder
};
builder
};
let middleware_client_builder = {
let builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
#[cfg(feature = "retry")]
let builder = if config.enable_retry {
struct RetryableStatus;
impl reqwest_retry::RetryableStrategy for RetryableStatus {
fn handle(
&self,
res: &Result<reqwest::Response, reqwest_middleware::Error>,
) -> Option<reqwest_retry::Retryable> {
match res {
Ok(success) => reqwest_retry::default_on_request_success(success),
Err(_) => None,
}
}
}
let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
.build_with_max_retries(config.max_retries);
let retry_middleware =
reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
backoff_policy,
RetryableStatus,
);
builder.with(retry_middleware)
} else {
builder
};
builder
};
let client = middleware_client_builder.build();
Self { config, client }
}
pub fn with_client_and_config(
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
) -> Self {
Self { config, client }
}
/// Create a new app, returning the app ID. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn create_app(
&self,
body: crate::datadogV2::model::CreateAppRequest,
) -> Result<crate::datadogV2::model::CreateAppResponse, datadog::Error<CreateAppError>> {
match self.create_app_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),
}
}
/// Create a new app, returning the app ID. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn create_app_with_http_info(
&self,
body: crate::datadogV2::model::CreateAppRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::CreateAppResponse>,
datadog::Error<CreateAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.create_app";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps",
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::CreateAppResponse>(&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<CreateAppError> = 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))
}
}
/// Delete a single app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn delete_app(
&self,
app_id: uuid::Uuid,
) -> Result<crate::datadogV2::model::DeleteAppResponse, datadog::Error<DeleteAppError>> {
match self.delete_app_with_http_info(app_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),
}
}
/// Delete a single app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn delete_app_with_http_info(
&self,
app_id: uuid::Uuid,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::DeleteAppResponse>,
datadog::Error<DeleteAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.delete_app";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps/{app_id}",
local_configuration.get_operation_host(operation_id),
app_id = datadog::urlencode(app_id.to_string())
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, 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::DeleteAppResponse>(&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<DeleteAppError> = 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))
}
}
/// Delete multiple apps in a single request from a list of app IDs. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn delete_apps(
&self,
body: crate::datadogV2::model::DeleteAppsRequest,
) -> Result<crate::datadogV2::model::DeleteAppsResponse, datadog::Error<DeleteAppsError>> {
match self.delete_apps_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),
}
}
/// Delete multiple apps in a single request from a list of app IDs. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn delete_apps_with_http_info(
&self,
body: crate::datadogV2::model::DeleteAppsRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::DeleteAppsResponse>,
datadog::Error<DeleteAppsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.delete_apps";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, 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::DeleteAppsResponse>(
&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<DeleteAppsError> = 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))
}
}
/// Get the full definition of an app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn get_app(
&self,
app_id: uuid::Uuid,
params: GetAppOptionalParams,
) -> Result<crate::datadogV2::model::GetAppResponse, datadog::Error<GetAppError>> {
match self.get_app_with_http_info(app_id, params).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),
}
}
/// Get the full definition of an app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn get_app_with_http_info(
&self,
app_id: uuid::Uuid,
params: GetAppOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::GetAppResponse>,
datadog::Error<GetAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_app";
// unbox and build optional parameters
let version = params.version;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps/{app_id}",
local_configuration.get_operation_host(operation_id),
app_id = datadog::urlencode(app_id.to_string())
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = version {
local_req_builder =
local_req_builder.query(&[("version", &local_query_param.to_string())]);
};
// 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::GetAppResponse>(&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<GetAppError> = 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 all apps, with optional filters and sorting. This endpoint is paginated. Only basic app information such as the app ID, name, and description is returned by this endpoint. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn list_apps(
&self,
params: ListAppsOptionalParams,
) -> Result<crate::datadogV2::model::ListAppsResponse, datadog::Error<ListAppsError>> {
match self.list_apps_with_http_info(params).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),
}
}
/// List all apps, with optional filters and sorting. This endpoint is paginated. Only basic app information such as the app ID, name, and description is returned by this endpoint. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn list_apps_with_http_info(
&self,
params: ListAppsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::ListAppsResponse>,
datadog::Error<ListAppsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_apps";
// unbox and build optional parameters
let limit = params.limit;
let page = params.page;
let filter_user_name = params.filter_user_name;
let filter_user_uuid = params.filter_user_uuid;
let filter_name = params.filter_name;
let filter_query = params.filter_query;
let filter_deployed = params.filter_deployed;
let filter_tags = params.filter_tags;
let filter_favorite = params.filter_favorite;
let filter_self_service = params.filter_self_service;
let sort = params.sort;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = limit {
local_req_builder =
local_req_builder.query(&[("limit", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page {
local_req_builder =
local_req_builder.query(&[("page", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_user_name {
local_req_builder =
local_req_builder.query(&[("filter[user_name]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_user_uuid {
local_req_builder =
local_req_builder.query(&[("filter[user_uuid]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_name {
local_req_builder =
local_req_builder.query(&[("filter[name]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_query {
local_req_builder =
local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_deployed {
local_req_builder =
local_req_builder.query(&[("filter[deployed]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_tags {
local_req_builder =
local_req_builder.query(&[("filter[tags]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_favorite {
local_req_builder =
local_req_builder.query(&[("filter[favorite]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_self_service {
local_req_builder = local_req_builder
.query(&[("filter[self_service]", &local_query_param.to_string())]);
};
if let Some(ref local) = sort {
local_req_builder = local_req_builder.query(&[(
"sort",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
};
// 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::ListAppsResponse>(&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<ListAppsError> = 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))
}
}
/// Publish an app for use by other users. To ensure the app is accessible to the correct users, you also need to set a [Restriction Policy](<https://docs.datadoghq.com/api/latest/restriction-policies/>) on the app if a policy does not yet exist. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn publish_app(
&self,
app_id: uuid::Uuid,
) -> Result<crate::datadogV2::model::PublishAppResponse, datadog::Error<PublishAppError>> {
match self.publish_app_with_http_info(app_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),
}
}
/// Publish an app for use by other users. To ensure the app is accessible to the correct users, you also need to set a [Restriction Policy](<https://docs.datadoghq.com/api/latest/restriction-policies/>) on the app if a policy does not yet exist. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn publish_app_with_http_info(
&self,
app_id: uuid::Uuid,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::PublishAppResponse>,
datadog::Error<PublishAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.publish_app";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps/{app_id}/deployment",
local_configuration.get_operation_host(operation_id),
app_id = datadog::urlencode(app_id.to_string())
);
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("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::PublishAppResponse>(
&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<PublishAppError> = 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))
}
}
/// Unpublish an app, removing the live version of the app. Unpublishing creates a new instance of a `deployment` object on the app, with a nil `app_version_id` (`00000000-0000-0000-0000-000000000000`). The app can still be updated and published again in the future. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn unpublish_app(
&self,
app_id: uuid::Uuid,
) -> Result<crate::datadogV2::model::UnpublishAppResponse, datadog::Error<UnpublishAppError>>
{
match self.unpublish_app_with_http_info(app_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),
}
}
/// Unpublish an app, removing the live version of the app. Unpublishing creates a new instance of a `deployment` object on the app, with a nil `app_version_id` (`00000000-0000-0000-0000-000000000000`). The app can still be updated and published again in the future. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn unpublish_app_with_http_info(
&self,
app_id: uuid::Uuid,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::UnpublishAppResponse>,
datadog::Error<UnpublishAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.unpublish_app";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps/{app_id}/deployment",
local_configuration.get_operation_host(operation_id),
app_id = datadog::urlencode(app_id.to_string())
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, 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::UnpublishAppResponse>(
&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<UnpublishAppError> = 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))
}
}
/// Update an existing app. This creates a new version of the app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn update_app(
&self,
app_id: uuid::Uuid,
body: crate::datadogV2::model::UpdateAppRequest,
) -> Result<crate::datadogV2::model::UpdateAppResponse, datadog::Error<UpdateAppError>> {
match self.update_app_with_http_info(app_id, 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),
}
}
/// Update an existing app. This creates a new version of the app. This API requires a [registered application key](<https://docs.datadoghq.com/api/latest/action-connection/#register-a-new-app-key>). Alternatively, you can configure these permissions [in the UI](<https://docs.datadoghq.com/account_management/api-app-keys/#actions-api-access>).
pub async fn update_app_with_http_info(
&self,
app_id: uuid::Uuid,
body: crate::datadogV2::model::UpdateAppRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::UpdateAppResponse>,
datadog::Error<UpdateAppError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.update_app";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/app-builder/apps/{app_id}",
local_configuration.get_operation_host(operation_id),
app_id = datadog::urlencode(app_id.to_string())
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, 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::UpdateAppResponse>(&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<UpdateAppError> = 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))
}
}
}