workos 1.0.0

Official Rust SDK for the WorkOS API
Documentation
// Code generated by oagen. DO NOT EDIT.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct AuditLogsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateOrganizationAuditLogsRetentionParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: UpdateAuditLogsRetention,
}

impl UpdateOrganizationAuditLogsRetentionParams {
    /// Construct a new `UpdateOrganizationAuditLogsRetentionParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: UpdateAuditLogsRetention) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListActionsParams {
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Upper limit on the number of objects to return, between `1` and `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Order the results by the creation time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<PaginationOrder>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListActionSchemasParams {
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Upper limit on the number of objects to return, between `1` and `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Order the results by the creation time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<PaginationOrder>,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateSchemaParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: AuditLogSchema,
}

impl CreateSchemaParams {
    /// Construct a new `CreateSchemaParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: AuditLogSchema) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateEventParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: AuditLogEventIngestion,
}

impl CreateEventParams {
    /// Construct a new `CreateEventParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: AuditLogEventIngestion) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateExportParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: AuditLogExportCreation,
}

impl CreateExportParams {
    /// Construct a new `CreateExportParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: AuditLogExportCreation) -> Self {
        Self { body }
    }
}

impl<'a> AuditLogsApi<'a> {
    /// Get Retention
    ///
    /// Get the configured event retention period for the given Organization.
    pub async fn get_organization_audit_logs_retention(
        &self,
        id: &str,
    ) -> Result<AuditLogsRetentionJson, Error> {
        self.get_organization_audit_logs_retention_with_options(id, None)
            .await
    }

    /// Variant of [`Self::get_organization_audit_logs_retention`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_organization_audit_logs_retention_with_options(
        &self,
        id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogsRetentionJson, Error> {
        let id = crate::client::path_segment(id);
        let path = format!("/organizations/{id}/audit_logs_retention");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Set Retention
    ///
    /// Set the event retention period for the given Organization.
    pub async fn update_organization_audit_logs_retention(
        &self,
        id: &str,
        params: UpdateOrganizationAuditLogsRetentionParams,
    ) -> Result<AuditLogsRetentionJson, Error> {
        self.update_organization_audit_logs_retention_with_options(id, params, None)
            .await
    }

    /// Variant of [`Self::update_organization_audit_logs_retention`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_organization_audit_logs_retention_with_options(
        &self,
        id: &str,
        params: UpdateOrganizationAuditLogsRetentionParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogsRetentionJson, Error> {
        let id = crate::client::path_segment(id);
        let path = format!("/organizations/{id}/audit_logs_retention");
        let method = http::Method::PUT;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// List Actions
    ///
    /// Get a list of all Audit Log actions in the current environment.
    pub async fn list_actions(
        &self,
        params: ListActionsParams,
    ) -> Result<Vec<AuditLogActionJson>, Error> {
        self.list_actions_with_options(params, None).await
    }

    /// Variant of [`Self::list_actions`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_actions_with_options(
        &self,
        params: ListActionsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Vec<AuditLogActionJson>, Error> {
        let path = "/audit_logs/actions".to_string();
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// List Schemas
    ///
    /// Get a list of all schemas for the Audit Logs action identified by `:name`.
    pub async fn list_action_schemas(
        &self,
        action_name: &str,
        params: ListActionSchemasParams,
    ) -> Result<Vec<AuditLogSchemaJson>, Error> {
        self.list_action_schemas_with_options(action_name, params, None)
            .await
    }

    /// Variant of [`Self::list_action_schemas`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_action_schemas_with_options(
        &self,
        action_name: &str,
        params: ListActionSchemasParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Vec<AuditLogSchemaJson>, Error> {
        let action_name = crate::client::path_segment(action_name);
        let path = format!("/audit_logs/actions/{action_name}/schemas");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Create Schema
    ///
    /// Creates a new Audit Log schema used to validate the payload of incoming Audit Log Events. If the `action` does not exist, it will also be created.
    pub async fn create_schema(
        &self,
        action_name: &str,
        params: CreateSchemaParams,
    ) -> Result<AuditLogSchemaJson, Error> {
        self.create_schema_with_options(action_name, params, None)
            .await
    }

    /// Variant of [`Self::create_schema`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_schema_with_options(
        &self,
        action_name: &str,
        params: CreateSchemaParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogSchemaJson, Error> {
        let action_name = crate::client::path_segment(action_name);
        let path = format!("/audit_logs/actions/{action_name}/schemas");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Create Event
    ///
    /// Create an Audit Log Event.
    ///
    /// This API supports idempotency which guarantees that performing the same operation multiple times will have the same result as if the operation were performed only once. This is handy in situations where you may need to retry a request due to a failure or prevent accidental duplicate requests from creating more than one resource.
    ///
    /// To achieve idempotency, you can add `Idempotency-Key` request header to a Create Event request with a unique string as the value. Each subsequent request matching this unique string will return the same response. We suggest using [v4 UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier) for idempotency keys to avoid collisions.
    ///
    /// Idempotency keys expire after 24 hours. The API will generate a new response if you submit a request with an expired key.
    pub async fn create_event(
        &self,
        params: CreateEventParams,
    ) -> Result<AuditLogEventCreateResponse, Error> {
        self.create_event_with_options(params, None).await
    }

    /// Variant of [`Self::create_event`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_event_with_options(
        &self,
        params: CreateEventParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogEventCreateResponse, Error> {
        let path = "/audit_logs/events".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Create Export
    ///
    /// Create an Audit Log Export. Exports are scoped to a single organization within a specified date range.
    pub async fn create_export(
        &self,
        params: CreateExportParams,
    ) -> Result<AuditLogExportJson, Error> {
        self.create_export_with_options(params, None).await
    }

    /// Variant of [`Self::create_export`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_export_with_options(
        &self,
        params: CreateExportParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogExportJson, Error> {
        let path = "/audit_logs/exports".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Export
    ///
    /// Get an Audit Log Export. The URL will expire after 10 minutes. If the export is needed again at a later time, refetching the export will regenerate the URL.
    pub async fn get_export(&self, audit_log_export_id: &str) -> Result<AuditLogExportJson, Error> {
        self.get_export_with_options(audit_log_export_id, None)
            .await
    }

    /// Variant of [`Self::get_export`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_export_with_options(
        &self,
        audit_log_export_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<AuditLogExportJson, Error> {
        let audit_log_export_id = crate::client::path_segment(audit_log_export_id);
        let path = format!("/audit_logs/exports/{audit_log_export_id}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}