openfga_sdk/apis/
open_fga_api.rs

1/**
2 * rust SDK for OpenFGA
3 *
4 * API version: 0.1
5 * Website: https://openfga.dev
6 * Documentation: https://openfga.dev/docs
7 * Support: https://discord.gg/8naAwJfWN6
8 * License: [Apache-2.0](https://github.com/openfga/rust-sdk/blob/main/LICENSE)
9 *
10 * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11 */
12use reqwest;
13
14use super::{configuration, Error};
15use crate::apis::ResponseContent;
16
17/// struct for typed errors of method [`check`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum CheckError {
21    Status400(crate::models::ValidationErrorMessageResponse),
22    Status404(crate::models::PathUnknownErrorMessageResponse),
23    Status500(crate::models::InternalErrorMessageResponse),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`create_store`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateStoreError {
31    Status400(crate::models::ValidationErrorMessageResponse),
32    Status404(crate::models::PathUnknownErrorMessageResponse),
33    Status500(crate::models::InternalErrorMessageResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`delete_store`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteStoreError {
41    Status400(crate::models::ValidationErrorMessageResponse),
42    Status404(crate::models::PathUnknownErrorMessageResponse),
43    Status500(crate::models::InternalErrorMessageResponse),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`expand`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ExpandError {
51    Status400(crate::models::ValidationErrorMessageResponse),
52    Status404(crate::models::PathUnknownErrorMessageResponse),
53    Status500(crate::models::InternalErrorMessageResponse),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`get_store`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetStoreError {
61    Status400(crate::models::ValidationErrorMessageResponse),
62    Status404(crate::models::PathUnknownErrorMessageResponse),
63    Status500(crate::models::InternalErrorMessageResponse),
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`list_objects`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListObjectsError {
71    Status400(crate::models::ValidationErrorMessageResponse),
72    Status404(crate::models::PathUnknownErrorMessageResponse),
73    Status500(crate::models::InternalErrorMessageResponse),
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method [`list_stores`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum ListStoresError {
81    Status400(crate::models::ValidationErrorMessageResponse),
82    Status404(crate::models::PathUnknownErrorMessageResponse),
83    Status500(crate::models::InternalErrorMessageResponse),
84    UnknownValue(serde_json::Value),
85}
86
87/// struct for typed errors of method [`read`]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum ReadError {
91    Status400(crate::models::ValidationErrorMessageResponse),
92    Status404(crate::models::PathUnknownErrorMessageResponse),
93    Status500(crate::models::InternalErrorMessageResponse),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`read_assertions`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum ReadAssertionsError {
101    Status400(crate::models::ValidationErrorMessageResponse),
102    Status404(crate::models::PathUnknownErrorMessageResponse),
103    Status500(crate::models::InternalErrorMessageResponse),
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`read_authorization_model`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum ReadAuthorizationModelError {
111    Status400(crate::models::ValidationErrorMessageResponse),
112    Status404(crate::models::PathUnknownErrorMessageResponse),
113    Status500(crate::models::InternalErrorMessageResponse),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`read_authorization_models`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum ReadAuthorizationModelsError {
121    Status400(crate::models::ValidationErrorMessageResponse),
122    Status404(crate::models::PathUnknownErrorMessageResponse),
123    Status500(crate::models::InternalErrorMessageResponse),
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`read_changes`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum ReadChangesError {
131    Status400(crate::models::ValidationErrorMessageResponse),
132    Status404(crate::models::PathUnknownErrorMessageResponse),
133    Status500(crate::models::InternalErrorMessageResponse),
134    UnknownValue(serde_json::Value),
135}
136
137/// struct for typed errors of method [`write`]
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum WriteError {
141    Status400(crate::models::ValidationErrorMessageResponse),
142    Status404(crate::models::PathUnknownErrorMessageResponse),
143    Status500(crate::models::InternalErrorMessageResponse),
144    UnknownValue(serde_json::Value),
145}
146
147/// struct for typed errors of method [`write_assertions`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum WriteAssertionsError {
151    Status400(crate::models::ValidationErrorMessageResponse),
152    Status404(crate::models::PathUnknownErrorMessageResponse),
153    Status500(crate::models::InternalErrorMessageResponse),
154    UnknownValue(serde_json::Value),
155}
156
157/// struct for typed errors of method [`write_authorization_model`]
158#[derive(Debug, Clone, Serialize, Deserialize)]
159#[serde(untagged)]
160pub enum WriteAuthorizationModelError {
161    Status400(crate::models::ValidationErrorMessageResponse),
162    Status404(crate::models::PathUnknownErrorMessageResponse),
163    Status500(crate::models::InternalErrorMessageResponse),
164    UnknownValue(serde_json::Value),
165}
166
167/// The Check API queries to check if the user has a certain relationship with an object in a certain store. Path parameter `store_id` as well as the body parameter `tuple_key` with specified `object`, `relation` and `user` subfields are all required. Optionally, a `contextual_tuples` object may also be included in the body of the request. This object contains one field `tuple_keys`, which is an array of tuple keys. The response will return whether the relationship exists in the field `allowed`.  ## Example In order to check if user `anne` of type `user` has a `can_read` relationship with object `document:2021-budget` given the following contextual tuple ```json {   \"user\": \"user:anne\",   \"relation\": \"member\",   \"object\": \"time_slot:office_hours\" } ``` a check API call should be fired with the following body: ```json {   \"tuple_key\": {     \"user\": \"user:anne\",     \"relation\": \"can_read\",     \"object\": \"document:2021-budget\"   },   \"contextual_tuples\": {     \"tuple_keys\": [       {         \"user\": \"user:anne\",         \"relation\": \"member\",         \"object\": \"time_slot:office_hours\"       }     ]   } } ``` OpenFGA's response will include `{ \"allowed\": true }` if there is a relationship and `{ \"allowed\": false }` if there isn't.
168pub async fn check(
169    configuration: &configuration::Configuration,
170    store_id: &str,
171    body: crate::models::CheckRequest,
172) -> Result<crate::models::CheckResponse, Error<CheckError>> {
173    let local_var_configuration = configuration;
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!(
178        "{}/stores/{store_id}/check",
179        local_var_configuration.base_path,
180        store_id = crate::apis::urlencode(store_id)
181    );
182    let mut local_var_req_builder =
183        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
184
185    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
186        local_var_req_builder =
187            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
188    }
189    local_var_req_builder = local_var_req_builder.json(&body);
190
191    let local_var_req = local_var_req_builder.build()?;
192    let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194    let local_var_status = local_var_resp.status();
195    let local_var_content = local_var_resp.text().await?;
196
197    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198        serde_json::from_str(&local_var_content).map_err(Error::from)
199    } else {
200        let local_var_entity: Option<CheckError> = serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent {
202            status: local_var_status,
203            content: local_var_content,
204            entity: local_var_entity,
205        };
206        Err(Error::ResponseError(local_var_error))
207    }
208}
209
210/// Create a unique OpenFGA store which will be used to store authorization models and relationship tuples.
211pub async fn create_store(
212    configuration: &configuration::Configuration,
213    body: crate::models::CreateStoreRequest,
214) -> Result<crate::models::CreateStoreResponse, Error<CreateStoreError>> {
215    let local_var_configuration = configuration;
216
217    let local_var_client = &local_var_configuration.client;
218
219    let local_var_uri_str = format!("{}/stores", local_var_configuration.base_path);
220    let mut local_var_req_builder =
221        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
222
223    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
224        local_var_req_builder =
225            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227    local_var_req_builder = local_var_req_builder.json(&body);
228
229    let local_var_req = local_var_req_builder.build()?;
230    let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232    let local_var_status = local_var_resp.status();
233    let local_var_content = local_var_resp.text().await?;
234
235    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236        serde_json::from_str(&local_var_content).map_err(Error::from)
237    } else {
238        let local_var_entity: Option<CreateStoreError> =
239            serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent {
241            status: local_var_status,
242            content: local_var_content,
243            entity: local_var_entity,
244        };
245        Err(Error::ResponseError(local_var_error))
246    }
247}
248
249/// Delete an OpenFGA store. This does not delete the data associated to it, like tuples or authorization models.
250pub async fn delete_store(
251    configuration: &configuration::Configuration,
252    store_id: &str,
253) -> Result<(), Error<DeleteStoreError>> {
254    let local_var_configuration = configuration;
255
256    let local_var_client = &local_var_configuration.client;
257
258    let local_var_uri_str = format!(
259        "{}/stores/{store_id}",
260        local_var_configuration.base_path,
261        store_id = crate::apis::urlencode(store_id)
262    );
263    let mut local_var_req_builder =
264        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
265
266    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267        local_var_req_builder =
268            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
269    }
270
271    let local_var_req = local_var_req_builder.build()?;
272    let local_var_resp = local_var_client.execute(local_var_req).await?;
273
274    let local_var_status = local_var_resp.status();
275    let local_var_content = local_var_resp.text().await?;
276
277    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
278        Ok(())
279    } else {
280        let local_var_entity: Option<DeleteStoreError> =
281            serde_json::from_str(&local_var_content).ok();
282        let local_var_error = ResponseContent {
283            status: local_var_status,
284            content: local_var_content,
285            entity: local_var_entity,
286        };
287        Err(Error::ResponseError(local_var_error))
288    }
289}
290
291/// The Expand API will return all users (including user and userset) that have certain relationship with an object in a certain store. This is different from the `/stores/{store_id}/read` API in that both users and computed references are returned. Path parameter `store_id` as well as body parameter `object`, `relation` are all required. The response will return a userset tree whose leaves are the user id and usersets.  Union, intersection and difference operator are located in the intermediate nodes.  ## Example Assume the following type definition for document: ```yaml   type document     relations       define reader as self or writer       define writer as self ``` In order to expand all users that have `reader` relationship with object `document:2021-budget`, an expand API call should be fired with the following body ```json {   \"tuple_key\": {     \"object\": \"document:2021-budget\",     \"relation\": \"reader\"   } } ``` OpenFGA's response will be a userset tree of the users and computed usersets that have read access to the document. ```json {   \"tree\":{     \"root\":{       \"type\":\"document:2021-budget#reader\",       \"union\":{         \"nodes\":[           {             \"type\":\"document:2021-budget#reader\",             \"leaf\":{               \"users\":{                 \"users\":[                   \"user:bob\"                 ]               }             }           },           {             \"type\":\"document:2021-budget#reader\",             \"leaf\":{               \"computed\":{                 \"userset\":\"document:2021-budget#writer\"               }             }           }         ]       }     }   } } ``` The caller can then call expand API for the `writer` relationship for the `document:2021-budget`.
292pub async fn expand(
293    configuration: &configuration::Configuration,
294    store_id: &str,
295    body: crate::models::ExpandRequest,
296) -> Result<crate::models::ExpandResponse, Error<ExpandError>> {
297    let local_var_configuration = configuration;
298
299    let local_var_client = &local_var_configuration.client;
300
301    let local_var_uri_str = format!(
302        "{}/stores/{store_id}/expand",
303        local_var_configuration.base_path,
304        store_id = crate::apis::urlencode(store_id)
305    );
306    let mut local_var_req_builder =
307        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
308
309    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
310        local_var_req_builder =
311            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
312    }
313    local_var_req_builder = local_var_req_builder.json(&body);
314
315    let local_var_req = local_var_req_builder.build()?;
316    let local_var_resp = local_var_client.execute(local_var_req).await?;
317
318    let local_var_status = local_var_resp.status();
319    let local_var_content = local_var_resp.text().await?;
320
321    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
322        serde_json::from_str(&local_var_content).map_err(Error::from)
323    } else {
324        let local_var_entity: Option<ExpandError> = serde_json::from_str(&local_var_content).ok();
325        let local_var_error = ResponseContent {
326            status: local_var_status,
327            content: local_var_content,
328            entity: local_var_entity,
329        };
330        Err(Error::ResponseError(local_var_error))
331    }
332}
333
334/// Returns an OpenFGA store.
335pub async fn get_store(
336    configuration: &configuration::Configuration,
337    store_id: &str,
338) -> Result<crate::models::GetStoreResponse, Error<GetStoreError>> {
339    let local_var_configuration = configuration;
340
341    let local_var_client = &local_var_configuration.client;
342
343    let local_var_uri_str = format!(
344        "{}/stores/{store_id}",
345        local_var_configuration.base_path,
346        store_id = crate::apis::urlencode(store_id)
347    );
348    let mut local_var_req_builder =
349        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
350
351    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
352        local_var_req_builder =
353            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
354    }
355
356    let local_var_req = local_var_req_builder.build()?;
357    let local_var_resp = local_var_client.execute(local_var_req).await?;
358
359    let local_var_status = local_var_resp.status();
360    let local_var_content = local_var_resp.text().await?;
361
362    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
363        serde_json::from_str(&local_var_content).map_err(Error::from)
364    } else {
365        let local_var_entity: Option<GetStoreError> = serde_json::from_str(&local_var_content).ok();
366        let local_var_error = ResponseContent {
367            status: local_var_status,
368            content: local_var_content,
369            entity: local_var_entity,
370        };
371        Err(Error::ResponseError(local_var_error))
372    }
373}
374
375pub async fn list_objects(
376    configuration: &configuration::Configuration,
377    store_id: &str,
378    body: crate::models::ListObjectsRequest,
379) -> Result<crate::models::ListObjectsResponse, Error<ListObjectsError>> {
380    let local_var_configuration = configuration;
381
382    let local_var_client = &local_var_configuration.client;
383
384    let local_var_uri_str = format!(
385        "{}/stores/{store_id}/list-objects",
386        local_var_configuration.base_path,
387        store_id = crate::apis::urlencode(store_id)
388    );
389    let mut local_var_req_builder =
390        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
391
392    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
393        local_var_req_builder =
394            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
395    }
396    local_var_req_builder = local_var_req_builder.json(&body);
397
398    let local_var_req = local_var_req_builder.build()?;
399    let local_var_resp = local_var_client.execute(local_var_req).await?;
400
401    let local_var_status = local_var_resp.status();
402    let local_var_content = local_var_resp.text().await?;
403
404    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
405        serde_json::from_str(&local_var_content).map_err(Error::from)
406    } else {
407        let local_var_entity: Option<ListObjectsError> =
408            serde_json::from_str(&local_var_content).ok();
409        let local_var_error = ResponseContent {
410            status: local_var_status,
411            content: local_var_content,
412            entity: local_var_entity,
413        };
414        Err(Error::ResponseError(local_var_error))
415    }
416}
417
418/// Returns a paginated list of OpenFGA stores.
419pub async fn list_stores(
420    configuration: &configuration::Configuration,
421    page_size: Option<i32>,
422    continuation_token: Option<&str>,
423) -> Result<crate::models::ListStoresResponse, Error<ListStoresError>> {
424    let local_var_configuration = configuration;
425
426    let local_var_client = &local_var_configuration.client;
427
428    let local_var_uri_str = format!("{}/stores", local_var_configuration.base_path);
429    let mut local_var_req_builder =
430        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
431
432    if let Some(ref local_var_str) = page_size {
433        local_var_req_builder =
434            local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
435    }
436    if let Some(ref local_var_str) = continuation_token {
437        local_var_req_builder =
438            local_var_req_builder.query(&[("continuation_token", &local_var_str.to_string())]);
439    }
440    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
441        local_var_req_builder =
442            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
443    }
444
445    let local_var_req = local_var_req_builder.build()?;
446    let local_var_resp = local_var_client.execute(local_var_req).await?;
447
448    let local_var_status = local_var_resp.status();
449    let local_var_content = local_var_resp.text().await?;
450
451    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
452        serde_json::from_str(&local_var_content).map_err(Error::from)
453    } else {
454        let local_var_entity: Option<ListStoresError> =
455            serde_json::from_str(&local_var_content).ok();
456        let local_var_error = ResponseContent {
457            status: local_var_status,
458            content: local_var_content,
459            entity: local_var_entity,
460        };
461        Err(Error::ResponseError(local_var_error))
462    }
463}
464
465/// The POST read API will return the tuples for a certain store that matches a query filter specified in the body. Tuples and type definitions allow OpenFGA to determine whether a relationship exists between an object and an user. It is different from the `/stores/{store_id}/expand` API in that only read returns relationship tuples that are stored in the system and satisfy the query. It does not expand or traverse the graph by taking the authorization model into account.Path parameter `store_id` is required.  In the body: 1. Object is mandatory. An object can be a full object (e.g., `type:object_id`) or type only (e.g., `type:`). 2. User is mandatory in the case the object is type only. ## Examples ### Query for all objects in a type definition To query for all objects that `bob` has `reader` relationship in the document type definition, call read API with body of ```json {  \"tuple_key\": {      \"user\": \"user:bob\",      \"relation\": \"reader\",      \"object\": \"document:\"   } } ``` The API will return tuples and an optional continuation token, something like ```json {   \"tuples\": [     {       \"key\": {         \"user\": \"user:bob\",         \"relation\": \"reader\",         \"object\": \"document:2021-budget\"       },       \"timestamp\": \"2021-10-06T15:32:11.128Z\"     }   ] } ``` This means that `bob` has a `reader` relationship with 1 document `document:2021-budget`. ### Query for all users with particular relationships for a particular document To query for all users that have `reader` relationship with `document:2021-budget`, call read API with body of  ```json {   \"tuple_key\": {      \"object\": \"document:2021-budget\",      \"relation\": \"reader\"    } } ``` The API will return something like  ```json {   \"tuples\": [     {       \"key\": {         \"user\": \"user:bob\",         \"relation\": \"reader\",         \"object\": \"document:2021-budget\"       },       \"timestamp\": \"2021-10-06T15:32:11.128Z\"     }   ] } ``` This means that `document:2021-budget` has 1 `reader` (`bob`).  Note that the API will not return writers such as `anne` even when all writers are readers.  This is because only direct relationship are returned for the READ API. ### Query for all users with all relationships for a particular document To query for all users that have any relationship with `document:2021-budget`, call read API with body of  ```json {   \"tuple_key\": {       \"object\": \"document:2021-budget\"    } } ``` The API will return something like  ```json {   \"tuples\": [     {       \"key\": {         \"user\": \"user:anne\",         \"relation\": \"writer\",         \"object\": \"document:2021-budget\"       },       \"timestamp\": \"2021-10-05T13:42:12.356Z\"     },     {       \"key\": {         \"user\": \"user:bob\",         \"relation\": \"reader\",         \"object\": \"document:2021-budget\"       },       \"timestamp\": \"2021-10-06T15:32:11.128Z\"     }   ] } ``` This means that `document:2021-budget` has 1 `reader` (`user:bob`) and 1 `writer` (`user:anne`).
466pub async fn read(
467    configuration: &configuration::Configuration,
468    store_id: &str,
469    body: crate::models::ReadRequest,
470) -> Result<crate::models::ReadResponse, Error<ReadError>> {
471    let local_var_configuration = configuration;
472
473    let local_var_client = &local_var_configuration.client;
474
475    let local_var_uri_str = format!(
476        "{}/stores/{store_id}/read",
477        local_var_configuration.base_path,
478        store_id = crate::apis::urlencode(store_id)
479    );
480    let mut local_var_req_builder =
481        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
482
483    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
484        local_var_req_builder =
485            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
486    }
487    local_var_req_builder = local_var_req_builder.json(&body);
488
489    let local_var_req = local_var_req_builder.build()?;
490    let local_var_resp = local_var_client.execute(local_var_req).await?;
491
492    let local_var_status = local_var_resp.status();
493    let local_var_content = local_var_resp.text().await?;
494
495    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
496        serde_json::from_str(&local_var_content).map_err(Error::from)
497    } else {
498        let local_var_entity: Option<ReadError> = serde_json::from_str(&local_var_content).ok();
499        let local_var_error = ResponseContent {
500            status: local_var_status,
501            content: local_var_content,
502            entity: local_var_entity,
503        };
504        Err(Error::ResponseError(local_var_error))
505    }
506}
507
508/// The GET assertions API will return, for a given authorization model id, all the assertions stored for it. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
509pub async fn read_assertions(
510    configuration: &configuration::Configuration,
511    store_id: &str,
512    authorization_model_id: &str,
513) -> Result<crate::models::ReadAssertionsResponse, Error<ReadAssertionsError>> {
514    let local_var_configuration = configuration;
515
516    let local_var_client = &local_var_configuration.client;
517
518    let local_var_uri_str = format!(
519        "{}/stores/{store_id}/assertions/{authorization_model_id}",
520        local_var_configuration.base_path,
521        store_id = crate::apis::urlencode(store_id),
522        authorization_model_id = crate::apis::urlencode(authorization_model_id)
523    );
524    let mut local_var_req_builder =
525        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
526
527    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
528        local_var_req_builder =
529            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
530    }
531
532    let local_var_req = local_var_req_builder.build()?;
533    let local_var_resp = local_var_client.execute(local_var_req).await?;
534
535    let local_var_status = local_var_resp.status();
536    let local_var_content = local_var_resp.text().await?;
537
538    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
539        serde_json::from_str(&local_var_content).map_err(Error::from)
540    } else {
541        let local_var_entity: Option<ReadAssertionsError> =
542            serde_json::from_str(&local_var_content).ok();
543        let local_var_error = ResponseContent {
544            status: local_var_status,
545            content: local_var_content,
546            entity: local_var_entity,
547        };
548        Err(Error::ResponseError(local_var_error))
549    }
550}
551
552/// The GET authorization-models by ID API will return a particular version of authorization model that had been configured for a certain store.   Path parameter `store_id` and `id` are required. The response will return the authorization model for the particular version.  ## Example To retrieve the authorization model with ID `01G5JAVJ41T49E9TT3SKVS7X1J` for the store, call the GET authorization-models by ID API with `01G5JAVJ41T49E9TT3SKVS7X1J` as the `id` path parameter.  The API will return: ```json {   \"authorization_model\":{     \"id\":\"01G5JAVJ41T49E9TT3SKVS7X1J\",     \"type_definitions\":[       {         \"type\":\"document\",         \"relations\":{           \"reader\":{             \"union\":{               \"child\":[                 {                   \"this\":{}                 },                 {                   \"computedUserset\":{                     \"object\":\"\",                     \"relation\":\"writer\"                   }                 }               ]             }           },           \"writer\":{             \"this\":{}           }         }       }     ]   } } ``` In the above example, there is only 1 type (`document`) with 2 relations (`writer` and `reader`).
553pub async fn read_authorization_model(
554    configuration: &configuration::Configuration,
555    store_id: &str,
556    id: &str,
557) -> Result<crate::models::ReadAuthorizationModelResponse, Error<ReadAuthorizationModelError>> {
558    let local_var_configuration = configuration;
559
560    let local_var_client = &local_var_configuration.client;
561
562    let local_var_uri_str = format!(
563        "{}/stores/{store_id}/authorization-models/{id}",
564        local_var_configuration.base_path,
565        store_id = crate::apis::urlencode(store_id),
566        id = crate::apis::urlencode(id)
567    );
568    let mut local_var_req_builder =
569        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
570
571    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
572        local_var_req_builder =
573            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
574    }
575
576    let local_var_req = local_var_req_builder.build()?;
577    let local_var_resp = local_var_client.execute(local_var_req).await?;
578
579    let local_var_status = local_var_resp.status();
580    let local_var_content = local_var_resp.text().await?;
581
582    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
583        serde_json::from_str(&local_var_content).map_err(Error::from)
584    } else {
585        let local_var_entity: Option<ReadAuthorizationModelError> =
586            serde_json::from_str(&local_var_content).ok();
587        let local_var_error = ResponseContent {
588            status: local_var_status,
589            content: local_var_content,
590            entity: local_var_entity,
591        };
592        Err(Error::ResponseError(local_var_error))
593    }
594}
595
596/// The GET authorization-models API will return all the authorization models for a certain store. Path parameter `store_id` is required. OpenFGA's response will contain an array of all authorization models, sorted in descending order of creation.  ## Example Assume that a store's authorization model has been configured twice. To get all the authorization models that have been created in this store, call GET authorization-models. The API will return a response that looks like: ```json {   \"authorization_models\": [     {       \"id\": \"01G50QVV17PECNVAHX1GG4Y5NC\",       \"type_definitions\": [...]     },     {       \"id\": \"01G4ZW8F4A07AKQ8RHSVG9RW04\",       \"type_definitions\": [...]     },   ] } ``` If there are more authorization models available, the response will contain an extra field `continuation_token`: ```json {   \"authorization_models\": [     {       \"id\": \"01G50QVV17PECNVAHX1GG4Y5NC\",       \"type_definitions\": [...]     },     {       \"id\": \"01G4ZW8F4A07AKQ8RHSVG9RW04\",       \"type_definitions\": [...]     },   ],   \"continuation_token\": \"eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==\" } ```
597pub async fn read_authorization_models(
598    configuration: &configuration::Configuration,
599    store_id: &str,
600    page_size: Option<i32>,
601    continuation_token: Option<&str>,
602) -> Result<crate::models::ReadAuthorizationModelsResponse, Error<ReadAuthorizationModelsError>> {
603    let local_var_configuration = configuration;
604
605    let local_var_client = &local_var_configuration.client;
606
607    let local_var_uri_str = format!(
608        "{}/stores/{store_id}/authorization-models",
609        local_var_configuration.base_path,
610        store_id = crate::apis::urlencode(store_id)
611    );
612    let mut local_var_req_builder =
613        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
614
615    if let Some(ref local_var_str) = page_size {
616        local_var_req_builder =
617            local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
618    }
619    if let Some(ref local_var_str) = continuation_token {
620        local_var_req_builder =
621            local_var_req_builder.query(&[("continuation_token", &local_var_str.to_string())]);
622    }
623    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
624        local_var_req_builder =
625            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
626    }
627
628    let local_var_req = local_var_req_builder.build()?;
629    let local_var_resp = local_var_client.execute(local_var_req).await?;
630
631    let local_var_status = local_var_resp.status();
632    let local_var_content = local_var_resp.text().await?;
633
634    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
635        serde_json::from_str(&local_var_content).map_err(Error::from)
636    } else {
637        let local_var_entity: Option<ReadAuthorizationModelsError> =
638            serde_json::from_str(&local_var_content).ok();
639        let local_var_error = ResponseContent {
640            status: local_var_status,
641            content: local_var_content,
642            entity: local_var_entity,
643        };
644        Err(Error::ResponseError(local_var_error))
645    }
646}
647
648/// The GET changes API will return a paginated list of tuple changes (additions and deletions) that occurred in a given store, sorted by ascending time. The response will include a continuation token that is used to get the next set of changes. If there are no changes after the provided continuation token, the same token will be returned in order for it to be used when new changes are recorded. If the store never had any tuples added or removed, this token will be empty. You can use the `type` parameter to only get the list of tuple changes that affect objects of that type.
649pub async fn read_changes(
650    configuration: &configuration::Configuration,
651    store_id: &str,
652    _type: Option<&str>,
653    page_size: Option<i32>,
654    continuation_token: Option<&str>,
655) -> Result<crate::models::ReadChangesResponse, Error<ReadChangesError>> {
656    let local_var_configuration = configuration;
657
658    let local_var_client = &local_var_configuration.client;
659
660    let local_var_uri_str = format!(
661        "{}/stores/{store_id}/changes",
662        local_var_configuration.base_path,
663        store_id = crate::apis::urlencode(store_id)
664    );
665    let mut local_var_req_builder =
666        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
667
668    if let Some(ref local_var_str) = _type {
669        local_var_req_builder =
670            local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
671    }
672    if let Some(ref local_var_str) = page_size {
673        local_var_req_builder =
674            local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
675    }
676    if let Some(ref local_var_str) = continuation_token {
677        local_var_req_builder =
678            local_var_req_builder.query(&[("continuation_token", &local_var_str.to_string())]);
679    }
680    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
681        local_var_req_builder =
682            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
683    }
684
685    let local_var_req = local_var_req_builder.build()?;
686    let local_var_resp = local_var_client.execute(local_var_req).await?;
687
688    let local_var_status = local_var_resp.status();
689    let local_var_content = local_var_resp.text().await?;
690
691    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
692        serde_json::from_str(&local_var_content).map_err(Error::from)
693    } else {
694        let local_var_entity: Option<ReadChangesError> =
695            serde_json::from_str(&local_var_content).ok();
696        let local_var_error = ResponseContent {
697            status: local_var_status,
698            content: local_var_content,
699            entity: local_var_entity,
700        };
701        Err(Error::ResponseError(local_var_error))
702    }
703}
704
705/// The POST write API will update the tuples for a certain store.  Tuples and type definitions allow OpenFGA to determine whether a relationship exists between an object and an user. Path parameter `store_id` is required.  In the body, `writes` adds new tuples while `deletes` removes existing tuples. ## Example ### Adding relationships To add `user:anne` as a `writer` for `document:2021-budget`, call write API with the following  ```json {   \"writes\": {     \"tuple_keys\": [       {         \"user\": \"user:anne\",         \"relation\": \"writer\",         \"object\": \"document:2021-budget\"       }     ]   } } ``` ### Removing relationships To remove `user:bob` as a `reader` for `document:2021-budget`, call write API with the following  ```json {   \"deletes\": {     \"tuple_keys\": [       {         \"user\": \"user:bob\",         \"relation\": \"reader\",         \"object\": \"document:2021-budget\"       }     ]   } } ```
706pub async fn write(
707    configuration: &configuration::Configuration,
708    store_id: &str,
709    body: crate::models::WriteRequest,
710) -> Result<serde_json::Value, Error<WriteError>> {
711    let local_var_configuration = configuration;
712
713    let local_var_client = &local_var_configuration.client;
714
715    let local_var_uri_str = format!(
716        "{}/stores/{store_id}/write",
717        local_var_configuration.base_path,
718        store_id = crate::apis::urlencode(store_id)
719    );
720    let mut local_var_req_builder =
721        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
722
723    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
724        local_var_req_builder =
725            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
726    }
727    local_var_req_builder = local_var_req_builder.json(&body);
728
729    let local_var_req = local_var_req_builder.build()?;
730    let local_var_resp = local_var_client.execute(local_var_req).await?;
731
732    let local_var_status = local_var_resp.status();
733    let local_var_content = local_var_resp.text().await?;
734
735    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
736        serde_json::from_str(&local_var_content).map_err(Error::from)
737    } else {
738        let local_var_entity: Option<WriteError> = serde_json::from_str(&local_var_content).ok();
739        let local_var_error = ResponseContent {
740            status: local_var_status,
741            content: local_var_content,
742            entity: local_var_entity,
743        };
744        Err(Error::ResponseError(local_var_error))
745    }
746}
747
748/// The Write Assertions API will add new assertions for an authorization model id, or overwrite the existing ones. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
749pub async fn write_assertions(
750    configuration: &configuration::Configuration,
751    store_id: &str,
752    authorization_model_id: &str,
753    body: crate::models::WriteAssertionsRequest,
754) -> Result<(), Error<WriteAssertionsError>> {
755    let local_var_configuration = configuration;
756
757    let local_var_client = &local_var_configuration.client;
758
759    let local_var_uri_str = format!(
760        "{}/stores/{store_id}/assertions/{authorization_model_id}",
761        local_var_configuration.base_path,
762        store_id = crate::apis::urlencode(store_id),
763        authorization_model_id = crate::apis::urlencode(authorization_model_id)
764    );
765    let mut local_var_req_builder =
766        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
767
768    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
769        local_var_req_builder =
770            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
771    }
772    local_var_req_builder = local_var_req_builder.json(&body);
773
774    let local_var_req = local_var_req_builder.build()?;
775    let local_var_resp = local_var_client.execute(local_var_req).await?;
776
777    let local_var_status = local_var_resp.status();
778    let local_var_content = local_var_resp.text().await?;
779
780    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
781        Ok(())
782    } else {
783        let local_var_entity: Option<WriteAssertionsError> =
784            serde_json::from_str(&local_var_content).ok();
785        let local_var_error = ResponseContent {
786            status: local_var_status,
787            content: local_var_content,
788            entity: local_var_entity,
789        };
790        Err(Error::ResponseError(local_var_error))
791    }
792}
793
794/// The POST authorization-model API will update the authorization model for a certain store. Path parameter `store_id` and `type_definitions` array in the body are required.  Each item in the `type_definitions` array is a type definition as specified in the field `type_definition`. The response will return the authorization model's ID in the `id` field.  ## Example To update the authorization model with a single `document` authorization model, call POST authorization-models API with the body:  ```json {   \"type_definitions\":[     {       \"type\":\"document\",       \"relations\":{         \"reader\":{           \"union\":{             \"child\":[               {                 \"this\":{}               },               {                 \"computedUserset\":{                   \"object\":\"\",                   \"relation\":\"writer\"                 }               }             ]           }         },         \"writer\":{           \"this\":{}         }       }     }   ] } ``` OpenFGA's response will include the version id for this authorization model, which will look like  ``` {\"authorization_model_id\": \"01G50QVV17PECNVAHX1GG4Y5NC\"} ```
795pub async fn write_authorization_model(
796    configuration: &configuration::Configuration,
797    store_id: &str,
798    body: crate::models::WriteAuthorizationModelRequest,
799) -> Result<crate::models::WriteAuthorizationModelResponse, Error<WriteAuthorizationModelError>> {
800    let local_var_configuration = configuration;
801
802    let local_var_client = &local_var_configuration.client;
803
804    let local_var_uri_str = format!(
805        "{}/stores/{store_id}/authorization-models",
806        local_var_configuration.base_path,
807        store_id = crate::apis::urlencode(store_id)
808    );
809    let mut local_var_req_builder =
810        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
811
812    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
813        local_var_req_builder =
814            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
815    }
816    local_var_req_builder = local_var_req_builder.json(&body);
817
818    let local_var_req = local_var_req_builder.build()?;
819    let local_var_resp = local_var_client.execute(local_var_req).await?;
820
821    let local_var_status = local_var_resp.status();
822    let local_var_content = local_var_resp.text().await?;
823
824    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
825        serde_json::from_str(&local_var_content).map_err(Error::from)
826    } else {
827        let local_var_entity: Option<WriteAuthorizationModelError> =
828            serde_json::from_str(&local_var_content).ok();
829        let local_var_error = ResponseContent {
830            status: local_var_status,
831            content: local_var_content,
832            entity: local_var_entity,
833        };
834        Err(Error::ResponseError(local_var_error))
835    }
836}