pub struct SecretProvidersPool { /* private fields */ }Expand description
A pool of multiple secret providers with a unified interface.
This struct manages multiple SecretProvider instances and provides a single
interface for retrieving secrets. When a secret is requested, the pool uses
either the provider specified in the secret reference or the default provider.
§Example
use regent_sdk::secrets::{SecretProvider, SecretProvidersPool, SecretReference};
// Create a pool with a single provider
let pool = SecretProvidersPool::from("files", SecretProvider::files());
// Retrieve a secret
let secret_ref = SecretReference::from("/path/to/secret", None);
let secret = pool.get_secret_raw(&secret_ref).await.unwrap();Implementations§
Source§impl SecretProvidersPool
impl SecretProvidersPool
Sourcepub fn from(name: &str, secret_provider: SecretProvider) -> Self
pub fn from(name: &str, secret_provider: SecretProvider) -> Self
Create a new secret providers pool with a single provider.
This is a convenience constructor for pools with only one provider, which will automatically be set as the default.
§Arguments
name- Name for the providersecret_provider- The secret provider instance
§Returns
A new SecretProvidersPool with the specified provider as the default.
§Example
use regent_sdk::secrets::{SecretProvider, SecretProvidersPool};
let pool = SecretProvidersPool::from("files", SecretProvider::files());Sourcepub fn enable_caching(&mut self)
pub fn enable_caching(&mut self)
Enable secret caching for this pool.
When caching is enabled, secrets are stored after first retrieval and subsequent requests for the same secret will return the cached value. This ensures idempotency by preventing secret rotation from affecting compliance operations that are in progress.
§Example
use regent_sdk::secrets::{SecretProvider, SecretProvidersPool};
let mut pool = SecretProvidersPool::from("files", SecretProvider::files());
pool.enable_caching();Sourcepub fn disable_caching(&mut self)
pub fn disable_caching(&mut self)
Disable secret caching for this pool.
§Example
use regent_sdk::secrets::{SecretProvider, SecretProvidersPool};
let mut pool = SecretProvidersPool::from("files", SecretProvider::files());
pool.disable_caching();Sourcepub fn is_caching_enabled(&self) -> bool
pub fn is_caching_enabled(&self) -> bool
Sourcepub fn create_cache_key(&self, secret_reference: &SecretReference) -> String
pub fn create_cache_key(&self, secret_reference: &SecretReference) -> String
Create a cache key from a secret reference.
This creates a unique key that combines the provider name and secret reference to ensure proper caching across different providers.
Sourcepub async fn get_secret_typed<T: DeserializeOwned>(
&self,
secret_reference: &SecretReference,
) -> Result<Secret<T>, RegentError>
pub async fn get_secret_typed<T: DeserializeOwned>( &self, secret_reference: &SecretReference, ) -> Result<Secret<T>, RegentError>
Retrieve a secret as a specific type.
§Type Parameters
T- The type to deserialize the secret into (must implementDeserializeOwned)
§Arguments
secret_reference- Reference to the secret to retrieve
§Returns
The secret wrapped in a Secret container, or a RegentError if retrieval failed.
§Example
use regent_sdk::secrets::{SecretProvidersPool, SecretReference};
use serde::Deserialize;
#[derive(Deserialize)]
struct ApiCredentials {
key: String,
secret: String,
}
let pool = SecretProvidersPool::from("files", SecretProvider::files());
let secret_ref = SecretReference::from("api_creds.json", None);
let creds: Secret<ApiCredentials> = pool.get_secret_typed(&secret_ref).await.unwrap();Sourcepub async fn get_secret_raw(
&self,
secret_reference: &SecretReference,
) -> Result<Secret<String>, RegentError>
pub async fn get_secret_raw( &self, secret_reference: &SecretReference, ) -> Result<Secret<String>, RegentError>
Retrieve a secret as a raw string.
§Arguments
secret_reference- Reference to the secret to retrieve
§Returns
The secret as a string wrapped in a Secret container, or a RegentError if retrieval failed.
§Example
use regent_sdk::secrets::{SecretProvidersPool, SecretReference};
let pool = SecretProvidersPool::from("files", SecretProvider::files());
let secret_ref = SecretReference::from("/path/to/password.txt", None);
let password = pool.get_secret_raw(&secret_ref).await.unwrap();
let password_str: String = password.inner();Trait Implementations§
Source§impl Clone for SecretProvidersPool
impl Clone for SecretProvidersPool
Source§fn clone(&self) -> SecretProvidersPool
fn clone(&self) -> SecretProvidersPool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more