tembo_api_client/apis/
tokens_api.rs

1/*
2 * Tembo Cloud
3 *
4 * Platform API for Tembo Cloud             </br>             </br>             To find a Tembo Data API, please find it here:             </br>             </br>             [AWS US East 1](https://api.data-1.use1.tembo.io/swagger-ui/)
5 *
6 * The version of the OpenAPI document: v1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`invalidate_token`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum InvalidateTokenError {
20    Status401(models::ErrorResponseSchema),
21    Status403(models::ErrorResponseSchema),
22    UnknownValue(serde_json::Value),
23}
24
25/// Invalidate the token included in the Authorization header  May take a up to a minute for subsequent requests to be rejected after the invalidation has been accepted.
26pub async fn invalidate_token(
27    configuration: &configuration::Configuration,
28) -> Result<String, Error<InvalidateTokenError>> {
29    let uri_str = format!("{}/api/v1/tokens/invalidate", configuration.base_path);
30    let mut req_builder = configuration
31        .client
32        .request(reqwest::Method::DELETE, &uri_str);
33
34    if let Some(ref user_agent) = configuration.user_agent {
35        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
36    }
37    if let Some(ref token) = configuration.bearer_access_token {
38        req_builder = req_builder.bearer_auth(token.to_owned());
39    };
40
41    let req = req_builder.build()?;
42    let resp = configuration.client.execute(req).await?;
43
44    let status = resp.status();
45
46    if !status.is_client_error() && !status.is_server_error() {
47        let content = resp.text().await?;
48        serde_json::from_str(&content).map_err(Error::from)
49    } else {
50        let content = resp.text().await?;
51        let entity: Option<InvalidateTokenError> = serde_json::from_str(&content).ok();
52        Err(Error::ResponseError(ResponseContent {
53            status,
54            content,
55            entity,
56        }))
57    }
58}