antimatter_api 2.0.13

Interact with the Antimatter Cloud API
Documentation
/*
 * Antimatter Public API
 *
 * Interact with the Antimatter Cloud API
 *
 * The version of the OpenAPI document: 2.0.13
 * Contact: support@antimatter.io
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};


/// struct for typed errors of method [`domain_add_access_log_entry`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainAddAccessLogEntryError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status403(),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_create_capsule`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainCreateCapsuleError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status403(models::ForbiddenError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_data_tagging_hook_invoke`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainDataTaggingHookInvokeError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_data_tagging_hook_test`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainDataTaggingHookTestError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_open_capsule`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainOpenCapsuleError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status403(models::ForbiddenError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_seal_capsule`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainSealCapsuleError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`domain_upsert_span_tags`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DomainUpsertSpanTagsError {
    Status400(models::InvalidRequestError),
    Status401(models::UnauthorizedError),
    Status404(models::ResourceNotFoundError),
    Status409(models::ConflictError),
    Status412(models::PreconditionFailedError),
    Status429(models::ResourceExhaustedError),
    DefaultResponse(models::Error),
    UnknownValue(serde_json::Value),
}


/// Adds a data-plane audit log entry for this capsule. Contains information about the originating principal and about read tag rollups. Contains an open capsule token (read from the file) to ensure that you legitimately read the capsule. Note that not all audit log entry types may be added with this method. Some (like open records) are generated server side. 
pub async fn domain_add_access_log_entry(configuration: &configuration::Configuration, domain_id: &str, capsule_id: &str, open_token: &str, add_capsule_log_entry_request: models::AddCapsuleLogEntryRequest) -> Result<(), Error<DomainAddAccessLogEntryError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/capsules/{capsuleID}/log", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), capsuleID=crate::apis::urlencode(capsule_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("openToken", &open_token.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&add_capsule_log_entry_request);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        Ok(())
    } else {
        let local_var_entity: Option<DomainAddAccessLogEntryError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Create a new capsule. The ID will be returned. Capsule will be \"unsealed\" first, meaning it's still in a creating state. Returns a capsule create token that can be used to feed in additional data about the capsule while it's still unsealed. Also returns a DEK and an encrypted DEK. 
pub async fn domain_create_capsule(configuration: &configuration::Configuration, domain_id: &str, write_context: &str, body: serde_json::Value) -> Result<models::CapsuleCreateResponse, Error<DomainCreateCapsuleError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/capsules", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("writeContext", &write_context.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&body);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<DomainCreateCapsuleError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Invoke a hook that operates on data and returns tags 
pub async fn domain_data_tagging_hook_invoke(configuration: &configuration::Configuration, domain_id: &str, hook_name: &str, data_tagging_hook_input: models::DataTaggingHookInput, write_context: Option<&str>) -> Result<models::DataTaggingHookResponse, Error<DomainDataTaggingHookInvokeError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/hooks/data-tagging/{hookName}/invoke", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), hookName=crate::apis::urlencode(hook_name));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = write_context {
        local_var_req_builder = local_var_req_builder.query(&[("writeContext", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&data_tagging_hook_input);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<DomainDataTaggingHookInvokeError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Invoke a hook that operates on data and returns tags. This endpoint is intended for testing purposes when creating regex or llm rules before adding them to write contexts, or for one-off classification of data without configuring a write context and so forth. 
pub async fn domain_data_tagging_hook_test(configuration: &configuration::Configuration, domain_id: &str, hook_name: &str, domain_data_tagging_hook_test_request: models::DomainDataTaggingHookTestRequest) -> Result<models::DataTaggingHookResponse, Error<DomainDataTaggingHookTestError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/hooks/data-tagging/{hookName}/test", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), hookName=crate::apis::urlencode(hook_name));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&domain_data_tagging_hook_test_request);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<DomainDataTaggingHookTestError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Given the encrypted DEK for this capsule, get back the decrypted DEK. contains the read context 
pub async fn domain_open_capsule(configuration: &configuration::Configuration, domain_id: &str, capsule_id: &str, read_context: &str, capsule_open_request: models::CapsuleOpenRequest) -> Result<models::CapsuleOpenResponse, Error<DomainOpenCapsuleError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/capsules/{capsuleID}/open", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), capsuleID=crate::apis::urlencode(capsule_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("readContext", &read_context.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&capsule_open_request);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<DomainOpenCapsuleError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Seal this capsule, if it's unsealed. Requires capsule create token
pub async fn domain_seal_capsule(configuration: &configuration::Configuration, domain_id: &str, capsule_id: &str, create_token: &str, capsule_seal_request: models::CapsuleSealRequest) -> Result<(), Error<DomainSealCapsuleError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/capsules/{capsuleID}/seal", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), capsuleID=crate::apis::urlencode(capsule_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("createToken", &create_token.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&capsule_seal_request);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        Ok(())
    } else {
        let local_var_entity: Option<DomainSealCapsuleError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Upsert span tag rollups. This is only permitted when a capsule is not sealed. It requires a special \"capsule owner\" token that is returned by create capsule. Note that the rollup calculations must be done on the client side. This method only permits storing the entire rollup, not aggregating serverside. This is idempotent 
pub async fn domain_upsert_span_tags(configuration: &configuration::Configuration, domain_id: &str, capsule_id: &str, create_token: &str, upsert_span_tags_request: models::UpsertSpanTagsRequest) -> Result<(), Error<DomainUpsertSpanTagsError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/domains/{domainID}/capsules/{capsuleID}/span-tags", local_var_configuration.base_path, domainID=crate::apis::urlencode(domain_id), capsuleID=crate::apis::urlencode(capsule_id));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("createToken", &create_token.to_string())]);
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&upsert_span_tags_request);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        Ok(())
    } else {
        let local_var_entity: Option<DomainUpsertSpanTagsError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}