| Crates.io | gaia-client |
| lib.rs | gaia-client |
| version | 0.0.1-rc.8 |
| created_at | 2025-11-04 06:40:58.285159+00 |
| updated_at | 2025-11-23 22:26:05.57004+00 |
| description | Rust client library for Gaia secret management daemon |
| homepage | |
| repository | https://github.com/stain-win/gaia |
| max_upload_size | |
| id | 1915847 |
| size | 81,004 |
A Rust client library for interacting with the Gaia secret management daemon.
protocAdd this to your Cargo.toml:
[dependencies]
gaia-client = "0.1"
tokio = { version = "1.0", features = ["full"] }
No additional build tools required! The library ships with pre-generated protobuf code, so you don't need to install protoc or any other external dependencies.
use gaia_client::{GaiaClient, GaiaClientConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Configure the client
let config = GaiaClientConfig::new(
"localhost:50051",
"/etc/gaia/certs/ca.crt",
"/etc/gaia/certs/client.crt",
"/etc/gaia/certs/client.key",
);
// Connect to the Gaia daemon
let mut client = GaiaClient::connect(config).await?;
// Check if daemon is ready
if !client.is_unlocked().await? {
eprintln!("Daemon is locked. Please unlock it first.");
return Ok(());
}
// Fetch a secret
let secret = client.get_secret("production", "database_url").await?;
println!("Database URL: {}", secret.value);
Ok(())
}
use gaia_client::GaiaClientConfig;
let config = GaiaClientConfig::new(
"localhost:50051", // Server address
"/etc/gaia/certs/ca.crt", // CA certificate
"/etc/gaia/certs/client.crt", // Client certificate
"/etc/gaia/certs/client.key", // Client private key
);
use gaia_client::GaiaClientConfig;
// Reads from:
// - GAIA_SERVER_ADDRESS (default: "localhost:50051")
// - GAIA_CA_CERT (default: "/etc/gaia/certs/ca.crt")
// - GAIA_CLIENT_CERT (default: "/etc/gaia/certs/client.crt")
// - GAIA_CLIENT_KEY (default: "/etc/gaia/certs/client.key")
let config = GaiaClientConfig::from_env();
let config = GaiaClientConfig::new(
"gaia.example.com:50051",
"/etc/gaia/certs/ca.crt",
"/etc/gaia/certs/client.crt",
"/etc/gaia/certs/client.key",
).with_domain_name("gaia.example.com");
connect(config: GaiaClientConfig) -> Result<GaiaClient>Connects to the Gaia daemon using the provided configuration.
let mut client = GaiaClient::connect(config).await?;
get_status() -> Result<StatusResponse>Retrieves the daemon status ("locked" or "unlocked").
let status = client.get_status().await?;
println!("Status: {}", status.status);
is_unlocked() -> Result<bool>Checks if the daemon is unlocked and ready to serve secrets.
if client.is_unlocked().await? {
println!("Daemon is ready!");
}
get_secret(namespace: &str, id: &str) -> Result<Secret>Retrieves a specific secret from a namespace.
let secret = client.get_secret("production", "database_url").await?;
println!("Secret: {}", secret.value);
get_namespaces() -> Result<NamespaceResponse>Lists all namespaces accessible to this client.
let namespaces = client.get_namespaces().await?;
for ns in namespaces.namespaces {
println!("Namespace: {}", ns);
}
get_common_secrets(namespace: Option<String>) -> Result<Vec<Namespace>>Retrieves all secrets from the common area, optionally filtered by namespace.
// Get all common secrets
let all_common = client.get_common_secrets(None).await?;
// Get common secrets from specific namespace
let production_common = client.get_common_secrets(Some("production".to_string())).await?;
get_common_namespace_secrets(namespace: &str) -> Result<Vec<Secret>>Retrieves secrets from a specific namespace in the common area.
let secrets = client.get_common_namespace_secrets("production").await?;
for secret in secrets {
println!("{}: {}", secret.id, secret.value);
}
The library includes several examples in the examples/ directory:
Demonstrates basic connection and status checking:
cargo run --example simple_client
Shows how to retrieve secrets from different namespaces:
cargo run --example fetch_secrets
The library provides a comprehensive error type:
use gaia_client::GaiaError;
match client.get_secret("production", "api_key").await {
Ok(secret) => println!("API Key: {}", secret.value),
Err(GaiaError::DaemonLocked) => eprintln!("Daemon is locked"),
Err(GaiaError::SecretNotFound(ns, id)) => eprintln!("Secret {}/{} not found", ns, id),
Err(GaiaError::DaemonOffline) => eprintln!("Daemon is offline"),
Err(e) => eprintln!("Error: {}", e),
}
Before using the client, you need to:
/etc/gaia/certs/)Example certificate structure:
/etc/gaia/certs/
βββ ca.crt # CA certificate (verifies server)
βββ client.crt # Client certificate (authenticates your app)
βββ client.key # Client private key
The library works on:
protoc) - Required for buildingmacOS:
brew install protobuf
Ubuntu/Debian:
sudo apt-get install protobuf-compiler
Windows: Download from GitHub releases
The library uses Protocol Buffers for gRPC communication. The proto files are compiled automatically at build time.
cd libs/rust
cargo build --release
A Makefile is provided for common tasks:
# See all available commands
make help
# Build the library
make build
# Run tests
make test
# Run all quality checks (format, clippy, test)
make all
# Format code
make fmt
# Run clippy lints
make clippy
# Generate documentation
make doc
# Clean build artifacts
make clean
The library uses gRPC with Protocol Buffers. The proto definitions are located in ../../proto/gaia-client.proto (root of the repository).
At build time, the build.rs script automatically:
../../proto/gaia-client.prototonic-buildThis library uses pre-generated protobuf code checked into src/proto.rs, eliminating the need for protoc at build time. This makes the library easy to use as a dependency - users don't need to install any external tools.
Just add the dependency to your Cargo.toml and start using it. No protoc installation required!
If you need to regenerate the protobuf code (e.g., after updating the proto files):
Install protoc (Protocol Buffers compiler):
# macOS
brew install protobuf
# Ubuntu/Debian
sudo apt install protobuf-compiler
# Or download from: https://github.com/protocolbuffers/protobuf/releases
Regenerate the proto code:
REGENERATE_PROTO=1 cargo build --features regenerate-proto
Copy the generated code to source:
cp target/debug/build/gaia-client-*/out/gaia.rs src/proto.rs
Commit the updated src/proto.rs file
Note: The proto files are kept in sync with the main Gaia repository at ../../proto/gaia-client.proto during development, and copied to proto/ when publishing.
# Check if everything is set up correctly
make setup
# Development cycle
make dev # Quick format and check
# Before committing
make all # Full quality check
# Run examples (requires running Gaia daemon)
make example-simple
make example-fetch
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or contributions, please visit the GitHub repository.