Skip to main content

grow_hashicorp_vault/
lib.rs

1// Skeleton created by sdk-kit 0.1.0; owned by this repository (edit freely).
2//! # grow-hashicorp-vault
3//!
4//! Rust SDK for [HashiCorp Vault](https://grow-codes-packages.github.io/hashicorp-vault/) by
5//! Grow Codes: one async client (tokio) for auth, KV v1/v2, transit, dynamic database
6//! credentials with a lease manager, PKI, policies and mounts, response wrapping,
7//! [capabilities](Sys::capabilities_self) checks, Enterprise
8//! [namespaces](VaultClient::with_namespace) and the Grow
9//! [`SecretsProvider`](secrets::SecretsProvider) over KV.
10//!
11//! Not affiliated with or endorsed by HashiCorp, Inc. or IBM; Vault is a trademark of
12//! HashiCorp, Inc.
13//!
14//! ```no_run
15//! # async fn demo() -> grow_hashicorp_vault::Result<()> {
16//! use grow_hashicorp_vault::secrets::SecretsProvider;
17//! use grow_hashicorp_vault::{VaultClient, VaultConfig};
18//!
19//! // explicit > GROW_HASHICORP_VAULT_* > VAULT_* > defaults
20//! let client = VaultClient::new(VaultConfig::from_env()?)?;
21//! println!("healthy: {}", client.health().await?.healthy);
22//!
23//! // KV v2 (auto-detected per mount)
24//! let kv = client.kv().await?;
25//! kv.write("app/db", serde_json::json!({"password": "s3cr3t"}), None).await?;
26//! let secret = kv.read("app/db", None).await?;
27//! assert_eq!(secret.data["password"], "s3cr3t");
28//!
29//! // transit
30//! let ct = client.transit().encrypt("app-key", b"hello", None).await?;
31//! let pt = client.transit().decrypt("app-key", &ct.ciphertext, None).await?;
32//! assert_eq!(pt, b"hello");
33//!
34//! // the Grow SecretsProvider over KV
35//! let secrets = client.secrets();
36//! secrets.set("api-key", "abc123".into(), None).await?;
37//! assert_eq!(secrets.get_string("api-key", None).await?.as_deref(), Some("abc123"));
38//!
39//! client.close().await;
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! Features: `blocking` (a blocking client), `testing` (in-memory fakes, the conformance
45//! runner and the [`testing::init`] / [`testing::unseal`] server lifecycle helpers).
46#![cfg_attr(docsrs, feature(doc_cfg))]
47
48pub mod core;
49
50mod api;
51mod auth;
52mod client;
53mod config;
54mod database;
55mod kv;
56mod lease;
57mod pki;
58mod provider;
59mod renew;
60mod sys;
61mod transit;
62mod wrapping;
63
64#[cfg(feature = "blocking")]
65#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
66pub mod blocking;
67
68// The generated test support (`src/testing/mod.rs`, owned by sdk-kit) is compiled as a
69// private module and re-exported together with the service-owned server lifecycle helpers
70// (`init`, `unseal`, `seal`, ...), so `grow_hashicorp_vault::testing` matches the `testing` module of
71// the other four languages without editing the generated file.
72#[cfg(feature = "testing")]
73#[path = "testing/mod.rs"]
74mod testing_generated;
75
76#[cfg(feature = "testing")]
77mod operator;
78
79/// Test support (feature `testing`): in-memory fakes, the conformance runner (SPEC ยง6) and
80/// the Vault server lifecycle helpers ([`testing::init`], [`testing::unseal`],
81/// [`testing::seal`], [`testing::init_status`], [`testing::wait_for_active`]) used by test
82/// fixtures and bootstrap scripts.
83///
84/// ```no_run
85/// # async fn demo() -> grow_hashicorp_vault::Result<()> {
86/// use grow_hashicorp_vault::testing::{self, InitOptions};
87/// use grow_hashicorp_vault::{VaultClient, VaultConfig};
88///
89/// let client = VaultClient::new(VaultConfig::builder().url("http://hashicorp-vault:8200").build()?)?;
90/// if !testing::init_status(&client).await? {
91///     let init = testing::init(&client, &InitOptions::default()).await?;
92///     testing::unseal(&client, init.keys[0].expose_secret()).await?;
93///     client.set_token(Some(init.root_token.clone()));
94/// }
95/// testing::wait_for_active(&client, std::time::Duration::from_secs(30)).await?;
96/// # Ok(())
97/// # }
98/// ```
99#[cfg(feature = "testing")]
100#[cfg_attr(docsrs, doc(cfg(feature = "testing")))]
101pub mod testing {
102    pub use crate::operator::{
103        init, init_status, seal, unseal, unseal_reset, wait_for_active, InitOptions, InitResult,
104    };
105    pub use crate::testing_generated::*;
106}
107
108pub mod secrets;
109
110pub use crate::core::{Error, ErrorCode, HealthStatus, Result, RetryPolicy, Secret};
111
112pub use crate::config::{DEFAULT_KV_MOUNT, DEFAULT_URL, DEFAULT_VALUE_FIELD};
113
114pub use crate::client::VaultClient;
115
116pub use crate::config::VaultConfig;
117
118pub use crate::config::VaultConfigBuilder;
119
120pub use crate::auth::{
121    AppRoleAuth, Auth, AuthInfo, AuthMethod, JwtAuth, KubernetesAuth, TokenAuth,
122    TokenCreateOptions, TokenInfo, UserpassAuth, DEFAULT_KUBERNETES_JWT_PATH,
123};
124pub use crate::database::{Database, DatabaseConnectionConfig, DatabaseRole, Lease};
125pub use crate::kv::{Kv, KvMetadata, KvMetadataOptions, KvSecret, KvV1, KvV2, KvVersionMetadata};
126pub use crate::lease::{
127    LeaseInfo, LeaseLookup, LeaseManager, ManageOptions, ManagedLease, OnLeaseError, OnLeaseExpire,
128    OnLeaseRenew,
129};
130pub use crate::pki::{
131    Certificate, CertificateInfo, IssueOptions, Pki, Revocation, TidyOptions, TidyStatus,
132};
133pub use crate::provider::{KvSecretsProvider, SecretsProviderOptions};
134pub use crate::renew::{OnExpire, OnRenew, OnRenewError, TokenRenewer, TokenRenewerOptions};
135pub use crate::sys::{
136    capability, AppRoleOptions, Capabilities, HealthResponse, LeaderStatus, MountInfo,
137    MountOptions, Policy, SealStatus, SecretId, SecretIdOptions, Sys,
138};
139pub use crate::transit::{
140    CreateKeyOptions, DataKey, DataKeyOptions, EncryptOptions, HashOptions, HmacOptions,
141    SignOptions, Transit, TransitBatchItem, TransitBatchResult, TransitCiphertext, TransitKey,
142    TransitKeyConfig, TransitKeyVersion, TransitSignature,
143};
144pub use crate::wrapping::{SecretResponse, WrapInfo, WrapLookup, Wrapping};
145
146/// Service-prefixed alias of [`Error`].
147pub type VaultError = Error;