openfga 1.0.2

Rust SDK for OpenFGA — the open-source authorization system
Documentation
/*
 * OpenFGA
 *
 * A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
 *
 * The version of the OpenAPI document: 1.x
 * Contact: community@openfga.dev
 * Generated by: https://openapi-generator.tech
 */

use super::{Error, configuration, parse_empty_response, parse_response};
use crate::models;
use serde::{Deserialize, Serialize};

/// struct for typed errors of method [`read_assertions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReadAssertionsError {
    Status400(models::ValidationErrorMessageResponse),
    Status401(models::UnauthenticatedResponse),
    Status403(models::ForbiddenResponse),
    Status404(models::PathUnknownErrorMessageResponse),
    Status409(models::AbortedMessageResponse),
    Status422(models::UnprocessableContentMessageResponse),
    Status500(models::InternalErrorMessageResponse),
}

/// struct for typed errors of method [`write_assertions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WriteAssertionsError {
    Status400(models::ValidationErrorMessageResponse),
    Status401(models::UnauthenticatedResponse),
    Status403(models::ForbiddenResponse),
    Status404(models::PathUnknownErrorMessageResponse),
    Status409(models::AbortedMessageResponse),
    Status422(models::UnprocessableContentMessageResponse),
    Status500(models::InternalErrorMessageResponse),
}

/// The ReadAssertions API will return, for a given authorization model id, all the assertions stored for it.
pub async fn read_assertions(
    configuration: &configuration::Configuration,
    store_id: &str,
    authorization_model_id: &str,
) -> Result<models::ReadAssertionsResponse, Error<ReadAssertionsError>> {
    let uri_str = format!(
        "{}/stores/{store_id}/assertions/{authorization_model_id}",
        configuration.base_path,
        store_id = crate::apis::urlencode(store_id),
        authorization_model_id = crate::apis::urlencode(authorization_model_id)
    );
    let req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
    let req_builder = configuration.apply_to_request(req_builder);
    let resp = req_builder.send().await?;
    parse_response(resp).await
}

/// The WriteAssertions API will upsert new assertions for an authorization model id, or overwrite the existing ones. An assertion is an object that contains a tuple key, the expectation of whether a call to the Check API of that tuple key will return true or false, and optionally a list of contextual tuples.
pub async fn write_assertions(
    configuration: &configuration::Configuration,
    store_id: &str,
    authorization_model_id: &str,
    body: models::WriteAssertionsRequest,
) -> Result<(), Error<WriteAssertionsError>> {
    let uri_str = format!(
        "{}/stores/{store_id}/assertions/{authorization_model_id}",
        configuration.base_path,
        store_id = crate::apis::urlencode(store_id),
        authorization_model_id = crate::apis::urlencode(authorization_model_id)
    );
    let req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
    let req_builder = configuration.apply_to_request(req_builder);
    let req_builder = req_builder.json(&body);
    let resp = req_builder.send().await?;
    parse_empty_response(resp).await
}