synwire_core/credentials/traits.rs
1//! Credential provider traits.
2
3use crate::BoxFuture;
4use crate::credentials::SecretValue;
5use crate::error::SynwireError;
6
7/// Provider of credentials (API keys, tokens, etc).
8///
9/// Implementors supply credentials to model providers and other components
10/// that require authentication. The trait supports both static and
11/// refreshable credential sources.
12///
13/// # Example
14///
15/// ```
16/// use synwire_core::credentials::{CredentialProvider, SecretValue, StaticCredentialProvider};
17///
18/// let provider = StaticCredentialProvider::new(SecretValue::new("sk-test-key"));
19/// ```
20pub trait CredentialProvider: Send + Sync {
21 /// Get the current credential value.
22 fn get_credential(&self) -> BoxFuture<'_, Result<SecretValue, SynwireError>>;
23
24 /// Refresh the credential (e.g., after a 401/403 response).
25 ///
26 /// Default implementation delegates to [`get_credential`](Self::get_credential).
27 fn refresh_credential(&self) -> BoxFuture<'_, Result<SecretValue, SynwireError>> {
28 self.get_credential()
29 }
30}