rusty_falcon 0.7.1

Rust bindings for CrowdStrike Falcon API
Documentation
/*
 * 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 [`create_file_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateFileV1Error {
    Status400(models::MsaspecResponseFields),
    Status403(models::MsaspecResponseFields),
    Status404(models::MsaspecResponseFields),
    Status429(models::MsaReplyMetaOnly),
    Status500(models::MsaspecResponseFields),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`update_file_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateFileV1Error {
    Status400(models::MsaspecResponseFields),
    Status403(models::MsaspecResponseFields),
    Status404(models::MsaspecResponseFields),
    Status429(models::MsaReplyMetaOnly),
    Status500(models::MsaspecResponseFields),
    UnknownValue(serde_json::Value),
}

pub async fn create_file_v1(
    configuration: &configuration::Configuration,
    file: std::path::PathBuf,
    name: &str,
    x_cs_username: Option<&str>,
    x_cs_useruuid: Option<&str>,
    description: Option<&str>,
    id: Option<&str>,
    repo: Option<&str>,
) -> Result<models::DomainLookupFileWrapper, Error<CreateFileV1Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let _p_form_file = file;
    let p_form_name = name;
    let p_header_x_cs_username = x_cs_username;
    let p_header_x_cs_useruuid = x_cs_useruuid;
    let p_form_description = description;
    let p_form_id = id;
    let p_form_repo = repo;

    let uri_str = format!(
        "{}/loggingapi/entities/lookup-files/v1",
        configuration.base_path
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &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(param_value) = p_header_x_cs_username {
        req_builder = req_builder.header("X-CS-USERNAME", param_value.to_string());
    }
    if let Some(param_value) = p_header_x_cs_useruuid {
        req_builder = req_builder.header("X-CS-USERUUID", param_value.to_string());
    }
    let mut multipart_form = reqwest::multipart::Form::new();
    // TODO: support file upload for 'file' parameter
    multipart_form = multipart_form.text("name", p_form_name.to_string());
    if let Some(param_value) = p_form_description {
        multipart_form = multipart_form.text("description", param_value.to_string());
    }
    if let Some(param_value) = p_form_id {
        multipart_form = multipart_form.text("id", param_value.to_string());
    }
    if let Some(param_value) = p_form_repo {
        multipart_form = multipart_form.text("repo", param_value.to_string());
    }
    req_builder = req_builder.multipart(multipart_form);

    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::DomainLookupFileWrapper`",
                )));
            }
            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::DomainLookupFileWrapper`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateFileV1Error> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

pub async fn update_file_v1(
    configuration: &configuration::Configuration,
    id: &str,
    x_cs_username: Option<&str>,
    x_cs_useruuid: Option<&str>,
    description: Option<&str>,
    file: Option<std::path::PathBuf>,
) -> Result<models::DomainLookupFileWrapper, Error<UpdateFileV1Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_form_id = id;
    let p_header_x_cs_username = x_cs_username;
    let p_header_x_cs_useruuid = x_cs_useruuid;
    let p_form_description = description;
    let _p_form_file = file;

    let uri_str = format!(
        "{}/loggingapi/entities/lookup-files/v1",
        configuration.base_path
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::PATCH, &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(param_value) = p_header_x_cs_username {
        req_builder = req_builder.header("X-CS-USERNAME", param_value.to_string());
    }
    if let Some(param_value) = p_header_x_cs_useruuid {
        req_builder = req_builder.header("X-CS-USERUUID", param_value.to_string());
    }
    let mut multipart_form = reqwest::multipart::Form::new();
    multipart_form = multipart_form.text("id", p_form_id.to_string());
    if let Some(param_value) = p_form_description {
        multipart_form = multipart_form.text("description", param_value.to_string());
    }
    // TODO: support file upload for 'file' parameter
    req_builder = req_builder.multipart(multipart_form);

    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::DomainLookupFileWrapper`",
                )));
            }
            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::DomainLookupFileWrapper`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<UpdateFileV1Error> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}