/*
* CrowdStrike API Specification
*
* Use this API specification as a reference for the API endpoints you can use to interact with your Falcon environment. These endpoints support authentication via OAuth2 and interact with detections and network containment. For detailed usage guides and examples, see our [documentation inside the Falcon console](https://falcon.crowdstrike.com/support/documentation). To use the APIs described below, combine the base URL with the path shown for each API endpoint. For commercial cloud customers, your base URL is `https://api.crowdstrike.com`. Each API endpoint requires authorization via an OAuth2 token. Your first API request should retrieve an OAuth2 token using the `oauth2/token` endpoint, such as `https://api.crowdstrike.com/oauth2/token`. For subsequent requests, include the OAuth2 token in an HTTP authorization header. Tokens expire after 30 minutes, after which you should make a new token request to continue making API requests.
*
* The version of the OpenAPI document: rolling
*
* Generated by: https://openapi-generator.tech
*/
use super::{ContentType, Error, configuration};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::de::Error as _;
/// struct for typed errors of method [`combined_edges_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CombinedEdgesGetError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::MsaReplyMetaOnly),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`combined_ran_on_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CombinedRanOnGetError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::MsaReplyMetaOnly),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`combined_summary_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CombinedSummaryGetError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::MsaReplyMetaOnly),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`entities_vertices_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EntitiesVerticesGetError {
Status400(models::ThreatgraphVertexDetailsResponse),
Status401(models::ThreatgraphVertexDetailsResponse),
Status403(models::MsaReplyMetaOnly),
Status404(models::ThreatgraphVertexDetailsResponse),
Status410(models::ThreatgraphVertexDetailsResponse),
Status429(models::MsaReplyMetaOnly),
Status500(models::ThreatgraphVertexDetailsResponse),
Status502(models::ThreatgraphVertexDetailsResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`entities_vertices_getv2`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EntitiesVerticesGetv2Error {
Status400(models::ThreatgraphVertexDetailsResponse),
Status401(models::ThreatgraphVertexDetailsResponse),
Status403(models::MsaReplyMetaOnly),
Status404(models::ThreatgraphVertexDetailsResponse),
Status410(models::ThreatgraphVertexDetailsResponse),
Status429(models::MsaReplyMetaOnly),
Status500(models::ThreatgraphVertexDetailsResponse),
Status502(models::ThreatgraphVertexDetailsResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`queries_edgetypes_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum QueriesEdgetypesGetError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::MsaReplyMetaOnly),
UnknownValue(serde_json::Value),
}
pub async fn combined_edges_get(
configuration: &configuration::Configuration,
ids: &str,
edge_type: &str,
limit: Option<i32>,
offset: Option<&str>,
direction: Option<&str>,
scope: Option<&str>,
nano: Option<bool>,
) -> Result<(), Error<CombinedEdgesGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_ids = ids;
let p_query_edge_type = edge_type;
let p_query_limit = limit;
let p_query_offset = offset;
let p_query_direction = direction;
let p_query_scope = scope;
let p_query_nano = nano;
let uri_str = format!("{}/threatgraph/combined/edges/v1", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("ids", &p_query_ids.to_string())]);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("edge_type", &p_query_edge_type.to_string())]);
if let Some(ref param_value) = p_query_direction {
req_builder = req_builder.query(&[("direction", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_scope {
req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_nano {
req_builder = req_builder.query(&[("nano", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<CombinedEdgesGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn combined_ran_on_get(
configuration: &configuration::Configuration,
value: &str,
r#type: &str,
limit: Option<i32>,
offset: Option<&str>,
nano: Option<bool>,
) -> Result<(), Error<CombinedRanOnGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_value = value;
let p_query_type = r#type;
let p_query_limit = limit;
let p_query_offset = offset;
let p_query_nano = nano;
let uri_str = format!("{}/threatgraph/combined/ran-on/v1", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("value", &p_query_value.to_string())]);
req_builder = req_builder.query(&[("type", &p_query_type.to_string())]);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_nano {
req_builder = req_builder.query(&[("nano", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<CombinedRanOnGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn combined_summary_get(
configuration: &configuration::Configuration,
vertex_type: &str,
ids: Vec<String>,
scope: Option<&str>,
nano: Option<bool>,
) -> Result<(), Error<CombinedSummaryGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_vertex_type = vertex_type;
let p_query_ids = ids;
let p_query_scope = scope;
let p_query_nano = nano;
let uri_str = format!(
"{}/threatgraph/combined/{vertex_type}/summary/v1",
configuration.base_path,
vertex_type = crate::apis::urlencode(p_path_vertex_type)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "multi" {
"multi" => req_builder.query(
&p_query_ids
.into_iter()
.map(|p| ("ids".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"ids",
&p_query_ids
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
if let Some(ref param_value) = p_query_scope {
req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_nano {
req_builder = req_builder.query(&[("nano", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<CombinedSummaryGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn entities_vertices_get(
configuration: &configuration::Configuration,
vertex_type: &str,
ids: Vec<String>,
scope: Option<&str>,
nano: Option<bool>,
) -> Result<models::ThreatgraphVertexDetailsResponse, Error<EntitiesVerticesGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_vertex_type = vertex_type;
let p_query_ids = ids;
let p_query_scope = scope;
let p_query_nano = nano;
let uri_str = format!(
"{}/threatgraph/entities/{vertex_type}/v1",
configuration.base_path,
vertex_type = crate::apis::urlencode(p_path_vertex_type)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "multi" {
"multi" => req_builder.query(
&p_query_ids
.into_iter()
.map(|p| ("ids".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"ids",
&p_query_ids
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
if let Some(ref param_value) = p_query_scope {
req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_nano {
req_builder = req_builder.query(&[("nano", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ThreatgraphVertexDetailsResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::ThreatgraphVertexDetailsResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<EntitiesVerticesGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn entities_vertices_getv2(
configuration: &configuration::Configuration,
vertex_type: &str,
ids: Vec<String>,
scope: Option<&str>,
nano: Option<bool>,
) -> Result<models::ThreatgraphVertexDetailsResponse, Error<EntitiesVerticesGetv2Error>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_vertex_type = vertex_type;
let p_query_ids = ids;
let p_query_scope = scope;
let p_query_nano = nano;
let uri_str = format!(
"{}/threatgraph/entities/{vertex_type}/v2",
configuration.base_path,
vertex_type = crate::apis::urlencode(p_path_vertex_type)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "multi" {
"multi" => req_builder.query(
&p_query_ids
.into_iter()
.map(|p| ("ids".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"ids",
&p_query_ids
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
if let Some(ref param_value) = p_query_scope {
req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_nano {
req_builder = req_builder.query(&[("nano", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ThreatgraphVertexDetailsResponse`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::ThreatgraphVertexDetailsResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<EntitiesVerticesGetv2Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn queries_edgetypes_get(
configuration: &configuration::Configuration,
) -> Result<(), Error<QueriesEdgetypesGetError>> {
let uri_str = format!(
"{}/threatgraph/queries/edge-types/v1",
configuration.base_path
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<QueriesEdgetypesGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}