vaultrs
An asynchronous Rust client library for the Hashicorp Vault API
The following features are currently supported:
See something missing? Open an issue.
Installation
Add vaultrs as a depdendency to your cargo.toml:
[dependencies]
vaultrs = "0.5.2"
Usage
Basic
The client is used to configure the connection to Vault and is required to be passed to all API calls for execution. Behind the scenes it uses an asynchronous client from Reqwest for communicating to Vault.
use ;
// Create a client
let client = new.unwrap;
Secrets
The library currently supports all operations available for version 2 of the key/value store.
use ;
use kv2;
// Create and read secrets
let secret = MySecret ;
set.await;
let secret: MySecret = read.await.unwrap;
println! // "secret"
PKI
The library currently supports all operations available for the PKI secrets engine.
use GenerateCertificateRequest;
use cert;
// Generate a certificate using the PKI backend
let cert = generate.await.unwrap;
println! // "{PEM encoded certificate}"
Wrapping
All requests implement the ability to be wrapped. These can be passed in your application internally before being unwrapped.
use ResponseWrapper;
use ListMountsRequest;
let endpoint = builder.build.unwrap;
let wrap_resp = endpoint.wrap.await; // Wrapped response
assert!;
let wrap_resp = wrap_resp.unwrap; // Unwrap Result<>
let info = wrap_resp.lookup.await; // Check status of this wrapped response
assert!;
let unwrap_resp = wrap_resp.unwrap.await; // Unwrap the response
assert!;
let info = wrap_resp.lookup.await; // Error: response already unwrapped
assert!;
Error Handling
All errors generated by this crate are wrapped in the ClientError enum
provided by the crate. API warninings are automatically captured via log and
API errors are captured and returned as their own variant. Connection related
errors from rusify are wrapped and returned as a single variant.
Testing
See the the tests directory for tests. Run tests with cargo test.
Note: All tests rely on bringing up a local Vault development server using Docker. The Docker CLI must be installed on the machine running the tests and you must have permission to start new containers.
Contributing
Check out the issues for items neeeding attention or submit your own and then:
- Fork the repo (https://github.com/jmgilman/vaultrs/fork)
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request
See CONTRIBUTING for extensive documentation on the architecture of this library and how to add additional functionality to it.