Skip to main content

ProviderConfig

Struct ProviderConfig 

Source
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 auth map is printed as [REDACTED].
  • Header values containing sensitive substrings (token, secret, key, auth) are individually redacted.
  • values uses is_sensitive_key for 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

Source

pub fn new() -> Self

Create an empty configuration.

Source

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.

Source

pub fn get(&self, key: &str) -> Option<&str>

Get a configuration value by key.

Returns None if the key is not present.

Source

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>).

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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>.

Source

pub fn bearer_token(&self) -> Option<String>

Get the bearer token from auth credentials.

Shorthand for self.auth_get_owned("token").

Source

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).

Source

pub fn set_header(&mut self, key: &str, value: impl Into<String>) -> &mut Self

Set a custom HTTP header. The key is automatically lowercased.

Source

pub fn custom_headers(&self) -> &BTreeMap<String, String>

Return the custom headers map.

Source

pub fn set_verbose(&mut self, verbose: bool)

Set the verbose flag.

Source

pub fn verbose(&self) -> bool

Check whether verbose/debug output is enabled.

Source

pub fn set_timeout(&mut self, timeout: Duration)

Set the HTTP client timeout.

Source

pub fn timeout(&self) -> Option<Duration>

Get the HTTP client timeout.

Trait Implementations§

Source§

impl Clone for ProviderConfig

Source§

fn clone(&self) -> ProviderConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProviderConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProviderConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.