ory_client/apis/
relationship_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.17.2
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`check_opl_syntax`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CheckOplSyntaxError {
22    Status400(models::ErrorGeneric),
23    DefaultResponse(models::ErrorGeneric),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`create_relationship`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum CreateRelationshipError {
31    Status400(models::ErrorGeneric),
32    DefaultResponse(models::ErrorGeneric),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`delete_relationships`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum DeleteRelationshipsError {
40    Status400(models::ErrorGeneric),
41    DefaultResponse(models::ErrorGeneric),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`get_relationships`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetRelationshipsError {
49    Status404(models::ErrorGeneric),
50    DefaultResponse(models::ErrorGeneric),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`list_relationship_namespaces`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ListRelationshipNamespacesError {
58    DefaultResponse(models::ErrorGeneric),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`patch_relationships`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum PatchRelationshipsError {
66    Status400(models::ErrorGeneric),
67    Status404(models::ErrorGeneric),
68    DefaultResponse(models::ErrorGeneric),
69    UnknownValue(serde_json::Value),
70}
71
72
73/// The OPL file is expected in the body of the request.
74pub async fn check_opl_syntax(configuration: &configuration::Configuration, body: Option<&str>) -> Result<models::CheckOplSyntaxResult, Error<CheckOplSyntaxError>> {
75    let local_var_configuration = configuration;
76
77    let local_var_client = &local_var_configuration.client;
78
79    let local_var_uri_str = format!("{}/opl/syntax/check", local_var_configuration.base_path);
80    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
81
82    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
83        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
84    }
85    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
86        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
87    };
88    local_var_req_builder = local_var_req_builder.json(&body);
89
90    let local_var_req = local_var_req_builder.build()?;
91    let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93    let local_var_status = local_var_resp.status();
94    let local_var_content = local_var_resp.text().await?;
95
96    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97        serde_json::from_str(&local_var_content).map_err(Error::from)
98    } else {
99        let local_var_entity: Option<CheckOplSyntaxError> = serde_json::from_str(&local_var_content).ok();
100        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
101        Err(Error::ResponseError(local_var_error))
102    }
103}
104
105/// Use this endpoint to create a relationship.
106pub async fn create_relationship(configuration: &configuration::Configuration, create_relationship_body: Option<models::CreateRelationshipBody>) -> Result<models::Relationship, Error<CreateRelationshipError>> {
107    let local_var_configuration = configuration;
108
109    let local_var_client = &local_var_configuration.client;
110
111    let local_var_uri_str = format!("{}/admin/relation-tuples", local_var_configuration.base_path);
112    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
113
114    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
116    }
117    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
118        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
119    };
120    local_var_req_builder = local_var_req_builder.json(&create_relationship_body);
121
122    let local_var_req = local_var_req_builder.build()?;
123    let local_var_resp = local_var_client.execute(local_var_req).await?;
124
125    let local_var_status = local_var_resp.status();
126    let local_var_content = local_var_resp.text().await?;
127
128    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129        serde_json::from_str(&local_var_content).map_err(Error::from)
130    } else {
131        let local_var_entity: Option<CreateRelationshipError> = serde_json::from_str(&local_var_content).ok();
132        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
133        Err(Error::ResponseError(local_var_error))
134    }
135}
136
137/// Use this endpoint to delete relationships
138pub async fn delete_relationships(configuration: &configuration::Configuration, namespace: Option<&str>, object: Option<&str>, relation: Option<&str>, subject_id: Option<&str>, subject_set_period_namespace: Option<&str>, subject_set_period_object: Option<&str>, subject_set_period_relation: Option<&str>) -> Result<(), Error<DeleteRelationshipsError>> {
139    let local_var_configuration = configuration;
140
141    let local_var_client = &local_var_configuration.client;
142
143    let local_var_uri_str = format!("{}/admin/relation-tuples", local_var_configuration.base_path);
144    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
145
146    if let Some(ref local_var_str) = namespace {
147        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
148    }
149    if let Some(ref local_var_str) = object {
150        local_var_req_builder = local_var_req_builder.query(&[("object", &local_var_str.to_string())]);
151    }
152    if let Some(ref local_var_str) = relation {
153        local_var_req_builder = local_var_req_builder.query(&[("relation", &local_var_str.to_string())]);
154    }
155    if let Some(ref local_var_str) = subject_id {
156        local_var_req_builder = local_var_req_builder.query(&[("subject_id", &local_var_str.to_string())]);
157    }
158    if let Some(ref local_var_str) = subject_set_period_namespace {
159        local_var_req_builder = local_var_req_builder.query(&[("subject_set.namespace", &local_var_str.to_string())]);
160    }
161    if let Some(ref local_var_str) = subject_set_period_object {
162        local_var_req_builder = local_var_req_builder.query(&[("subject_set.object", &local_var_str.to_string())]);
163    }
164    if let Some(ref local_var_str) = subject_set_period_relation {
165        local_var_req_builder = local_var_req_builder.query(&[("subject_set.relation", &local_var_str.to_string())]);
166    }
167    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169    }
170    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
171        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
172    };
173
174    let local_var_req = local_var_req_builder.build()?;
175    let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177    let local_var_status = local_var_resp.status();
178    let local_var_content = local_var_resp.text().await?;
179
180    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181        Ok(())
182    } else {
183        let local_var_entity: Option<DeleteRelationshipsError> = serde_json::from_str(&local_var_content).ok();
184        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185        Err(Error::ResponseError(local_var_error))
186    }
187}
188
189/// Get all relationships that match the query. Only the namespace field is required.
190pub async fn get_relationships(configuration: &configuration::Configuration, page_token: Option<&str>, page_size: Option<i64>, namespace: Option<&str>, object: Option<&str>, relation: Option<&str>, subject_id: Option<&str>, subject_set_period_namespace: Option<&str>, subject_set_period_object: Option<&str>, subject_set_period_relation: Option<&str>) -> Result<models::Relationships, Error<GetRelationshipsError>> {
191    let local_var_configuration = configuration;
192
193    let local_var_client = &local_var_configuration.client;
194
195    let local_var_uri_str = format!("{}/relation-tuples", local_var_configuration.base_path);
196    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
197
198    if let Some(ref local_var_str) = page_token {
199        local_var_req_builder = local_var_req_builder.query(&[("page_token", &local_var_str.to_string())]);
200    }
201    if let Some(ref local_var_str) = page_size {
202        local_var_req_builder = local_var_req_builder.query(&[("page_size", &local_var_str.to_string())]);
203    }
204    if let Some(ref local_var_str) = namespace {
205        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
206    }
207    if let Some(ref local_var_str) = object {
208        local_var_req_builder = local_var_req_builder.query(&[("object", &local_var_str.to_string())]);
209    }
210    if let Some(ref local_var_str) = relation {
211        local_var_req_builder = local_var_req_builder.query(&[("relation", &local_var_str.to_string())]);
212    }
213    if let Some(ref local_var_str) = subject_id {
214        local_var_req_builder = local_var_req_builder.query(&[("subject_id", &local_var_str.to_string())]);
215    }
216    if let Some(ref local_var_str) = subject_set_period_namespace {
217        local_var_req_builder = local_var_req_builder.query(&[("subject_set.namespace", &local_var_str.to_string())]);
218    }
219    if let Some(ref local_var_str) = subject_set_period_object {
220        local_var_req_builder = local_var_req_builder.query(&[("subject_set.object", &local_var_str.to_string())]);
221    }
222    if let Some(ref local_var_str) = subject_set_period_relation {
223        local_var_req_builder = local_var_req_builder.query(&[("subject_set.relation", &local_var_str.to_string())]);
224    }
225    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
226        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
227    }
228    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
229        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
230    };
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    let local_var_status = local_var_resp.status();
236    let local_var_content = local_var_resp.text().await?;
237
238    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239        serde_json::from_str(&local_var_content).map_err(Error::from)
240    } else {
241        let local_var_entity: Option<GetRelationshipsError> = serde_json::from_str(&local_var_content).ok();
242        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
243        Err(Error::ResponseError(local_var_error))
244    }
245}
246
247/// Get all namespaces
248pub async fn list_relationship_namespaces(configuration: &configuration::Configuration, ) -> Result<models::RelationshipNamespaces, Error<ListRelationshipNamespacesError>> {
249    let local_var_configuration = configuration;
250
251    let local_var_client = &local_var_configuration.client;
252
253    let local_var_uri_str = format!("{}/namespaces", local_var_configuration.base_path);
254    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
255
256    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
258    }
259    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
260        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
261    };
262
263    let local_var_req = local_var_req_builder.build()?;
264    let local_var_resp = local_var_client.execute(local_var_req).await?;
265
266    let local_var_status = local_var_resp.status();
267    let local_var_content = local_var_resp.text().await?;
268
269    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270        serde_json::from_str(&local_var_content).map_err(Error::from)
271    } else {
272        let local_var_entity: Option<ListRelationshipNamespacesError> = serde_json::from_str(&local_var_content).ok();
273        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
274        Err(Error::ResponseError(local_var_error))
275    }
276}
277
278/// Use this endpoint to patch one or more relationships.
279pub async fn patch_relationships(configuration: &configuration::Configuration, relationship_patch: Option<Vec<models::RelationshipPatch>>) -> Result<(), Error<PatchRelationshipsError>> {
280    let local_var_configuration = configuration;
281
282    let local_var_client = &local_var_configuration.client;
283
284    let local_var_uri_str = format!("{}/admin/relation-tuples", local_var_configuration.base_path);
285    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
286
287    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
288        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289    }
290    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
291        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
292    };
293    local_var_req_builder = local_var_req_builder.json(&relationship_patch);
294
295    let local_var_req = local_var_req_builder.build()?;
296    let local_var_resp = local_var_client.execute(local_var_req).await?;
297
298    let local_var_status = local_var_resp.status();
299    let local_var_content = local_var_resp.text().await?;
300
301    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
302        Ok(())
303    } else {
304        let local_var_entity: Option<PatchRelationshipsError> = serde_json::from_str(&local_var_content).ok();
305        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
306        Err(Error::ResponseError(local_var_error))
307    }
308}
309