Skip to main content

ory_client/apis/
api_keys_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.22.41
7 * Contact: support@ory.sh
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 [`admin_batch_import_api_keys`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AdminBatchImportApiKeysError {
22    DefaultResponse(models::Status),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`admin_batch_verify_api_keys`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AdminBatchVerifyApiKeysError {
30    DefaultResponse(models::Status),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`admin_delete_imported_api_key`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum AdminDeleteImportedApiKeyError {
38    DefaultResponse(models::Status),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`admin_derive_token`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum AdminDeriveTokenError {
46    DefaultResponse(models::Status),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`admin_get_imported_api_key`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum AdminGetImportedApiKeyError {
54    DefaultResponse(models::Status),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`admin_get_issued_api_key`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum AdminGetIssuedApiKeyError {
62    DefaultResponse(models::Status),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`admin_import_api_key`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum AdminImportApiKeyError {
70    DefaultResponse(models::Status),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`admin_issue_api_key`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum AdminIssueApiKeyError {
78    DefaultResponse(models::Status),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`admin_list_imported_api_keys`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum AdminListImportedApiKeysError {
86    DefaultResponse(models::Status),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`admin_list_issued_api_keys`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum AdminListIssuedApiKeysError {
94    DefaultResponse(models::Status),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`admin_revoke_api_key`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum AdminRevokeApiKeyError {
102    DefaultResponse(models::Status),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`admin_rotate_issued_api_key`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum AdminRotateIssuedApiKeyError {
110    DefaultResponse(models::Status),
111    UnknownValue(serde_json::Value),
112}
113
114/// struct for typed errors of method [`admin_update_imported_api_key`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum AdminUpdateImportedApiKeyError {
118    DefaultResponse(models::Status),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`admin_update_issued_api_key`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum AdminUpdateIssuedApiKeyError {
126    DefaultResponse(models::Status),
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`admin_verify_api_key`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum AdminVerifyApiKeyError {
134    DefaultResponse(models::Status),
135    UnknownValue(serde_json::Value),
136}
137
138/// struct for typed errors of method [`get_jwks`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum GetJwksError {
142    DefaultResponse(models::Status),
143    UnknownValue(serde_json::Value),
144}
145
146/// struct for typed errors of method [`revoke_api_key`]
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(untagged)]
149pub enum RevokeApiKeyError {
150    DefaultResponse(models::Status),
151    UnknownValue(serde_json::Value),
152}
153
154
155/// Imports up to 1000 external API keys in one request. Returns per-item results. If at least one item succeeds, response is 200 OK. If all items fail, the endpoint returns a non-200 error.  ```http POST /v2alpha1/admin/importedApiKeys:batchImport {   \"requests\": [     {\"raw_key\": \"sk_live_abc\", \"name\": \"Stripe key\", \"actor_id\": \"user_1\"},     {\"raw_key\": \"ghp_xyz\", \"name\": \"GitHub PAT\", \"actor_id\": \"user_2\"}   ] } ```
156pub async fn admin_batch_import_api_keys(configuration: &configuration::Configuration, batch_import_api_keys_request: models::BatchImportApiKeysRequest) -> Result<models::BatchImportApiKeysResponse, Error<AdminBatchImportApiKeysError>> {
157    // add a prefix to parameters to efficiently prevent name collisions
158    let p_body_batch_import_api_keys_request = batch_import_api_keys_request;
159
160    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys:batchImport", configuration.base_path);
161    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
162
163    if let Some(ref user_agent) = configuration.user_agent {
164        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
165    }
166    if let Some(ref token) = configuration.bearer_access_token {
167        req_builder = req_builder.bearer_auth(token.to_owned());
168    };
169    req_builder = req_builder.json(&p_body_batch_import_api_keys_request);
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175    let content_type = resp
176        .headers()
177        .get("content-type")
178        .and_then(|v| v.to_str().ok())
179        .unwrap_or("application/octet-stream");
180    let content_type = super::ContentType::from(content_type);
181
182    if !status.is_client_error() && !status.is_server_error() {
183        let content = resp.text().await?;
184        match content_type {
185            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchImportApiKeysResponse`"))),
187            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::BatchImportApiKeysResponse`")))),
188        }
189    } else {
190        let content = resp.text().await?;
191        let entity: Option<AdminBatchImportApiKeysError> = serde_json::from_str(&content).ok();
192        Err(Error::ResponseError(ResponseContent { status, content, entity }))
193    }
194}
195
196/// Verifies multiple credentials in a single request. Efficiently verifies up to 100 credentials in parallel. Each credential is verified independently; partial failures are returned. Admin access only.  Cache Control (HTTP Headers):   - Cache-Control: no-cache  - Bypasses cache read, forces fresh DB lookup   - Cache-Control: no-store  - Bypasses cache read AND write (never cached)   - Pragma: no-cache         - Same as Cache-Control: no-cache (HTTP/1.0)  The cache directive applies to every credential in the batch.  ```http POST /v2alpha1/admin/apiKeys:batchVerify {   \"requests\": [     {\"credential\": \"sk_live_abc123...\"},     {\"credential\": \"eyJhbGciOiJFZERTQSI...\"}   ] } ```
197pub async fn admin_batch_verify_api_keys(configuration: &configuration::Configuration, batch_verify_api_keys_request: models::BatchVerifyApiKeysRequest, cache_control: Option<&str>, pragma: Option<&str>) -> Result<models::BatchVerifyApiKeysResponse, Error<AdminBatchVerifyApiKeysError>> {
198    // add a prefix to parameters to efficiently prevent name collisions
199    let p_body_batch_verify_api_keys_request = batch_verify_api_keys_request;
200    let p_header_cache_control = cache_control;
201    let p_header_pragma = pragma;
202
203    let uri_str = format!("{}/v2alpha1/admin/apiKeys:batchVerify", configuration.base_path);
204    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
205
206    if let Some(ref user_agent) = configuration.user_agent {
207        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
208    }
209    if let Some(param_value) = p_header_cache_control {
210        req_builder = req_builder.header("Cache-Control", param_value.to_string());
211    }
212    if let Some(param_value) = p_header_pragma {
213        req_builder = req_builder.header("Pragma", param_value.to_string());
214    }
215    if let Some(ref token) = configuration.bearer_access_token {
216        req_builder = req_builder.bearer_auth(token.to_owned());
217    };
218    req_builder = req_builder.json(&p_body_batch_verify_api_keys_request);
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchVerifyApiKeysResponse`"))),
236            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::BatchVerifyApiKeysResponse`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<AdminBatchVerifyApiKeysError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244
245/// Permanently deletes an imported key (hard delete). The key is removed from the database. Use RevokeAPIKey for soft deletion (recommended).  ```http DELETE /v2alpha1/admin/importedApiKeys/{key_id} ```
246pub async fn admin_delete_imported_api_key(configuration: &configuration::Configuration, key_id: &str) -> Result<serde_json::Value, Error<AdminDeleteImportedApiKeyError>> {
247    // add a prefix to parameters to efficiently prevent name collisions
248    let p_path_key_id = key_id;
249
250    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
251    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
252
253    if let Some(ref user_agent) = configuration.user_agent {
254        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
255    }
256    if let Some(ref token) = configuration.bearer_access_token {
257        req_builder = req_builder.bearer_auth(token.to_owned());
258    };
259
260    let req = req_builder.build()?;
261    let resp = configuration.client.execute(req).await?;
262
263    let status = resp.status();
264    let content_type = resp
265        .headers()
266        .get("content-type")
267        .and_then(|v| v.to_str().ok())
268        .unwrap_or("application/octet-stream");
269    let content_type = super::ContentType::from(content_type);
270
271    if !status.is_client_error() && !status.is_server_error() {
272        let content = resp.text().await?;
273        match content_type {
274            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
276            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
277        }
278    } else {
279        let content = resp.text().await?;
280        let entity: Option<AdminDeleteImportedApiKeyError> = serde_json::from_str(&content).ok();
281        Err(Error::ResponseError(ResponseContent { status, content, entity }))
282    }
283}
284
285/// Mints a short-lived JWT or Macaroon token from an API key. Works with both issued and imported keys. The derived token inherits the permissions of the parent API key.  ```http POST /v2alpha1/admin/apiKeys:derive {   \"credential\": \"eyJhbGciOiJFZERTQSI...\",   \"ttl\": \"1h\" } ```
286pub async fn admin_derive_token(configuration: &configuration::Configuration, derive_token_request: models::DeriveTokenRequest) -> Result<models::DeriveTokenResponse, Error<AdminDeriveTokenError>> {
287    // add a prefix to parameters to efficiently prevent name collisions
288    let p_body_derive_token_request = derive_token_request;
289
290    let uri_str = format!("{}/v2alpha1/admin/apiKeys:derive", configuration.base_path);
291    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
292
293    if let Some(ref user_agent) = configuration.user_agent {
294        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
295    }
296    if let Some(ref token) = configuration.bearer_access_token {
297        req_builder = req_builder.bearer_auth(token.to_owned());
298    };
299    req_builder = req_builder.json(&p_body_derive_token_request);
300
301    let req = req_builder.build()?;
302    let resp = configuration.client.execute(req).await?;
303
304    let status = resp.status();
305    let content_type = resp
306        .headers()
307        .get("content-type")
308        .and_then(|v| v.to_str().ok())
309        .unwrap_or("application/octet-stream");
310    let content_type = super::ContentType::from(content_type);
311
312    if !status.is_client_error() && !status.is_server_error() {
313        let content = resp.text().await?;
314        match content_type {
315            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
316            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeriveTokenResponse`"))),
317            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::DeriveTokenResponse`")))),
318        }
319    } else {
320        let content = resp.text().await?;
321        let entity: Option<AdminDeriveTokenError> = serde_json::from_str(&content).ok();
322        Err(Error::ResponseError(ResponseContent { status, content, entity }))
323    }
324}
325
326/// Retrieves details about a specific imported key. Returns metadata about the imported key. The original raw key is never returned.  ```http GET /v2alpha1/admin/importedApiKeys/{key_id} ```
327pub async fn admin_get_imported_api_key(configuration: &configuration::Configuration, key_id: &str) -> Result<models::ImportedApiKey, Error<AdminGetImportedApiKeyError>> {
328    // add a prefix to parameters to efficiently prevent name collisions
329    let p_path_key_id = key_id;
330
331    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
332    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
333
334    if let Some(ref user_agent) = configuration.user_agent {
335        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336    }
337    if let Some(ref token) = configuration.bearer_access_token {
338        req_builder = req_builder.bearer_auth(token.to_owned());
339    };
340
341    let req = req_builder.build()?;
342    let resp = configuration.client.execute(req).await?;
343
344    let status = resp.status();
345    let content_type = resp
346        .headers()
347        .get("content-type")
348        .and_then(|v| v.to_str().ok())
349        .unwrap_or("application/octet-stream");
350    let content_type = super::ContentType::from(content_type);
351
352    if !status.is_client_error() && !status.is_server_error() {
353        let content = resp.text().await?;
354        match content_type {
355            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
356            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportedApiKey`"))),
357            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::ImportedApiKey`")))),
358        }
359    } else {
360        let content = resp.text().await?;
361        let entity: Option<AdminGetImportedApiKeyError> = serde_json::from_str(&content).ok();
362        Err(Error::ResponseError(ResponseContent { status, content, entity }))
363    }
364}
365
366/// Retrieves details about a specific issued API key including its status, scopes, expiration, and usage statistics. The secret is never returned.  ```http GET /v2alpha1/admin/issuedApiKeys/01HQZX9VYQKJB8XQZQXQZQXQXQ ```
367pub async fn admin_get_issued_api_key(configuration: &configuration::Configuration, key_id: &str) -> Result<models::IssuedApiKey, Error<AdminGetIssuedApiKeyError>> {
368    // add a prefix to parameters to efficiently prevent name collisions
369    let p_path_key_id = key_id;
370
371    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
372    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
373
374    if let Some(ref user_agent) = configuration.user_agent {
375        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
376    }
377    if let Some(ref token) = configuration.bearer_access_token {
378        req_builder = req_builder.bearer_auth(token.to_owned());
379    };
380
381    let req = req_builder.build()?;
382    let resp = configuration.client.execute(req).await?;
383
384    let status = resp.status();
385    let content_type = resp
386        .headers()
387        .get("content-type")
388        .and_then(|v| v.to_str().ok())
389        .unwrap_or("application/octet-stream");
390    let content_type = super::ContentType::from(content_type);
391
392    if !status.is_client_error() && !status.is_server_error() {
393        let content = resp.text().await?;
394        match content_type {
395            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
396            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IssuedApiKey`"))),
397            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::IssuedApiKey`")))),
398        }
399    } else {
400        let content = resp.text().await?;
401        let entity: Option<AdminGetIssuedApiKeyError> = serde_json::from_str(&content).ok();
402        Err(Error::ResponseError(ResponseContent { status, content, entity }))
403    }
404}
405
406/// Imports an external API key into the system. Allows importing keys from legacy systems or external providers. The raw key is hashed and stored securely (HMAC). Imported keys support token derivation (JWT/Macaroon) like issued keys.  ```http POST /v2alpha1/admin/importedApiKeys {   \"raw_key\": \"sk_live_abc123xyz\",   \"name\": \"Imported Stripe Key\",   \"actor_id\": \"user_123\" } ```
407pub async fn admin_import_api_key(configuration: &configuration::Configuration, import_api_key_request: models::ImportApiKeyRequest) -> Result<models::ImportedApiKey, Error<AdminImportApiKeyError>> {
408    // add a prefix to parameters to efficiently prevent name collisions
409    let p_body_import_api_key_request = import_api_key_request;
410
411    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys", configuration.base_path);
412    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
413
414    if let Some(ref user_agent) = configuration.user_agent {
415        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
416    }
417    if let Some(ref token) = configuration.bearer_access_token {
418        req_builder = req_builder.bearer_auth(token.to_owned());
419    };
420    req_builder = req_builder.json(&p_body_import_api_key_request);
421
422    let req = req_builder.build()?;
423    let resp = configuration.client.execute(req).await?;
424
425    let status = resp.status();
426    let content_type = resp
427        .headers()
428        .get("content-type")
429        .and_then(|v| v.to_str().ok())
430        .unwrap_or("application/octet-stream");
431    let content_type = super::ContentType::from(content_type);
432
433    if !status.is_client_error() && !status.is_server_error() {
434        let content = resp.text().await?;
435        match content_type {
436            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
437            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportedApiKey`"))),
438            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::ImportedApiKey`")))),
439        }
440    } else {
441        let content = resp.text().await?;
442        let entity: Option<AdminImportApiKeyError> = serde_json::from_str(&content).ok();
443        Err(Error::ResponseError(ResponseContent { status, content, entity }))
444    }
445}
446
447/// Creates a new API key for a given actor. The secret is returned only once in the response and cannot be retrieved later. Keys can be scoped with specific permissions and have optional expiration.  ```http POST /v2alpha1/admin/issuedApiKeys {   \"name\": \"production-service\",   \"actor_id\": \"user_123\",   \"scopes\": [\"read\", \"write\"],   \"ttl\": \"8760h\" } ```
448pub async fn admin_issue_api_key(configuration: &configuration::Configuration, issue_api_key_request: models::IssueApiKeyRequest) -> Result<models::IssueApiKeyResponse, Error<AdminIssueApiKeyError>> {
449    // add a prefix to parameters to efficiently prevent name collisions
450    let p_body_issue_api_key_request = issue_api_key_request;
451
452    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys", configuration.base_path);
453    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
454
455    if let Some(ref user_agent) = configuration.user_agent {
456        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
457    }
458    if let Some(ref token) = configuration.bearer_access_token {
459        req_builder = req_builder.bearer_auth(token.to_owned());
460    };
461    req_builder = req_builder.json(&p_body_issue_api_key_request);
462
463    let req = req_builder.build()?;
464    let resp = configuration.client.execute(req).await?;
465
466    let status = resp.status();
467    let content_type = resp
468        .headers()
469        .get("content-type")
470        .and_then(|v| v.to_str().ok())
471        .unwrap_or("application/octet-stream");
472    let content_type = super::ContentType::from(content_type);
473
474    if !status.is_client_error() && !status.is_server_error() {
475        let content = resp.text().await?;
476        match content_type {
477            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
478            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IssueApiKeyResponse`"))),
479            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::IssueApiKeyResponse`")))),
480        }
481    } else {
482        let content = resp.text().await?;
483        let entity: Option<AdminIssueApiKeyError> = serde_json::from_str(&content).ok();
484        Err(Error::ResponseError(ResponseContent { status, content, entity }))
485    }
486}
487
488/// Lists all imported keys with filtering. Returns imported keys only (not issued keys). Supports pagination and AIP-160 filter expressions.  ```http GET /v2alpha1/admin/importedApiKeys?page_size=50&filter=status%3DKEY_STATUS_ACTIVE ```
489pub async fn admin_list_imported_api_keys(configuration: &configuration::Configuration, page_size: Option<i32>, page_token: Option<&str>, filter: Option<&str>) -> Result<models::ListImportedApiKeysResponse, Error<AdminListImportedApiKeysError>> {
490    // add a prefix to parameters to efficiently prevent name collisions
491    let p_query_page_size = page_size;
492    let p_query_page_token = page_token;
493    let p_query_filter = filter;
494
495    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys", configuration.base_path);
496    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
497
498    if let Some(ref param_value) = p_query_page_size {
499        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
500    }
501    if let Some(ref param_value) = p_query_page_token {
502        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
503    }
504    if let Some(ref param_value) = p_query_filter {
505        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
506    }
507    if let Some(ref user_agent) = configuration.user_agent {
508        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
509    }
510    if let Some(ref token) = configuration.bearer_access_token {
511        req_builder = req_builder.bearer_auth(token.to_owned());
512    };
513
514    let req = req_builder.build()?;
515    let resp = configuration.client.execute(req).await?;
516
517    let status = resp.status();
518    let content_type = resp
519        .headers()
520        .get("content-type")
521        .and_then(|v| v.to_str().ok())
522        .unwrap_or("application/octet-stream");
523    let content_type = super::ContentType::from(content_type);
524
525    if !status.is_client_error() && !status.is_server_error() {
526        let content = resp.text().await?;
527        match content_type {
528            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
529            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListImportedApiKeysResponse`"))),
530            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::ListImportedApiKeysResponse`")))),
531        }
532    } else {
533        let content = resp.text().await?;
534        let entity: Option<AdminListImportedApiKeysError> = serde_json::from_str(&content).ok();
535        Err(Error::ResponseError(ResponseContent { status, content, entity }))
536    }
537}
538
539/// Lists issued API keys with optional filtering. Supports cursor-based pagination and AIP-160 filter expressions. Returns only issued (generated) API keys; use ListImportedAPIKeys for imported keys.  ```http GET /v2alpha1/admin/issuedApiKeys?page_size=50&filter=actor_id%3D%22user_123%22 ```
540pub async fn admin_list_issued_api_keys(configuration: &configuration::Configuration, page_size: Option<i32>, page_token: Option<&str>, filter: Option<&str>) -> Result<models::ListIssuedApiKeysResponse, Error<AdminListIssuedApiKeysError>> {
541    // add a prefix to parameters to efficiently prevent name collisions
542    let p_query_page_size = page_size;
543    let p_query_page_token = page_token;
544    let p_query_filter = filter;
545
546    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys", configuration.base_path);
547    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
548
549    if let Some(ref param_value) = p_query_page_size {
550        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
551    }
552    if let Some(ref param_value) = p_query_page_token {
553        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
554    }
555    if let Some(ref param_value) = p_query_filter {
556        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
557    }
558    if let Some(ref user_agent) = configuration.user_agent {
559        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
560    }
561    if let Some(ref token) = configuration.bearer_access_token {
562        req_builder = req_builder.bearer_auth(token.to_owned());
563    };
564
565    let req = req_builder.build()?;
566    let resp = configuration.client.execute(req).await?;
567
568    let status = resp.status();
569    let content_type = resp
570        .headers()
571        .get("content-type")
572        .and_then(|v| v.to_str().ok())
573        .unwrap_or("application/octet-stream");
574    let content_type = super::ContentType::from(content_type);
575
576    if !status.is_client_error() && !status.is_server_error() {
577        let content = resp.text().await?;
578        match content_type {
579            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
580            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListIssuedApiKeysResponse`"))),
581            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::ListIssuedApiKeysResponse`")))),
582        }
583    } else {
584        let content = resp.text().await?;
585        let entity: Option<AdminListIssuedApiKeysError> = serde_json::from_str(&content).ok();
586        Err(Error::ResponseError(ResponseContent { status, content, entity }))
587    }
588}
589
590/// Immediately revokes an API key (issued or imported). Once revoked, the key can no longer be used for authentication. This operation is irreversible. Revoked keys are retained for audit purposes.  ```http POST /v2alpha1/admin/apiKeys/01HQZX9VYQKJB8XQZQXQZQXQXQ:revoke {   \"reason\": \"REVOCATION_REASON_KEY_COMPROMISE\" } ```
591pub async fn admin_revoke_api_key(configuration: &configuration::Configuration, key_id: &str, admin_revoke_api_key_body: models::AdminRevokeApiKeyBody) -> Result<serde_json::Value, Error<AdminRevokeApiKeyError>> {
592    // add a prefix to parameters to efficiently prevent name collisions
593    let p_path_key_id = key_id;
594    let p_body_admin_revoke_api_key_body = admin_revoke_api_key_body;
595
596    let uri_str = format!("{}/v2alpha1/admin/apiKeys/{key_id}:revoke", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
597    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
598
599    if let Some(ref user_agent) = configuration.user_agent {
600        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
601    }
602    if let Some(ref token) = configuration.bearer_access_token {
603        req_builder = req_builder.bearer_auth(token.to_owned());
604    };
605    req_builder = req_builder.json(&p_body_admin_revoke_api_key_body);
606
607    let req = req_builder.build()?;
608    let resp = configuration.client.execute(req).await?;
609
610    let status = resp.status();
611    let content_type = resp
612        .headers()
613        .get("content-type")
614        .and_then(|v| v.to_str().ok())
615        .unwrap_or("application/octet-stream");
616    let content_type = super::ContentType::from(content_type);
617
618    if !status.is_client_error() && !status.is_server_error() {
619        let content = resp.text().await?;
620        match content_type {
621            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
622            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
623            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
624        }
625    } else {
626        let content = resp.text().await?;
627        let entity: Option<AdminRevokeApiKeyError> = serde_json::from_str(&content).ok();
628        Err(Error::ResponseError(ResponseContent { status, content, entity }))
629    }
630}
631
632/// Generates a new secret for an issued API key. Creates a new API key with a new key_id and secret, and immediately revokes the old key. This is the recommended way to update scopes, metadata, or rotate credentials.  For zero-downtime rotation, use this workflow instead:   1. IssueAPIKey with new credentials   2. Deploy new secret to all services   3. Verify new secret works everywhere   4. RevokeAPIKey to remove the old key  ```http POST /v2alpha1/admin/issuedApiKeys/01HQZX9VYQKJB8XQZQXQZQXQXQ:rotate {   \"scopes\": [\"read\"] } ```
633pub async fn admin_rotate_issued_api_key(configuration: &configuration::Configuration, key_id: &str, admin_rotate_issued_api_key_body: models::AdminRotateIssuedApiKeyBody) -> Result<models::RotateIssuedApiKeyResponse, Error<AdminRotateIssuedApiKeyError>> {
634    // add a prefix to parameters to efficiently prevent name collisions
635    let p_path_key_id = key_id;
636    let p_body_admin_rotate_issued_api_key_body = admin_rotate_issued_api_key_body;
637
638    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys/{key_id}:rotate", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
639    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
640
641    if let Some(ref user_agent) = configuration.user_agent {
642        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
643    }
644    if let Some(ref token) = configuration.bearer_access_token {
645        req_builder = req_builder.bearer_auth(token.to_owned());
646    };
647    req_builder = req_builder.json(&p_body_admin_rotate_issued_api_key_body);
648
649    let req = req_builder.build()?;
650    let resp = configuration.client.execute(req).await?;
651
652    let status = resp.status();
653    let content_type = resp
654        .headers()
655        .get("content-type")
656        .and_then(|v| v.to_str().ok())
657        .unwrap_or("application/octet-stream");
658    let content_type = super::ContentType::from(content_type);
659
660    if !status.is_client_error() && !status.is_server_error() {
661        let content = resp.text().await?;
662        match content_type {
663            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
664            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RotateIssuedApiKeyResponse`"))),
665            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::RotateIssuedApiKeyResponse`")))),
666        }
667    } else {
668        let content = resp.text().await?;
669        let entity: Option<AdminRotateIssuedApiKeyError> = serde_json::from_str(&content).ok();
670        Err(Error::ResponseError(ResponseContent { status, content, entity }))
671    }
672}
673
674/// Updates metadata, scopes, or rate limits of an imported key. Supports partial updates via the update_mask query parameter (AIP-134). Omitting update_mask is equivalent to a mask of every populated field in the body. To clear a field to its zero value, list it explicitly in update_mask and leave it unset (or empty) in the body.  ```http PATCH /v2alpha1/admin/importedApiKeys/{key_id}?update_mask=name {   \"imported_api_key\": {     \"key_id\": \"{key_id}\",     \"name\": \"New name\"   } } ```
675pub async fn admin_update_imported_api_key(configuration: &configuration::Configuration, key_id: &str, admin_update_imported_api_key_request: models::AdminUpdateImportedApiKeyRequest, update_mask: Option<&str>) -> Result<models::ImportedApiKey, Error<AdminUpdateImportedApiKeyError>> {
676    // add a prefix to parameters to efficiently prevent name collisions
677    let p_path_key_id = key_id;
678    let p_body_admin_update_imported_api_key_request = admin_update_imported_api_key_request;
679    let p_query_update_mask = update_mask;
680
681    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
682    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
683
684    if let Some(ref param_value) = p_query_update_mask {
685        req_builder = req_builder.query(&[("update_mask", &param_value.to_string())]);
686    }
687    if let Some(ref user_agent) = configuration.user_agent {
688        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
689    }
690    if let Some(ref token) = configuration.bearer_access_token {
691        req_builder = req_builder.bearer_auth(token.to_owned());
692    };
693    req_builder = req_builder.json(&p_body_admin_update_imported_api_key_request);
694
695    let req = req_builder.build()?;
696    let resp = configuration.client.execute(req).await?;
697
698    let status = resp.status();
699    let content_type = resp
700        .headers()
701        .get("content-type")
702        .and_then(|v| v.to_str().ok())
703        .unwrap_or("application/octet-stream");
704    let content_type = super::ContentType::from(content_type);
705
706    if !status.is_client_error() && !status.is_server_error() {
707        let content = resp.text().await?;
708        match content_type {
709            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
710            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportedApiKey`"))),
711            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::ImportedApiKey`")))),
712        }
713    } else {
714        let content = resp.text().await?;
715        let entity: Option<AdminUpdateImportedApiKeyError> = serde_json::from_str(&content).ok();
716        Err(Error::ResponseError(ResponseContent { status, content, entity }))
717    }
718}
719
720/// Updates metadata, scopes, or rate limits of an issued key without rotating the secret. Use RotateIssuedAPIKey to change the secret.  Follows AIP-134: the request body is the IssuedAPIKey resource itself, and the update_mask query parameter names the subset of fields to apply. Omitting update_mask is equivalent to a mask of every populated field in the body. To clear a field to its zero value, list it explicitly in update_mask and leave it unset (or empty) in the body.  ```http PATCH /v2alpha1/admin/issuedApiKeys/01HQZX9VYQKJB8XQZQXQZQXQXQ?update_mask=scopes {   \"issued_api_key\": {     \"key_id\": \"01HQZX9VYQKJB8XQZQXQZQXQXQ\",     \"scopes\": [\"read\"]   } } ```
721pub async fn admin_update_issued_api_key(configuration: &configuration::Configuration, key_id: &str, admin_update_issued_api_key_request: models::AdminUpdateIssuedApiKeyRequest, update_mask: Option<&str>) -> Result<models::IssuedApiKey, Error<AdminUpdateIssuedApiKeyError>> {
722    // add a prefix to parameters to efficiently prevent name collisions
723    let p_path_key_id = key_id;
724    let p_body_admin_update_issued_api_key_request = admin_update_issued_api_key_request;
725    let p_query_update_mask = update_mask;
726
727    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
728    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
729
730    if let Some(ref param_value) = p_query_update_mask {
731        req_builder = req_builder.query(&[("update_mask", &param_value.to_string())]);
732    }
733    if let Some(ref user_agent) = configuration.user_agent {
734        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
735    }
736    if let Some(ref token) = configuration.bearer_access_token {
737        req_builder = req_builder.bearer_auth(token.to_owned());
738    };
739    req_builder = req_builder.json(&p_body_admin_update_issued_api_key_request);
740
741    let req = req_builder.build()?;
742    let resp = configuration.client.execute(req).await?;
743
744    let status = resp.status();
745    let content_type = resp
746        .headers()
747        .get("content-type")
748        .and_then(|v| v.to_str().ok())
749        .unwrap_or("application/octet-stream");
750    let content_type = super::ContentType::from(content_type);
751
752    if !status.is_client_error() && !status.is_server_error() {
753        let content = resp.text().await?;
754        match content_type {
755            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
756            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IssuedApiKey`"))),
757            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::IssuedApiKey`")))),
758        }
759    } else {
760        let content = resp.text().await?;
761        let entity: Option<AdminUpdateIssuedApiKeyError> = serde_json::from_str(&content).ok();
762        Err(Error::ResponseError(ResponseContent { status, content, entity }))
763    }
764}
765
766/// Verifies a single API key or derived token. Validates the credential's signature, expiration, and revocation status. Works with any credential type (issued keys, imported keys, JWT, macaroon). The verification result includes decoded claims and metadata — admin access only.  Cache Control (HTTP Headers):   - Cache-Control: no-cache  - Bypasses cache read, forces fresh DB lookup   - Cache-Control: no-store  - Bypasses cache read AND write (never cached)   - Pragma: no-cache         - Same as Cache-Control: no-cache (HTTP/1.0)  ```http POST /v2alpha1/admin/apiKeys:verify {   \"credential\": \"sk_live_abc123...\" } ```
767pub async fn admin_verify_api_key(configuration: &configuration::Configuration, verify_api_key_request: models::VerifyApiKeyRequest, cache_control: Option<&str>, pragma: Option<&str>) -> Result<models::VerifyApiKeyResponse, Error<AdminVerifyApiKeyError>> {
768    // add a prefix to parameters to efficiently prevent name collisions
769    let p_body_verify_api_key_request = verify_api_key_request;
770    let p_header_cache_control = cache_control;
771    let p_header_pragma = pragma;
772
773    let uri_str = format!("{}/v2alpha1/admin/apiKeys:verify", configuration.base_path);
774    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
775
776    if let Some(ref user_agent) = configuration.user_agent {
777        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
778    }
779    if let Some(param_value) = p_header_cache_control {
780        req_builder = req_builder.header("Cache-Control", param_value.to_string());
781    }
782    if let Some(param_value) = p_header_pragma {
783        req_builder = req_builder.header("Pragma", param_value.to_string());
784    }
785    if let Some(ref token) = configuration.bearer_access_token {
786        req_builder = req_builder.bearer_auth(token.to_owned());
787    };
788    req_builder = req_builder.json(&p_body_verify_api_key_request);
789
790    let req = req_builder.build()?;
791    let resp = configuration.client.execute(req).await?;
792
793    let status = resp.status();
794    let content_type = resp
795        .headers()
796        .get("content-type")
797        .and_then(|v| v.to_str().ok())
798        .unwrap_or("application/octet-stream");
799    let content_type = super::ContentType::from(content_type);
800
801    if !status.is_client_error() && !status.is_server_error() {
802        let content = resp.text().await?;
803        match content_type {
804            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
805            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifyApiKeyResponse`"))),
806            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::VerifyApiKeyResponse`")))),
807        }
808    } else {
809        let content = resp.text().await?;
810        let entity: Option<AdminVerifyApiKeyError> = serde_json::from_str(&content).ok();
811        Err(Error::ResponseError(ResponseContent { status, content, entity }))
812    }
813}
814
815/// Returns the JSON Web Key Set for token verification. Provides the public keys needed to verify JWT tokens issued by this service. Keys are loaded from configuration (file://, https://, or base64:// URIs). Follows the JWKS standard (RFC 7517).  ```http GET /v2alpha1/derivedKeys/jwks.json ```
816pub async fn get_jwks(configuration: &configuration::Configuration, ) -> Result<models::GetJwksResponse, Error<GetJwksError>> {
817
818    let uri_str = format!("{}/v2alpha1/derivedKeys/jwks.json", configuration.base_path);
819    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
820
821    if let Some(ref user_agent) = configuration.user_agent {
822        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
823    }
824
825    let req = req_builder.build()?;
826    let resp = configuration.client.execute(req).await?;
827
828    let status = resp.status();
829    let content_type = resp
830        .headers()
831        .get("content-type")
832        .and_then(|v| v.to_str().ok())
833        .unwrap_or("application/octet-stream");
834    let content_type = super::ContentType::from(content_type);
835
836    if !status.is_client_error() && !status.is_server_error() {
837        let content = resp.text().await?;
838        match content_type {
839            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
840            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetJwksResponse`"))),
841            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::GetJwksResponse`")))),
842        }
843    } else {
844        let content = resp.text().await?;
845        let entity: Option<GetJwksError> = serde_json::from_str(&content).ok();
846        Err(Error::ResponseError(ResponseContent { status, content, entity }))
847    }
848}
849
850/// Proof-of-possession variant of revocation. Lives alongside `AdminRevokeAPIKey` in this service; the `Self*` prefix on the request/response messages disambiguates from the admin variant's `RevokeAPIKeyRequest`.  Allows an API key holder to revoke their own key. The caller must provide the full API key secret as proof of possession. Supports issued API keys and imported keys. JWT and macaroon tokens cannot be self-revoked (they are stateless).  The PRIVILEGE_WITHDRAWN reason is not allowed for self-revocation (admin-only).  ```http POST /v2alpha1/apiKeys:selfRevoke {   \"credential\": \"sk_live_abc123...\",   \"reason\": \"REVOCATION_REASON_KEY_COMPROMISE\" } ```
851pub async fn revoke_api_key(configuration: &configuration::Configuration, self_revoke_api_key_request: models::SelfRevokeApiKeyRequest) -> Result<serde_json::Value, Error<RevokeApiKeyError>> {
852    // add a prefix to parameters to efficiently prevent name collisions
853    let p_body_self_revoke_api_key_request = self_revoke_api_key_request;
854
855    let uri_str = format!("{}/v2alpha1/apiKeys:selfRevoke", configuration.base_path);
856    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
857
858    if let Some(ref user_agent) = configuration.user_agent {
859        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
860    }
861    req_builder = req_builder.json(&p_body_self_revoke_api_key_request);
862
863    let req = req_builder.build()?;
864    let resp = configuration.client.execute(req).await?;
865
866    let status = resp.status();
867    let content_type = resp
868        .headers()
869        .get("content-type")
870        .and_then(|v| v.to_str().ok())
871        .unwrap_or("application/octet-stream");
872    let content_type = super::ContentType::from(content_type);
873
874    if !status.is_client_error() && !status.is_server_error() {
875        let content = resp.text().await?;
876        match content_type {
877            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
878            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
879            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
880        }
881    } else {
882        let content = resp.text().await?;
883        let entity: Option<RevokeApiKeyError> = serde_json::from_str(&content).ok();
884        Err(Error::ResponseError(ResponseContent { status, content, entity }))
885    }
886}
887