pub struct ApiKeyHandler { /* private fields */ }
Expand description
Handler for API key operations
Implementations§
Source§impl ApiKeyHandler
impl ApiKeyHandler
Sourcepub fn new(client: FilesClient) -> Self
pub fn new(client: FilesClient) -> Self
Creates a new ApiKeyHandler
Sourcepub async fn list(
&self,
user_id: Option<i64>,
cursor: Option<String>,
per_page: Option<i32>,
) -> Result<(Vec<ApiKeyEntity>, PaginationInfo)>
pub async fn list( &self, user_id: Option<i64>, cursor: Option<String>, per_page: Option<i32>, ) -> Result<(Vec<ApiKeyEntity>, PaginationInfo)>
List API keys
Returns a paginated list of API keys with usage information and metadata.
§Arguments
user_id
- Filter by specific user ID (None for all users)cursor
- Pagination cursor from previous responseper_page
- Number of results per page (max 10,000)
§Returns
A tuple containing:
- Vector of
ApiKeyEntity
objects PaginationInfo
with cursors for next/previous pages
§Example
use files_sdk::{FilesClient, ApiKeyHandler};
let client = FilesClient::builder().api_key("key").build()?;
let handler = ApiKeyHandler::new(client);
// List all API keys
let (keys, pagination) = handler.list(None, None, Some(50)).await?;
for key in keys {
println!("{}: Created {} - Last used {}",
key.name.unwrap_or_default(),
key.created_at.unwrap_or_default(),
key.last_use_at.unwrap_or_default());
}
// Get keys for specific user
let (user_keys, _) = handler.list(Some(12345), None, None).await?;
Sourcepub async fn get(&self, id: i64) -> Result<ApiKeyEntity>
pub async fn get(&self, id: i64) -> Result<ApiKeyEntity>
Get details of a specific API key
§Arguments
id
- API Key ID
§Returns
An ApiKeyEntity
with key details (note: the actual key value is not included)
§Example
use files_sdk::{FilesClient, ApiKeyHandler};
let client = FilesClient::builder().api_key("key").build()?;
let handler = ApiKeyHandler::new(client);
let key = handler.get(12345).await?;
println!("Key name: {}", key.name.unwrap_or_default());
println!("Expires: {}", key.expires_at.unwrap_or_default());
Sourcepub async fn create(
&self,
name: Option<&str>,
description: Option<&str>,
expires_at: Option<&str>,
permission_set: Option<&str>,
) -> Result<ApiKeyEntity>
pub async fn create( &self, name: Option<&str>, description: Option<&str>, expires_at: Option<&str>, permission_set: Option<&str>, ) -> Result<ApiKeyEntity>
Create a new API key
Generates a new API key for programmatic access. The key value is only returned once during creation - save it securely immediately.
§Arguments
name
- Descriptive name for the keydescription
- Detailed description of key purposeexpires_at
- ISO 8601 expiration timestamp (e.g., “2025-12-31T23:59:59Z”)permission_set
- Named permission set to limit key capabilities
§Returns
An ApiKeyEntity
with the key
field containing the actual API key.
This is the only time the key value will be visible.
§Example
use files_sdk::{FilesClient, ApiKeyHandler};
let client = FilesClient::builder().api_key("key").build()?;
let handler = ApiKeyHandler::new(client);
// Create key with expiration
let key = handler.create(
Some("CI/CD Pipeline Key"),
Some("For automated deployments"),
Some("2025-12-31T23:59:59Z"),
None
).await?;
// CRITICAL: Save this key now - it won't be shown again!
println!("API Key: {}", key.key.unwrap());
println!("Store this securely in your CI/CD secrets");
Sourcepub async fn update(
&self,
id: i64,
name: Option<&str>,
description: Option<&str>,
expires_at: Option<&str>,
) -> Result<ApiKeyEntity>
pub async fn update( &self, id: i64, name: Option<&str>, description: Option<&str>, expires_at: Option<&str>, ) -> Result<ApiKeyEntity>
Update an API key’s metadata
Modifies key information such as name, description, or expiration. The actual key value cannot be changed.
§Arguments
id
- API Key ID to updatename
- New descriptive namedescription
- New descriptionexpires_at
- New expiration timestamp
§Returns
The updated ApiKeyEntity
§Example
use files_sdk::{FilesClient, ApiKeyHandler};
let client = FilesClient::builder().api_key("key").build()?;
let handler = ApiKeyHandler::new(client);
// Extend expiration date
let key = handler.update(
12345,
None,
None,
Some("2026-12-31T23:59:59Z")
).await?;
Sourcepub async fn delete(&self, id: i64) -> Result<()>
pub async fn delete(&self, id: i64) -> Result<()>
Delete an API key permanently
Revokes the API key immediately. Any requests using this key will fail. This operation cannot be undone.
§Arguments
id
- API Key ID to delete
§Example
use files_sdk::{FilesClient, ApiKeyHandler};
let client = FilesClient::builder().api_key("key").build()?;
let handler = ApiKeyHandler::new(client);
// Revoke compromised or unused key
handler.delete(12345).await?;
println!("API key revoked successfully");
Trait Implementations§
Source§impl Clone for ApiKeyHandler
impl Clone for ApiKeyHandler
Source§fn clone(&self) -> ApiKeyHandler
fn clone(&self) -> ApiKeyHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more