ory_oathkeeper_client/apis/
api_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[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#[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#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetWellKnownJsonWebKeysError {
42 Status500(models::GenericError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ListRulesError {
50 Status500(models::GenericError),
51 UnknownValue(serde_json::Value),
52}
53
54
55pub 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
79pub async fn get_rule(configuration: &configuration::Configuration, id: &str) -> Result<models::Rule, Error<GetRuleError>> {
81 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
116pub 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
151pub async fn list_rules(configuration: &configuration::Configuration, limit: Option<i64>, offset: Option<i64>) -> Result<Vec<models::Rule>, Error<ListRulesError>> {
153 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", ¶m_value.to_string())]);
162 }
163 if let Some(ref param_value) = p_offset {
164 req_builder = req_builder.query(&[("offset", ¶m_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<models::Rule>`"))),
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<models::Rule>`")))),
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