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.40
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_get_jwks`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum AdminGetJwksError {
70    DefaultResponse(models::Status),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`admin_import_api_key`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum AdminImportApiKeyError {
78    DefaultResponse(models::Status),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`admin_issue_api_key`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum AdminIssueApiKeyError {
86    DefaultResponse(models::Status),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`admin_list_imported_api_keys`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum AdminListImportedApiKeysError {
94    DefaultResponse(models::Status),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`admin_list_issued_api_keys`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum AdminListIssuedApiKeysError {
102    DefaultResponse(models::Status),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`admin_revoke_api_key`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum AdminRevokeApiKeyError {
110    DefaultResponse(models::Status),
111    UnknownValue(serde_json::Value),
112}
113
114/// struct for typed errors of method [`admin_rotate_issued_api_key`]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[serde(untagged)]
117pub enum AdminRotateIssuedApiKeyError {
118    DefaultResponse(models::Status),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`admin_update_imported_api_key`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum AdminUpdateImportedApiKeyError {
126    DefaultResponse(models::Status),
127    UnknownValue(serde_json::Value),
128}
129
130/// struct for typed errors of method [`admin_update_issued_api_key`]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(untagged)]
133pub enum AdminUpdateIssuedApiKeyError {
134    DefaultResponse(models::Status),
135    UnknownValue(serde_json::Value),
136}
137
138/// struct for typed errors of method [`admin_verify_api_key`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum AdminVerifyApiKeyError {
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/// 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/admin/derivedKeys/jwks.json ```
407pub async fn admin_get_jwks(configuration: &configuration::Configuration, ) -> Result<models::GetJwksResponse, Error<AdminGetJwksError>> {
408
409    let uri_str = format!("{}/v2alpha1/admin/derivedKeys/jwks.json", configuration.base_path);
410    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
411
412    if let Some(ref user_agent) = configuration.user_agent {
413        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
414    }
415    if let Some(ref token) = configuration.bearer_access_token {
416        req_builder = req_builder.bearer_auth(token.to_owned());
417    };
418
419    let req = req_builder.build()?;
420    let resp = configuration.client.execute(req).await?;
421
422    let status = resp.status();
423    let content_type = resp
424        .headers()
425        .get("content-type")
426        .and_then(|v| v.to_str().ok())
427        .unwrap_or("application/octet-stream");
428    let content_type = super::ContentType::from(content_type);
429
430    if !status.is_client_error() && !status.is_server_error() {
431        let content = resp.text().await?;
432        match content_type {
433            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
434            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetJwksResponse`"))),
435            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`")))),
436        }
437    } else {
438        let content = resp.text().await?;
439        let entity: Option<AdminGetJwksError> = serde_json::from_str(&content).ok();
440        Err(Error::ResponseError(ResponseContent { status, content, entity }))
441    }
442}
443
444/// 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\" } ```
445pub async fn admin_import_api_key(configuration: &configuration::Configuration, import_api_key_request: models::ImportApiKeyRequest) -> Result<models::ImportedApiKey, Error<AdminImportApiKeyError>> {
446    // add a prefix to parameters to efficiently prevent name collisions
447    let p_body_import_api_key_request = import_api_key_request;
448
449    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys", configuration.base_path);
450    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
451
452    if let Some(ref user_agent) = configuration.user_agent {
453        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
454    }
455    if let Some(ref token) = configuration.bearer_access_token {
456        req_builder = req_builder.bearer_auth(token.to_owned());
457    };
458    req_builder = req_builder.json(&p_body_import_api_key_request);
459
460    let req = req_builder.build()?;
461    let resp = configuration.client.execute(req).await?;
462
463    let status = resp.status();
464    let content_type = resp
465        .headers()
466        .get("content-type")
467        .and_then(|v| v.to_str().ok())
468        .unwrap_or("application/octet-stream");
469    let content_type = super::ContentType::from(content_type);
470
471    if !status.is_client_error() && !status.is_server_error() {
472        let content = resp.text().await?;
473        match content_type {
474            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
475            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportedApiKey`"))),
476            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`")))),
477        }
478    } else {
479        let content = resp.text().await?;
480        let entity: Option<AdminImportApiKeyError> = serde_json::from_str(&content).ok();
481        Err(Error::ResponseError(ResponseContent { status, content, entity }))
482    }
483}
484
485/// 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\" } ```
486pub async fn admin_issue_api_key(configuration: &configuration::Configuration, issue_api_key_request: models::IssueApiKeyRequest) -> Result<models::IssueApiKeyResponse, Error<AdminIssueApiKeyError>> {
487    // add a prefix to parameters to efficiently prevent name collisions
488    let p_body_issue_api_key_request = issue_api_key_request;
489
490    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys", configuration.base_path);
491    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
492
493    if let Some(ref user_agent) = configuration.user_agent {
494        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
495    }
496    if let Some(ref token) = configuration.bearer_access_token {
497        req_builder = req_builder.bearer_auth(token.to_owned());
498    };
499    req_builder = req_builder.json(&p_body_issue_api_key_request);
500
501    let req = req_builder.build()?;
502    let resp = configuration.client.execute(req).await?;
503
504    let status = resp.status();
505    let content_type = resp
506        .headers()
507        .get("content-type")
508        .and_then(|v| v.to_str().ok())
509        .unwrap_or("application/octet-stream");
510    let content_type = super::ContentType::from(content_type);
511
512    if !status.is_client_error() && !status.is_server_error() {
513        let content = resp.text().await?;
514        match content_type {
515            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
516            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IssueApiKeyResponse`"))),
517            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`")))),
518        }
519    } else {
520        let content = resp.text().await?;
521        let entity: Option<AdminIssueApiKeyError> = serde_json::from_str(&content).ok();
522        Err(Error::ResponseError(ResponseContent { status, content, entity }))
523    }
524}
525
526/// 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 ```
527pub 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>> {
528    // add a prefix to parameters to efficiently prevent name collisions
529    let p_query_page_size = page_size;
530    let p_query_page_token = page_token;
531    let p_query_filter = filter;
532
533    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys", configuration.base_path);
534    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
535
536    if let Some(ref param_value) = p_query_page_size {
537        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
538    }
539    if let Some(ref param_value) = p_query_page_token {
540        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
541    }
542    if let Some(ref param_value) = p_query_filter {
543        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
544    }
545    if let Some(ref user_agent) = configuration.user_agent {
546        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
547    }
548    if let Some(ref token) = configuration.bearer_access_token {
549        req_builder = req_builder.bearer_auth(token.to_owned());
550    };
551
552    let req = req_builder.build()?;
553    let resp = configuration.client.execute(req).await?;
554
555    let status = resp.status();
556    let content_type = resp
557        .headers()
558        .get("content-type")
559        .and_then(|v| v.to_str().ok())
560        .unwrap_or("application/octet-stream");
561    let content_type = super::ContentType::from(content_type);
562
563    if !status.is_client_error() && !status.is_server_error() {
564        let content = resp.text().await?;
565        match content_type {
566            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
567            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListImportedApiKeysResponse`"))),
568            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`")))),
569        }
570    } else {
571        let content = resp.text().await?;
572        let entity: Option<AdminListImportedApiKeysError> = serde_json::from_str(&content).ok();
573        Err(Error::ResponseError(ResponseContent { status, content, entity }))
574    }
575}
576
577/// 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 ```
578pub 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>> {
579    // add a prefix to parameters to efficiently prevent name collisions
580    let p_query_page_size = page_size;
581    let p_query_page_token = page_token;
582    let p_query_filter = filter;
583
584    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys", configuration.base_path);
585    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
586
587    if let Some(ref param_value) = p_query_page_size {
588        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
589    }
590    if let Some(ref param_value) = p_query_page_token {
591        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
592    }
593    if let Some(ref param_value) = p_query_filter {
594        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
595    }
596    if let Some(ref user_agent) = configuration.user_agent {
597        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
598    }
599    if let Some(ref token) = configuration.bearer_access_token {
600        req_builder = req_builder.bearer_auth(token.to_owned());
601    };
602
603    let req = req_builder.build()?;
604    let resp = configuration.client.execute(req).await?;
605
606    let status = resp.status();
607    let content_type = resp
608        .headers()
609        .get("content-type")
610        .and_then(|v| v.to_str().ok())
611        .unwrap_or("application/octet-stream");
612    let content_type = super::ContentType::from(content_type);
613
614    if !status.is_client_error() && !status.is_server_error() {
615        let content = resp.text().await?;
616        match content_type {
617            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
618            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListIssuedApiKeysResponse`"))),
619            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`")))),
620        }
621    } else {
622        let content = resp.text().await?;
623        let entity: Option<AdminListIssuedApiKeysError> = serde_json::from_str(&content).ok();
624        Err(Error::ResponseError(ResponseContent { status, content, entity }))
625    }
626}
627
628/// 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\" } ```
629pub 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>> {
630    // add a prefix to parameters to efficiently prevent name collisions
631    let p_path_key_id = key_id;
632    let p_body_admin_revoke_api_key_body = admin_revoke_api_key_body;
633
634    let uri_str = format!("{}/v2alpha1/admin/apiKeys/{key_id}:revoke", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
635    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
636
637    if let Some(ref user_agent) = configuration.user_agent {
638        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
639    }
640    if let Some(ref token) = configuration.bearer_access_token {
641        req_builder = req_builder.bearer_auth(token.to_owned());
642    };
643    req_builder = req_builder.json(&p_body_admin_revoke_api_key_body);
644
645    let req = req_builder.build()?;
646    let resp = configuration.client.execute(req).await?;
647
648    let status = resp.status();
649    let content_type = resp
650        .headers()
651        .get("content-type")
652        .and_then(|v| v.to_str().ok())
653        .unwrap_or("application/octet-stream");
654    let content_type = super::ContentType::from(content_type);
655
656    if !status.is_client_error() && !status.is_server_error() {
657        let content = resp.text().await?;
658        match content_type {
659            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
660            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
661            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`")))),
662        }
663    } else {
664        let content = resp.text().await?;
665        let entity: Option<AdminRevokeApiKeyError> = serde_json::from_str(&content).ok();
666        Err(Error::ResponseError(ResponseContent { status, content, entity }))
667    }
668}
669
670/// 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\"] } ```
671pub 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>> {
672    // add a prefix to parameters to efficiently prevent name collisions
673    let p_path_key_id = key_id;
674    let p_body_admin_rotate_issued_api_key_body = admin_rotate_issued_api_key_body;
675
676    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys/{key_id}:rotate", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
677    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
678
679    if let Some(ref user_agent) = configuration.user_agent {
680        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
681    }
682    if let Some(ref token) = configuration.bearer_access_token {
683        req_builder = req_builder.bearer_auth(token.to_owned());
684    };
685    req_builder = req_builder.json(&p_body_admin_rotate_issued_api_key_body);
686
687    let req = req_builder.build()?;
688    let resp = configuration.client.execute(req).await?;
689
690    let status = resp.status();
691    let content_type = resp
692        .headers()
693        .get("content-type")
694        .and_then(|v| v.to_str().ok())
695        .unwrap_or("application/octet-stream");
696    let content_type = super::ContentType::from(content_type);
697
698    if !status.is_client_error() && !status.is_server_error() {
699        let content = resp.text().await?;
700        match content_type {
701            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
702            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RotateIssuedApiKeyResponse`"))),
703            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`")))),
704        }
705    } else {
706        let content = resp.text().await?;
707        let entity: Option<AdminRotateIssuedApiKeyError> = serde_json::from_str(&content).ok();
708        Err(Error::ResponseError(ResponseContent { status, content, entity }))
709    }
710}
711
712/// 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\"   } } ```
713pub 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>> {
714    // add a prefix to parameters to efficiently prevent name collisions
715    let p_path_key_id = key_id;
716    let p_body_admin_update_imported_api_key_request = admin_update_imported_api_key_request;
717    let p_query_update_mask = update_mask;
718
719    let uri_str = format!("{}/v2alpha1/admin/importedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
720    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
721
722    if let Some(ref param_value) = p_query_update_mask {
723        req_builder = req_builder.query(&[("update_mask", &param_value.to_string())]);
724    }
725    if let Some(ref user_agent) = configuration.user_agent {
726        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
727    }
728    if let Some(ref token) = configuration.bearer_access_token {
729        req_builder = req_builder.bearer_auth(token.to_owned());
730    };
731    req_builder = req_builder.json(&p_body_admin_update_imported_api_key_request);
732
733    let req = req_builder.build()?;
734    let resp = configuration.client.execute(req).await?;
735
736    let status = resp.status();
737    let content_type = resp
738        .headers()
739        .get("content-type")
740        .and_then(|v| v.to_str().ok())
741        .unwrap_or("application/octet-stream");
742    let content_type = super::ContentType::from(content_type);
743
744    if !status.is_client_error() && !status.is_server_error() {
745        let content = resp.text().await?;
746        match content_type {
747            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
748            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportedApiKey`"))),
749            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`")))),
750        }
751    } else {
752        let content = resp.text().await?;
753        let entity: Option<AdminUpdateImportedApiKeyError> = serde_json::from_str(&content).ok();
754        Err(Error::ResponseError(ResponseContent { status, content, entity }))
755    }
756}
757
758/// 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\"]   } } ```
759pub 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>> {
760    // add a prefix to parameters to efficiently prevent name collisions
761    let p_path_key_id = key_id;
762    let p_body_admin_update_issued_api_key_request = admin_update_issued_api_key_request;
763    let p_query_update_mask = update_mask;
764
765    let uri_str = format!("{}/v2alpha1/admin/issuedApiKeys/{key_id}", configuration.base_path, key_id=crate::apis::urlencode(p_path_key_id));
766    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
767
768    if let Some(ref param_value) = p_query_update_mask {
769        req_builder = req_builder.query(&[("update_mask", &param_value.to_string())]);
770    }
771    if let Some(ref user_agent) = configuration.user_agent {
772        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
773    }
774    if let Some(ref token) = configuration.bearer_access_token {
775        req_builder = req_builder.bearer_auth(token.to_owned());
776    };
777    req_builder = req_builder.json(&p_body_admin_update_issued_api_key_request);
778
779    let req = req_builder.build()?;
780    let resp = configuration.client.execute(req).await?;
781
782    let status = resp.status();
783    let content_type = resp
784        .headers()
785        .get("content-type")
786        .and_then(|v| v.to_str().ok())
787        .unwrap_or("application/octet-stream");
788    let content_type = super::ContentType::from(content_type);
789
790    if !status.is_client_error() && !status.is_server_error() {
791        let content = resp.text().await?;
792        match content_type {
793            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
794            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IssuedApiKey`"))),
795            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`")))),
796        }
797    } else {
798        let content = resp.text().await?;
799        let entity: Option<AdminUpdateIssuedApiKeyError> = serde_json::from_str(&content).ok();
800        Err(Error::ResponseError(ResponseContent { status, content, entity }))
801    }
802}
803
804/// 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...\" } ```
805pub 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>> {
806    // add a prefix to parameters to efficiently prevent name collisions
807    let p_body_verify_api_key_request = verify_api_key_request;
808    let p_header_cache_control = cache_control;
809    let p_header_pragma = pragma;
810
811    let uri_str = format!("{}/v2alpha1/admin/apiKeys:verify", configuration.base_path);
812    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
813
814    if let Some(ref user_agent) = configuration.user_agent {
815        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
816    }
817    if let Some(param_value) = p_header_cache_control {
818        req_builder = req_builder.header("Cache-Control", param_value.to_string());
819    }
820    if let Some(param_value) = p_header_pragma {
821        req_builder = req_builder.header("Pragma", param_value.to_string());
822    }
823    if let Some(ref token) = configuration.bearer_access_token {
824        req_builder = req_builder.bearer_auth(token.to_owned());
825    };
826    req_builder = req_builder.json(&p_body_verify_api_key_request);
827
828    let req = req_builder.build()?;
829    let resp = configuration.client.execute(req).await?;
830
831    let status = resp.status();
832    let content_type = resp
833        .headers()
834        .get("content-type")
835        .and_then(|v| v.to_str().ok())
836        .unwrap_or("application/octet-stream");
837    let content_type = super::ContentType::from(content_type);
838
839    if !status.is_client_error() && !status.is_server_error() {
840        let content = resp.text().await?;
841        match content_type {
842            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
843            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifyApiKeyResponse`"))),
844            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`")))),
845        }
846    } else {
847        let content = resp.text().await?;
848        let entity: Option<AdminVerifyApiKeyError> = serde_json::from_str(&content).ok();
849        Err(Error::ResponseError(ResponseContent { status, content, entity }))
850    }
851}
852
853/// 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\" } ```
854pub async fn revoke_api_key(configuration: &configuration::Configuration, self_revoke_api_key_request: models::SelfRevokeApiKeyRequest) -> Result<serde_json::Value, Error<RevokeApiKeyError>> {
855    // add a prefix to parameters to efficiently prevent name collisions
856    let p_body_self_revoke_api_key_request = self_revoke_api_key_request;
857
858    let uri_str = format!("{}/v2alpha1/apiKeys:selfRevoke", configuration.base_path);
859    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
860
861    if let Some(ref user_agent) = configuration.user_agent {
862        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
863    }
864    req_builder = req_builder.json(&p_body_self_revoke_api_key_request);
865
866    let req = req_builder.build()?;
867    let resp = configuration.client.execute(req).await?;
868
869    let status = resp.status();
870    let content_type = resp
871        .headers()
872        .get("content-type")
873        .and_then(|v| v.to_str().ok())
874        .unwrap_or("application/octet-stream");
875    let content_type = super::ContentType::from(content_type);
876
877    if !status.is_client_error() && !status.is_server_error() {
878        let content = resp.text().await?;
879        match content_type {
880            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
881            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
882            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`")))),
883        }
884    } else {
885        let content = resp.text().await?;
886        let entity: Option<RevokeApiKeyError> = serde_json::from_str(&content).ok();
887        Err(Error::ResponseError(ResponseContent { status, content, entity }))
888    }
889}
890