Expand description
§KeyEnv Rust SDK
Official Rust SDK for KeyEnv - Secrets management made simple.
§Quick Start
use keyenv::KeyEnv;
use std::env;
#[tokio::main]
async fn main() -> Result<(), keyenv::Error> {
let client = KeyEnv::builder()
.token(env::var("KEYENV_TOKEN").expect("KEYENV_TOKEN not set"))
.build()?;
// Load secrets into environment
client.load_env("your-project-id", "production").await?;
println!("{}", env::var("DATABASE_URL").unwrap());
Ok(())
}§Loading Secrets
§Load into Environment
let count = client.load_env("project-id", "production").await?;
println!("Loaded {} secrets", count);§Export as HashMap
let secrets = client.export_secrets_as_map("project-id", "production").await?;
println!("{}", secrets.get("DATABASE_URL").unwrap());§Managing Secrets
// Get a secret
let secret = client.get_secret("project-id", "production", "DATABASE_URL").await?;
println!("{}", secret.value);
// Set a secret
client.set_secret("project-id", "production", "API_KEY", "sk_live_...").await?;
// Delete a secret
client.delete_secret("project-id", "production", "OLD_KEY").await?;§Error Handling
use keyenv::{KeyEnv, Error};
match client.get_secret("project-id", "production", "MISSING_KEY").await {
Ok(secret) => println!("{}", secret.value),
Err(Error::Api { status, message, .. }) => {
match status {
401 => eprintln!("Invalid or expired token"),
403 => eprintln!("Access denied"),
404 => eprintln!("Secret not found"),
_ => eprintln!("Error {}: {}", status, message),
}
}
Err(e) => eprintln!("Error: {}", e),
}§Caching
Enable caching for better performance in serverless environments:
use keyenv::KeyEnv;
use std::time::Duration;
let client = KeyEnv::builder()
.token("your-token")
.cache_ttl(Duration::from_secs(300)) // 5 minutes
.build()?;Structs§
- Bulk
Import Options - Options for bulk import operations.
- Bulk
Import Result - Result of a bulk import operation.
- Current
User Response - Response containing current user or service token information.
- Default
Permission - Default permission settings for an environment.
- Environment
- An environment within a project.
- KeyEnv
- KeyEnv API client.
- KeyEnv
Builder - Builder for creating a KeyEnv client.
- MyPermissions
Response - Response containing the current user’s permissions.
- Permission
- A permission for an environment.
- Permission
Input - Input for setting a permission.
- Project
- A KeyEnv project.
- Secret
- A secret’s metadata without the value.
- Secret
History - Historical version of a secret.
- Secret
Input - Input for creating or importing a secret.
- Secret
With Inheritance - A secret with inheritance information.
- Secret
With Value - A secret including its decrypted value.
- Secret
With Value AndInheritance - A secret with value and inheritance information.
- Service
Token - Information about a service token.
- Team
- A team.
- User
- A KeyEnv user.
Enums§
- Error
- Error type for KeyEnv SDK operations.
Constants§
- DEFAULT_
BASE_ URL - Default API base URL.
- DEFAULT_
TIMEOUT - Default request timeout.
- VERSION
- SDK version.
Type Aliases§
- Result
- Result type alias for KeyEnv operations.