pub struct ProviderConfig { /* private fields */ }Expand description
Dynamic configuration values resolved from config file profiles and CLI flags, passed to provider factory functions.
Configuration is organized into four namespaces:
- values — Connection parameters and provider-specific settings (endpoint, project, logstore, index, …).
- auth — Authentication credentials (token, username, password, access-key-id, api-key, …). Empty-string values are treated as absent.
- headers — Custom HTTP headers injected into every request. Keys are stored in lowercase.
- verbose / timeout — Promoted from string-key conventions to typed fields.
§Security
Debug is manually implemented:
- The entire
authmap is printed as[REDACTED]. - Header values containing sensitive substrings (
token,secret,key,auth) are individually redacted. valuesusesis_sensitive_keyfor per-key redaction.
§Example
use obz_core::ProviderConfig;
let mut config = ProviderConfig::new();
config.set("endpoint", "http://localhost:8428");
config.set_auth("token", "my-secret");
assert_eq!(config.get("endpoint"), Some("http://localhost:8428"));
assert_eq!(config.bearer_token(), Some("my-secret".to_string()));
assert!(config.require("endpoint").is_ok());
assert!(config.require("missing").is_err());
// Debug output redacts auth entirely
let debug = format!("{:?}", config);
assert!(debug.contains("[REDACTED]"));
assert!(!debug.contains("my-secret"));Implementations§
Source§impl ProviderConfig
impl ProviderConfig
Sourcepub fn set(&mut self, key: &str, value: impl Into<String>) -> &mut Self
pub fn set(&mut self, key: &str, value: impl Into<String>) -> &mut Self
Set a configuration value, returning &mut Self for chaining.
If the key already exists, its value is overwritten.
Sourcepub fn get(&self, key: &str) -> Option<&str>
pub fn get(&self, key: &str) -> Option<&str>
Get a configuration value by key.
Returns None if the key is not present.
Sourcepub fn get_owned(&self, key: &str) -> Option<String>
pub fn get_owned(&self, key: &str) -> Option<String>
Get a cloned configuration value by key.
Convenience method for cases where an owned String is needed
(e.g., passing to a constructor that takes Option<String>).
Sourcepub fn require(&self, key: &str) -> Result<&str, ObzError>
pub fn require(&self, key: &str) -> Result<&str, ObzError>
Get a required configuration value by key.
§Errors
Returns ObzError::InvalidArgument with ErrorCode::MissingRequired
if the key is not present. The error message suggests setting the value
in config.yaml.
Sourcepub fn require_config(&self, key: &str) -> Result<&str, ObzError>
pub fn require_config(&self, key: &str) -> Result<&str, ObzError>
Get a required provider configuration value by key.
Like require, but the error message includes a
hint pointing the user to config.yaml. Use this for provider
config fields (e.g. endpoint) that are typically set in the
config file rather than on the command line.
§Errors
Returns ObzError::InvalidArgument with ErrorCode::MissingRequired
if the key is not present.
Sourcepub fn set_auth(&mut self, key: &str, value: impl Into<String>) -> &mut Self
pub fn set_auth(&mut self, key: &str, value: impl Into<String>) -> &mut Self
Set an auth credential value.
Empty strings are stored but auth_get treats
them as absent.
Sourcepub fn auth_get(&self, key: &str) -> Option<&str>
pub fn auth_get(&self, key: &str) -> Option<&str>
Get an auth credential value by key.
Returns None if the key is missing or its value is an empty
string (empty auth values are treated as absent to prevent
accidental empty-credential requests).
Sourcepub fn auth_get_owned(&self, key: &str) -> Option<String>
pub fn auth_get_owned(&self, key: &str) -> Option<String>
Get a cloned auth credential value by key.
Returns None if the key is missing or empty.
Sourcepub fn auth_require(&self, key: &str) -> Result<&str, ObzError>
pub fn auth_require(&self, key: &str) -> Result<&str, ObzError>
Get a required auth credential value by key.
§Errors
Returns ObzError::InvalidArgument with ErrorCode::MissingRequired
if the key is missing or empty. The error message directs the user to
set the value in config.yaml under providers.<name>.auth.<key>.
Sourcepub fn bearer_token(&self) -> Option<String>
pub fn bearer_token(&self) -> Option<String>
Get the bearer token from auth credentials.
Shorthand for self.auth_get_owned("token").
Sourcepub fn basic_auth(&self) -> Option<(String, String)>
pub fn basic_auth(&self) -> Option<(String, String)>
Extract HTTP Basic Auth credentials (username, password) from
the auth map.
Returns None when either key is missing or empty, which means
the provider should skip basic-auth and fall through to other auth
methods (e.g., bearer token).
Sourcepub fn set_header(&mut self, key: &str, value: impl Into<String>) -> &mut Self
pub fn set_header(&mut self, key: &str, value: impl Into<String>) -> &mut Self
Set a custom HTTP header. The key is automatically lowercased.
Sourcepub fn custom_headers(&self) -> &BTreeMap<String, String>
pub fn custom_headers(&self) -> &BTreeMap<String, String>
Return the custom headers map.
Sourcepub fn set_verbose(&mut self, verbose: bool)
pub fn set_verbose(&mut self, verbose: bool)
Set the verbose flag.
Sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Set the HTTP client timeout.
Trait Implementations§
Source§impl Clone for ProviderConfig
impl Clone for ProviderConfig
Source§fn clone(&self) -> ProviderConfig
fn clone(&self) -> ProviderConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more