Skip to main content

mesa_dev_oapi/apis/
admin_api.rs

1/*
2 * Depot API
3 *
4 * Depot HTTP API v1
5 *
6 * The version of the OpenAPI document: 1.0.0
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 [`delete_by_org_api_keys_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteByOrgApiKeysByIdError {
22    Status400(models::PostByOrgApiKeys400Response),
23    Status401(models::PostByOrgApiKeys400Response),
24    Status403(models::PostByOrgApiKeys400Response),
25    Status404(models::PostByOrgApiKeys400Response),
26    Status406(models::PostByOrgApiKeys400Response),
27    Status409(models::PostByOrgApiKeys400Response),
28    Status500(models::PostByOrgApiKeys400Response),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_by_org_api_keys`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetByOrgApiKeysError {
36    Status400(models::GetByOrgApiKeys400Response),
37    Status401(models::GetByOrgApiKeys400Response),
38    Status403(models::GetByOrgApiKeys400Response),
39    Status404(models::GetByOrgApiKeys400Response),
40    Status406(models::GetByOrgApiKeys400Response),
41    Status409(models::GetByOrgApiKeys400Response),
42    Status500(models::GetByOrgApiKeys400Response),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_by_org_api_keys`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostByOrgApiKeysError {
50    Status400(models::PostByOrgApiKeys400Response),
51    Status401(models::PostByOrgApiKeys400Response),
52    Status403(models::PostByOrgApiKeys400Response),
53    Status404(models::PostByOrgApiKeys400Response),
54    Status406(models::PostByOrgApiKeys400Response),
55    Status409(models::PostByOrgApiKeys400Response),
56    Status500(models::PostByOrgApiKeys400Response),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Revoke an API key by its ID
62pub async fn delete_by_org_api_keys_by_id(configuration: &configuration::Configuration, id: &str, org: &str) -> Result<models::DeleteByOrgApiKeysById200Response, Error<DeleteByOrgApiKeysByIdError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_path_id = id;
65    let p_path_org = org;
66
67    let uri_str = format!("{}/{org}/api-keys/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), org=crate::apis::urlencode(p_path_org));
68    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
69
70    if let Some(ref user_agent) = configuration.user_agent {
71        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
72    }
73    if let Some(ref token) = configuration.bearer_access_token {
74        req_builder = req_builder.bearer_auth(token.to_owned());
75    };
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81    let content_type = resp
82        .headers()
83        .get("content-type")
84        .and_then(|v| v.to_str().ok())
85        .unwrap_or("application/octet-stream");
86    let content_type = super::ContentType::from(content_type);
87
88    if !status.is_client_error() && !status.is_server_error() {
89        let content = resp.text().await?;
90        match content_type {
91            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
92            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteByOrgApiKeysById200Response`"))),
93            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::DeleteByOrgApiKeysById200Response`")))),
94        }
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<DeleteByOrgApiKeysByIdError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent { status, content, entity }))
99    }
100}
101
102/// List all API keys for the organization (key values are not returned)
103pub async fn get_by_org_api_keys(configuration: &configuration::Configuration, org: &str) -> Result<models::GetByOrgApiKeys200Response, Error<GetByOrgApiKeysError>> {
104    // add a prefix to parameters to efficiently prevent name collisions
105    let p_path_org = org;
106
107    let uri_str = format!("{}/{org}/api-keys", configuration.base_path, org=crate::apis::urlencode(p_path_org));
108    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgApiKeys200Response`"))),
133            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::GetByOrgApiKeys200Response`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<GetByOrgApiKeysError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Create a new API key for programmatic access
143pub async fn post_by_org_api_keys(configuration: &configuration::Configuration, org: &str, post_by_org_api_keys_request: Option<models::PostByOrgApiKeysRequest>) -> Result<models::PostByOrgApiKeys201Response, Error<PostByOrgApiKeysError>> {
144    // add a prefix to parameters to efficiently prevent name collisions
145    let p_path_org = org;
146    let p_body_post_by_org_api_keys_request = post_by_org_api_keys_request;
147
148    let uri_str = format!("{}/{org}/api-keys", configuration.base_path, org=crate::apis::urlencode(p_path_org));
149    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
150
151    if let Some(ref user_agent) = configuration.user_agent {
152        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153    }
154    if let Some(ref token) = configuration.bearer_access_token {
155        req_builder = req_builder.bearer_auth(token.to_owned());
156    };
157    req_builder = req_builder.json(&p_body_post_by_org_api_keys_request);
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163    let content_type = resp
164        .headers()
165        .get("content-type")
166        .and_then(|v| v.to_str().ok())
167        .unwrap_or("application/octet-stream");
168    let content_type = super::ContentType::from(content_type);
169
170    if !status.is_client_error() && !status.is_server_error() {
171        let content = resp.text().await?;
172        match content_type {
173            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
174            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PostByOrgApiKeys201Response`"))),
175            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::PostByOrgApiKeys201Response`")))),
176        }
177    } else {
178        let content = resp.text().await?;
179        let entity: Option<PostByOrgApiKeysError> = serde_json::from_str(&content).ok();
180        Err(Error::ResponseError(ResponseContent { status, content, entity }))
181    }
182}
183