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

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions examples/v2_application-security_GetAsmServiceByName.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Get Application Security details for a service returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_application_security::ApplicationSecurityAPI;

#[tokio::main]
async fn main() {
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.GetAsmServiceByName", true);
let api = ApplicationSecurityAPI::with_config(configuration);
let resp = api
.get_asm_service_by_name("service_filter".to_string())
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
1 change: 1 addition & 0 deletions src/datadog/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ impl Default for Configuration {
("v2.update_connection".to_owned(), false),
("v2.get_pruned_trace_by_id".to_owned(), false),
("v2.get_trace_by_id".to_owned(), false),
("v2.get_asm_service_by_name".to_owned(), false),
("v2.create_report_schedule".to_owned(), false),
("v2.patch_report_schedule".to_owned(), false),
("v2.delete_sourcemaps".to_owned(), false),
Expand Down
135 changes: 135 additions & 0 deletions src/datadogV2/api/api_application_security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use flate2::{
write::{GzEncoder, ZlibEncoder},
Compression,
};
use log::warn;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
Expand Down Expand Up @@ -82,6 +83,14 @@ pub enum GetApplicationSecurityWafPolicyError {
UnknownValue(serde_json::Value),
}

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

/// ListApplicationSecurityWAFCustomRulesError is a struct for typed errors of method [`ApplicationSecurityAPI::list_application_security_waf_custom_rules`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -1313,6 +1322,132 @@ impl ApplicationSecurityAPI {
}
}

/// Retrieve Application Security details for services matching the given name.
/// Returns Application Security activation, compatibility, and product enablement
/// information for each matching `(service, environment)` pair, along with a count
/// of services that have Application Security Management (Threats) enabled.
pub async fn get_asm_service_by_name(
&self,
service_filter: String,
) -> Result<
crate::datadogV2::model::ApplicationSecurityServicesResponse,
datadog::Error<GetAsmServiceByNameError>,
> {
match self
.get_asm_service_by_name_with_http_info(service_filter)
.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 Application Security details for services matching the given name.
/// Returns Application Security activation, compatibility, and product enablement
/// information for each matching `(service, environment)` pair, along with a count
/// of services that have Application Security Management (Threats) enabled.
pub async fn get_asm_service_by_name_with_http_info(
&self,
service_filter: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::ApplicationSecurityServicesResponse>,
datadog::Error<GetAsmServiceByNameError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_asm_service_by_name";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.get_asm_service_by_name' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}

let local_client = &self.client;

let local_uri_str = format!(
"{}/api/v2/security/asm/services/{service_filter}",
local_configuration.get_operation_host(operation_id),
service_filter = datadog::urlencode(service_filter)
);
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::ApplicationSecurityServicesResponse>(
&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<GetAsmServiceByNameError> =
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))
}
}

/// Retrieve a list of WAF custom rule.
pub async fn list_application_security_waf_custom_rules(
&self,
Expand Down
10 changes: 10 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9734,6 +9734,16 @@ pub mod model_security_entity_risk_scores_meta;
pub use self::model_security_entity_risk_scores_meta::SecurityEntityRiskScoresMeta;
pub mod model_security_entity_risk_score_response;
pub use self::model_security_entity_risk_score_response::SecurityEntityRiskScoreResponse;
pub mod model_application_security_services_response;
pub use self::model_application_security_services_response::ApplicationSecurityServicesResponse;
pub mod model_application_security_service_resource;
pub use self::model_application_security_service_resource::ApplicationSecurityServiceResource;
pub mod model_application_security_service_attributes;
pub use self::model_application_security_service_attributes::ApplicationSecurityServiceAttributes;
pub mod model_application_security_service_type;
pub use self::model_application_security_service_type::ApplicationSecurityServiceType;
pub mod model_application_security_services_metadata;
pub use self::model_application_security_services_metadata::ApplicationSecurityServicesMetadata;
pub mod model_security_findings_sort;
pub use self::model_security_findings_sort::SecurityFindingsSort;
pub mod model_list_security_findings_response;
Expand Down
Loading
Loading