antimatter 2.0.13

antimatter.io Rust library for data control
Documentation
use super::Session;
use crate::session::session::SessionError;
use crate::session::RUNTIME;
use antimatter_api::apis::authentication_api::{self as auth_api};
use antimatter_api::apis::capsules_api::{self as cap_api};
use antimatter_api::apis::contexts_api::{self as ctx_api};
use antimatter_api::apis::general_api::{self as api};
use antimatter_api::apis::policy_api::{self as pol_api};
use antimatter_api::models::{
    AccessLogResults, DomainControlLogResults, DomainHooksList, DomainPrivateInfo,
    DomainPublicInfo, DomainResourceSummary, DomainSettings, DomainStatus, NewDomainSettings,
    NewVendorSettings, VendorSettings,
};

impl Session {
    /// Fetches session's domain's private information.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainPrivateInfo` with the private information
    /// for the session's domain.
    pub fn get_private_info(&mut self) -> Result<DomainPrivateInfo, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_get_private_info(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Fetches session's domain's public information.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainPublicInfo` with the public information
    /// for the session's domain.
    pub fn get_public_info(&mut self) -> Result<DomainPublicInfo, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_get_public_info(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Fetches session's domain's settings.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainSettings` with the settings for the
    /// session's domain.
    pub fn get_settings(&mut self) -> Result<DomainSettings, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_get_settings(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Update the domain's settings.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainSettings` with the settings for the
    /// session's domain.
    pub fn put_settings(
        &mut self,
        new_domain_settings: NewDomainSettings,
    ) -> Result<DomainSettings, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_put_settings(
                &conf,
                self.get_domain_id().as_str(),
                new_domain_settings,
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Fetches session's domain's status.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainStatus` with the status for the
    /// session's domain.
    pub fn get_status(&mut self) -> Result<DomainStatus, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_get_status(&conf, self.get_domain_id().as_str()))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Fetches a list of hooks for the session's domain.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainHooksList` with a vector of hooks in the
    /// session's domain.
    pub fn list_hooks(&mut self) -> Result<DomainHooksList, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(ctx_api::domain_list_hooks(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Fetches a list of available resources for the session's domain.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainResourceSummary` with a vector of
    /// available resources in the session's domain.
    pub fn list_resources(&mut self) -> Result<DomainResourceSummary, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(pol_api::domain_list_resources(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Gets the session's domain's access logs applying provided filtered.
    ///
    /// Arguments:
    ///
    /// * `start_date` - An Option<String> to retrieve capsule after
    ///     (format "YYYY-MM-DD HH:MM:SS").
    /// * `end_date` - An Option<String> to retrieve capsule before
    ///     (format "YYYY-MM-DD HH:MM:SS").
    /// * `num_results` - An Option<i32> indicating the number of capsules to
    ///     retrieve.
    /// * `start_from_id` - An Option<&str> log ID to get results after/before.
    /// * `session` - An Option<&str> contains the authenticated session's ID.
    /// * `location` - An Option<&str> contains the location to filter on.
    /// * `location_prefixed` - An Option<bool> contains a location prefix to
    ///     filter on.
    /// * `operation_type` - An Option<&str> containing the operation type.
    /// * `allowed_tag` - An Option<&str> containing the allowed tag name.
    /// * `redacted_or_tokenized_tag` - An Option<&str> containing the redacted
    ///     or tokenized tag name. Both tag types will be filtered on this tag
    ///     name.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `AccessLogResults` with a vector of access logs.
    pub fn query_access_logs(
        &mut self,
        start_date: Option<String>,
        end_date: Option<String>,
        num_results: Option<i32>,
        start_from_id: Option<&str>,
        session: Option<&str>,
        location: Option<&str>,
        location_prefixed: Option<bool>,
        operation_type: Option<&str>,
        allowed_tag: Option<&str>,
        redacted_or_tokenized_tag: Option<&str>,
    ) -> Result<AccessLogResults, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(cap_api::domain_query_access_log(
                &conf,
                self.get_domain_id().as_str(),
                start_date,
                end_date,
                num_results,
                start_from_id,
                session,
                location,
                location_prefixed,
                operation_type,
                allowed_tag,
                redacted_or_tokenized_tag,
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Gets the session's domain's control logs applying provided filtered.
    ///
    /// Arguments:
    ///
    /// * `start_date` - An Option<String> to retrieve capsule after
    ///     (format "YYYY-MM-DD HH:MM:SS").
    /// * `end_date` - An Option<String> to retrieve capsule before
    ///     (format "YYYY-MM-DD HH:MM:SS").
    /// * `num_results` - An Option<i32> indicating the number of capsules to
    ///     retrieve.
    /// * `start_from_id` - An Option<&str> log ID to get results after/before.
    /// * `session` - An Option<&str> contains the authenticated session's ID.
    /// * `url` - An Option<&str> contains the URL to filter on.
    /// * `description` - An Option<&str> contains a description to
    ///     filter on.
    ///
    /// Returns:
    ///
    /// A `Result` containing a `DomainControlLogResults` with a vector of
    /// control logs.
    pub fn query_control_log(
        &mut self,
        start_date: Option<String>,
        end_date: Option<String>,
        num_results: Option<i32>,
        start_from_id: Option<&str>,
        session: Option<&str>,
        url: Option<&str>,
        description: Option<&str>,
    ) -> Result<DomainControlLogResults, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_query_control_log(
                &conf,
                self.get_domain_id().as_str(),
                start_date,
                end_date,
                num_results,
                start_from_id,
                session,
                url,
                description,
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Get vendor settings for the session's domain
    ///
    /// Returns:
    /// A `Result` containing a `VendorSettings` with the vendor settings
    pub fn get_vendor_settings(&mut self) -> Result<VendorSettings, SessionError> {
        let conf = self.get_configuration()?;

        let res = RUNTIME
            .block_on(api::domain_get_vendor_settings(
                &conf,
                self.get_domain_id().as_str(),
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;

        Ok(res)
    }

    /// Create or update vendor settings for the session's domain
    ///
    /// Arguments:
    /// - `vendor_settings` - A `NewVendorSettings` containing the vendor settings
    pub fn put_vendor_settings(
        &mut self,
        vendor_settings: NewVendorSettings,
    ) -> Result<(), SessionError> {
        let conf = self.get_configuration()?;

        RUNTIME
            .block_on(auth_api::domain_put_vendor_settings(
                &conf,
                self.get_domain_id().as_str(),
                vendor_settings,
            ))
            .map_err(|e| SessionError::APIError(format!("{}", e)))?;
        Ok(())
    }
}