Skip to main content

clientapi_pve/apis/
access_openid_api.rs

1/*
2 * Proxmox Virtual Environment API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
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 [`access_openid_auth_url`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessOpenidAuthUrlError {
22    Status400(models::PveError),
23    Status401(models::PveError),
24    Status403(models::PveError),
25    Status404(models::PveError),
26    Status500(models::PveError),
27    Status501(models::PveError),
28    Status503(models::PveError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`access_openid_get_openid`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessOpenidGetOpenidError {
36    Status400(models::PveError),
37    Status401(models::PveError),
38    Status403(models::PveError),
39    Status404(models::PveError),
40    Status500(models::PveError),
41    Status501(models::PveError),
42    Status503(models::PveError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`access_openid_login`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AccessOpenidLoginError {
50    Status400(models::PveError),
51    Status401(models::PveError),
52    Status403(models::PveError),
53    Status404(models::PveError),
54    Status500(models::PveError),
55    Status501(models::PveError),
56    Status503(models::PveError),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Get the OpenId Authorization Url for the specified realm.
62pub async fn access_openid_auth_url(configuration: &configuration::Configuration, access_openid_auth_url_request: models::AccessOpenidAuthUrlRequest) -> Result<models::AccessOpenidAuthUrlResponse, Error<AccessOpenidAuthUrlError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_body_access_openid_auth_url_request = access_openid_auth_url_request;
65
66    let uri_str = format!("{}/access/openid/auth-url", configuration.base_path);
67    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
68
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    req_builder = req_builder.json(&p_body_access_openid_auth_url_request);
73
74    let req = req_builder.build()?;
75    let resp = configuration.client.execute(req).await?;
76
77    let status = resp.status();
78    let content_type = resp
79        .headers()
80        .get("content-type")
81        .and_then(|v| v.to_str().ok())
82        .unwrap_or("application/octet-stream");
83    let content_type = super::ContentType::from(content_type);
84
85    if !status.is_client_error() && !status.is_server_error() {
86        let content = resp.text().await?;
87        match content_type {
88            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessOpenidAuthUrlResponse`"))),
90            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::AccessOpenidAuthUrlResponse`")))),
91        }
92    } else {
93        let content = resp.text().await?;
94        let entity: Option<AccessOpenidAuthUrlError> = serde_json::from_str(&content).ok();
95        Err(Error::ResponseError(ResponseContent { status, content, entity }))
96    }
97}
98
99/// Directory index.
100pub async fn access_openid_get_openid(configuration: &configuration::Configuration, ) -> Result<models::AccessOpenidGetOpenidResponse, Error<AccessOpenidGetOpenidError>> {
101
102    let uri_str = format!("{}/access/openid", configuration.base_path);
103    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
104
105    if let Some(ref user_agent) = configuration.user_agent {
106        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
107    }
108    if let Some(ref apikey) = configuration.api_key {
109        let key = apikey.key.clone();
110        let value = match apikey.prefix {
111            Some(ref prefix) => format!("{} {}", prefix, key),
112            None => key,
113        };
114        req_builder = req_builder.header("Authorization", value);
115    };
116    if let Some(ref apikey) = configuration.api_key {
117        let key = apikey.key.clone();
118        let value = match apikey.prefix {
119            Some(ref prefix) => format!("{} {}", prefix, key),
120            None => key,
121        };
122        req_builder = req_builder.header("CSRFPreventionToken", value);
123    };
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129    let content_type = resp
130        .headers()
131        .get("content-type")
132        .and_then(|v| v.to_str().ok())
133        .unwrap_or("application/octet-stream");
134    let content_type = super::ContentType::from(content_type);
135
136    if !status.is_client_error() && !status.is_server_error() {
137        let content = resp.text().await?;
138        match content_type {
139            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
140            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessOpenidGetOpenidResponse`"))),
141            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::AccessOpenidGetOpenidResponse`")))),
142        }
143    } else {
144        let content = resp.text().await?;
145        let entity: Option<AccessOpenidGetOpenidError> = serde_json::from_str(&content).ok();
146        Err(Error::ResponseError(ResponseContent { status, content, entity }))
147    }
148}
149
150/// Verify OpenID authorization code and create a ticket.
151pub async fn access_openid_login(configuration: &configuration::Configuration, access_openid_login_request: models::AccessOpenidLoginRequest) -> Result<models::AccessOpenidLoginResponse, Error<AccessOpenidLoginError>> {
152    // add a prefix to parameters to efficiently prevent name collisions
153    let p_body_access_openid_login_request = access_openid_login_request;
154
155    let uri_str = format!("{}/access/openid/login", configuration.base_path);
156    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
157
158    if let Some(ref user_agent) = configuration.user_agent {
159        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160    }
161    req_builder = req_builder.json(&p_body_access_openid_login_request);
162
163    let req = req_builder.build()?;
164    let resp = configuration.client.execute(req).await?;
165
166    let status = resp.status();
167    let content_type = resp
168        .headers()
169        .get("content-type")
170        .and_then(|v| v.to_str().ok())
171        .unwrap_or("application/octet-stream");
172    let content_type = super::ContentType::from(content_type);
173
174    if !status.is_client_error() && !status.is_server_error() {
175        let content = resp.text().await?;
176        match content_type {
177            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessOpenidLoginResponse`"))),
179            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::AccessOpenidLoginResponse`")))),
180        }
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<AccessOpenidLoginError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent { status, content, entity }))
185    }
186}
187