Skip to main content

mesa_dev/client/
api_keys.rs

1use crate::low_level::apis::{admin_api, Error};
2use crate::models;
3
4use super::OrgClient;
5
6/// Client for API key management (`/{org}/api-keys`).
7#[derive(Clone, Debug)]
8pub struct ApiKeysClient<'a> {
9    pub(super) org: &'a OrgClient<'a>,
10}
11
12impl ApiKeysClient<'_> {
13    /// List all API keys (key values are not returned).
14    ///
15    /// # Errors
16    ///
17    /// Returns an error if the API request fails.
18    #[tracing::instrument(skip(self), fields(org = self.org.org), err(Debug))]
19    pub async fn list(
20        &self,
21    ) -> Result<models::GetByOrgApiKeys200Response, Error<admin_api::GetByOrgApiKeysError>> {
22        admin_api::get_by_org_api_keys(self.org.config, self.org.org).await
23    }
24
25    /// Create a new API key.
26    ///
27    /// # Errors
28    ///
29    /// Returns an error if the API request fails.
30    #[tracing::instrument(skip(self, request), fields(org = self.org.org), err(Debug))]
31    pub async fn create(
32        &self,
33        request: models::PostByOrgApiKeysRequest,
34    ) -> Result<models::PostByOrgApiKeys201Response, Error<admin_api::PostByOrgApiKeysError>> {
35        admin_api::post_by_org_api_keys(self.org.config, self.org.org, Some(request)).await
36    }
37
38    /// Revoke an API key by its ID.
39    ///
40    /// # Errors
41    ///
42    /// Returns an error if the API request fails.
43    #[tracing::instrument(skip(self), fields(org = self.org.org), err(Debug))]
44    pub async fn revoke(
45        &self,
46        id: &str,
47    ) -> Result<
48        models::DeleteByOrgApiKeysById200Response,
49        Error<admin_api::DeleteByOrgApiKeysByIdError>,
50    > {
51        admin_api::delete_by_org_api_keys_by_id(self.org.config, id, self.org.org).await
52    }
53}