authentik_rust/apis/
root_api.rs1use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum RootConfigRetrieveError {
22 Status400(models::ValidationError),
23 Status403(models::GenericError),
24 UnknownValue(serde_json::Value),
25}
26
27
28pub async fn root_config_retrieve(configuration: &configuration::Configuration, ) -> Result<models::Config, Error<RootConfigRetrieveError>> {
30 let local_var_configuration = configuration;
31
32 let local_var_client = &local_var_configuration.client;
33
34 let local_var_uri_str = format!("{}/root/config/", local_var_configuration.base_path);
35 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
36
37 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
38 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
39 }
40 if let Some(ref local_var_apikey) = local_var_configuration.api_key {
41 let local_var_key = local_var_apikey.key.clone();
42 let local_var_value = match local_var_apikey.prefix {
43 Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
44 None => local_var_key,
45 };
46 local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
47 };
48
49 let local_var_req = local_var_req_builder.build()?;
50 let local_var_resp = local_var_client.execute(local_var_req).await?;
51
52 let local_var_status = local_var_resp.status();
53 let local_var_content = local_var_resp.text().await?;
54
55 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
56 serde_json::from_str(&local_var_content).map_err(Error::from)
57 } else {
58 let local_var_entity: Option<RootConfigRetrieveError> = serde_json::from_str(&local_var_content).ok();
59 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
60 Err(Error::ResponseError(local_var_error))
61 }
62}
63