ory_oathkeeper_client/apis/
api_api.rs

1/*
2 * Ory Oathkeeper API
3 *
4 * Documentation for all of Ory Oathkeeper's APIs. 
5 *
6 * The version of the OpenAPI document: v25.4.0
7 * Contact: hi@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`decisions`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DecisionsError {
22    Status401(models::GenericError),
23    Status403(models::GenericError),
24    Status404(models::GenericError),
25    Status500(models::GenericError),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_rule`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetRuleError {
33    Status404(models::GenericError),
34    Status500(models::GenericError),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_well_known_json_web_keys`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetWellKnownJsonWebKeysError {
42    Status500(models::GenericError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`list_rules`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ListRulesError {
50    Status500(models::GenericError),
51    UnknownValue(serde_json::Value),
52}
53
54
55/// > This endpoint works with all HTTP Methods (GET, POST, PUT, ...) and matches every path prefixed with /decisions.  This endpoint mirrors the proxy capability of ORY Oathkeeper's proxy functionality but instead of forwarding the request to the upstream server, returns 200 (request should be allowed), 401 (unauthorized), or 403 (forbidden) status codes. This endpoint can be used to integrate with other API Proxies like Ambassador, Kong, Envoy, and many more.
56pub async fn decisions(configuration: &configuration::Configuration, ) -> Result<(), Error<DecisionsError>> {
57
58    let uri_str = format!("{}/decisions", configuration.base_path);
59    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
60
61    if let Some(ref user_agent) = configuration.user_agent {
62        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
63    }
64
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69
70    if !status.is_client_error() && !status.is_server_error() {
71        Ok(())
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<DecisionsError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent { status, content, entity }))
76    }
77}
78
79/// Use this method to retrieve a rule from the storage. If it does not exist you will receive a 404 error.
80pub async fn get_rule(configuration: &configuration::Configuration, id: &str) -> Result<models::Rule, Error<GetRuleError>> {
81    // add a prefix to parameters to efficiently prevent name collisions
82    let p_id = id;
83
84    let uri_str = format!("{}/rules/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
85    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
86
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90
91    let req = req_builder.build()?;
92    let resp = configuration.client.execute(req).await?;
93
94    let status = resp.status();
95    let content_type = resp
96        .headers()
97        .get("content-type")
98        .and_then(|v| v.to_str().ok())
99        .unwrap_or("application/octet-stream");
100    let content_type = super::ContentType::from(content_type);
101
102    if !status.is_client_error() && !status.is_server_error() {
103        let content = resp.text().await?;
104        match content_type {
105            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Rule`"))),
107            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Rule`")))),
108        }
109    } else {
110        let content = resp.text().await?;
111        let entity: Option<GetRuleError> = serde_json::from_str(&content).ok();
112        Err(Error::ResponseError(ResponseContent { status, content, entity }))
113    }
114}
115
116/// This endpoint returns cryptographic keys that are required to, for example, verify signatures of ID Tokens.
117pub async fn get_well_known_json_web_keys(configuration: &configuration::Configuration, ) -> Result<models::JsonWebKeySet, Error<GetWellKnownJsonWebKeysError>> {
118
119    let uri_str = format!("{}/.well-known/jwks.json", configuration.base_path);
120    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125
126    let req = req_builder.build()?;
127    let resp = configuration.client.execute(req).await?;
128
129    let status = resp.status();
130    let content_type = resp
131        .headers()
132        .get("content-type")
133        .and_then(|v| v.to_str().ok())
134        .unwrap_or("application/octet-stream");
135    let content_type = super::ContentType::from(content_type);
136
137    if !status.is_client_error() && !status.is_server_error() {
138        let content = resp.text().await?;
139        match content_type {
140            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
141            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JsonWebKeySet`"))),
142            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::JsonWebKeySet`")))),
143        }
144    } else {
145        let content = resp.text().await?;
146        let entity: Option<GetWellKnownJsonWebKeysError> = serde_json::from_str(&content).ok();
147        Err(Error::ResponseError(ResponseContent { status, content, entity }))
148    }
149}
150
151/// This method returns an array of all rules that are stored in the backend. This is useful if you want to get a full view of what rules you have currently in place.
152pub async fn list_rules(configuration: &configuration::Configuration, limit: Option<i64>, offset: Option<i64>) -> Result<Vec<models::Rule>, Error<ListRulesError>> {
153    // add a prefix to parameters to efficiently prevent name collisions
154    let p_limit = limit;
155    let p_offset = offset;
156
157    let uri_str = format!("{}/rules", configuration.base_path);
158    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
159
160    if let Some(ref param_value) = p_limit {
161        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
162    }
163    if let Some(ref param_value) = p_offset {
164        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
165    }
166    if let Some(ref user_agent) = configuration.user_agent {
167        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168    }
169
170    let req = req_builder.build()?;
171    let resp = configuration.client.execute(req).await?;
172
173    let status = resp.status();
174    let content_type = resp
175        .headers()
176        .get("content-type")
177        .and_then(|v| v.to_str().ok())
178        .unwrap_or("application/octet-stream");
179    let content_type = super::ContentType::from(content_type);
180
181    if !status.is_client_error() && !status.is_server_error() {
182        let content = resp.text().await?;
183        match content_type {
184            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
185            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Rule&gt;`"))),
186            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Rule&gt;`")))),
187        }
188    } else {
189        let content = resp.text().await?;
190        let entity: Option<ListRulesError> = serde_json::from_str(&content).ok();
191        Err(Error::ResponseError(ResponseContent { status, content, entity }))
192    }
193}
194