| Crates.io | vaultarq |
| lib.rs | vaultarq |
| version | 0.1.11 |
| created_at | 2025-05-11 20:19:45.071065+00 |
| updated_at | 2025-05-11 23:24:39.881237+00 |
| description | Rust SDK for Vaultarq - The developer-first, invisible secrets manager |
| homepage | https://github.com/Vaultarq/vaultarq |
| repository | https://github.com/Vaultarq/vaultarq |
| max_upload_size | |
| id | 1669688 |
| size | 19,694 |
Rust SDK for Vaultarq - The developer-first, invisible secrets manager
This SDK provides a seamless integration with Vaultarq for Rust applications, automatically loading secrets from your Vaultarq vault into your application's environment variables.
Add this to your Cargo.toml:
[dependencies]
vaultarq = "0.1.0"
use vaultarq::init;
fn main() {
// Load secrets into environment variables
init().unwrap();
// Now use secrets from environment
println!("API_KEY: {}", std::env::var("API_KEY").unwrap_or_default());
}
use vaultarq::{Config, init_with_config};
fn main() {
// Configure options
let config = Config::new()
.with_environment("prod")
.with_bin_path("/usr/local/bin/vaultarq")
.with_throw_if_not_found(true);
// Load secrets with custom config
init_with_config(&config).unwrap();
}
use vaultarq::{init, is_available};
fn main() {
// Check if Vaultarq is available
if is_available() {
init().unwrap();
} else {
println!("Vaultarq not found, using fallback");
// ... your fallback logic
}
}
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use vaultarq::init;
async fn index() -> impl Responder {
let db_name = std::env::var("DB_NAME").unwrap_or_else(|_| "unknown".to_string());
HttpResponse::Ok().body(format!("Connected to database: {}", db_name))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Load secrets before starting the server
init().unwrap_or_else(|e| {
eprintln!("Failed to load secrets: {}", e);
// Continue anyway
});
HttpServer::new(|| {
App::new()
.route("/", web::get().to(index))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
init() -> Result<(), Error>Loads secrets from the Vaultarq vault into environment variables using default configuration.
init_with_config(config: &Config) -> Result<(), Error>Loads secrets from the Vaultarq vault into environment variables using custom configuration.
is_available() -> boolChecks if Vaultarq is installed and accessible.
ConfigConfiguration struct for customizing how secrets are loaded.
new() -> Config: Creates a new configuration with default valueswith_bin_path(path: &str) -> Self: Sets the path to the Vaultarq executablewith_throw_if_not_found(throw: bool) -> Self: Sets whether to throw an error if Vaultarq is not foundwith_environment(env: &str) -> Self: Sets the environment to load secrets fromwith_format(format: Format) -> Self: Sets the format to export secrets inFormatEnum for specifying the export format:
Format::Bash (default): Export as export KEY="VALUE" statementsFormat::Dotenv: Export as KEY=VALUE statementsFormat::Json: Export as JSON objectMIT