authentik_client/apis/
root_api.rs

1/*
2 * authentik
3 *
4 * Making authentication simple.
5 *
6 * The version of the OpenAPI document: 2025.8.4
7 * Contact: hello@goauthentik.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`root_config_retrieve`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum RootConfigRetrieveError {
20    Status400(models::ValidationError),
21    Status403(models::GenericError),
22    UnknownValue(serde_json::Value),
23}
24
25/// Retrieve public configuration options
26pub async fn root_config_retrieve(
27    configuration: &configuration::Configuration,
28) -> Result<models::Config, Error<RootConfigRetrieveError>> {
29    let uri_str = format!("{}/root/config/", configuration.base_path);
30    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
31
32    if let Some(ref user_agent) = configuration.user_agent {
33        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
34    }
35    if let Some(ref token) = configuration.bearer_access_token {
36        req_builder = req_builder.bearer_auth(token.to_owned());
37    };
38
39    let req = req_builder.build()?;
40    let resp = configuration.client.execute(req).await?;
41
42    let status = resp.status();
43    let content_type = resp
44        .headers()
45        .get("content-type")
46        .and_then(|v| v.to_str().ok())
47        .unwrap_or("application/octet-stream");
48    let content_type = super::ContentType::from(content_type);
49
50    if !status.is_client_error() && !status.is_server_error() {
51        let content = resp.text().await?;
52        match content_type {
53            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
54            ContentType::Text => {
55                return Err(Error::from(serde_json::Error::custom(
56                    "Received `text/plain` content type response that cannot be converted to `models::Config`",
57                )))
58            }
59            ContentType::Unsupported(unknown_type) => {
60                return Err(Error::from(serde_json::Error::custom(format!(
61                    "Received `{unknown_type}` content type response that cannot be converted to `models::Config`"
62                ))))
63            }
64        }
65    } else {
66        let content = resp.text().await?;
67        let entity: Option<RootConfigRetrieveError> = serde_json::from_str(&content).ok();
68        Err(Error::ResponseError(ResponseContent {
69            status,
70            content,
71            entity,
72        }))
73    }
74}